From 338640596de1cf231586aca31d722f7f5bd38a6d Mon Sep 17 00:00:00 2001 From: MiniPear Date: Fri, 31 Mar 2023 18:24:31 +0800 Subject: [PATCH] fix(runtime): wait for the next tick to finish rendering (close: #4771) --- __tests__/integration/utils/renderSpec.ts | 2 -- src/runtime/render.ts | 7 +++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/__tests__/integration/utils/renderSpec.ts b/__tests__/integration/utils/renderSpec.ts index 375291f9d5..bdf0e84e58 100644 --- a/__tests__/integration/utils/renderSpec.ts +++ b/__tests__/integration/utils/renderSpec.ts @@ -19,7 +19,5 @@ export async function renderSpec( // @ts-ignore renderFunction({ theme: 'classic', ...options }, context, resolve), ); - // Wait for the next tick. - await sleep(20); return gCanvas; } diff --git a/src/runtime/render.ts b/src/runtime/render.ts index 5c22b35888..f7918c4c5a 100644 --- a/src/runtime/render.ts +++ b/src/runtime/render.ts @@ -94,8 +94,11 @@ export function render( plot({ ...keyed, width, height }, selection, library, context), ) .then(() => { - emitter.emit(ChartEvent.AFTER_RENDER); - resolve?.(); + // Wait for the next tick. + canvas.requestAnimationFrame(() => { + emitter.emit(ChartEvent.AFTER_RENDER); + resolve?.(); + }); }) .catch((e) => { reject?.(e);