Skip to content

Commit

Permalink
fix(runtime): wait for the next tick to finish rendering (close: #4771)
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Mar 31, 2023
1 parent 0615ca8 commit 3386405
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 0 additions & 2 deletions __tests__/integration/utils/renderSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
7 changes: 5 additions & 2 deletions src/runtime/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ export function render<T extends G2ViewTree = G2ViewTree>(
plot<T>({ ...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);
Expand Down

0 comments on commit 3386405

Please sign in to comment.