Skip to content

Commit 0d52c6b

Browse files
atscottAndrewKushnir
authored andcommitted
fix(router): Delay the view transition to ensure renders in microtasks complete (#56494)
This commit delays makes two changes: * Use the `read` phase for `afterNextRender` hook. We really want to wait for any write hooks to complete before starting the animation * In addition, wait a macrotask before resolve (really, this makes the above change unnecessary but it's still conceptually the right thing). This ensures any follow-up rendering in the microtask queue is flushed before the animation starts. Important note: This only affects the timing of the animation start, delaying it longer to allow additional rendering/change detections to flush. This promise already resolves in an `afterNextRender` hook and is only used directly by the browser's view transition machinery. PR Close #56494
1 parent 955ade6 commit 0d52c6b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/router/src/utils/view_transition.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ export function createViewTransition(
139139
*/
140140
function createRenderPromise(injector: Injector) {
141141
return new Promise<void>((resolve) => {
142-
afterNextRender(resolve, {injector});
142+
// Wait for the microtask queue to empty after the next render happens (by waiting a macrotask).
143+
// This ensures any follow-up renders in the microtask queue are completed before the
144+
// view transition starts animating.
145+
afterNextRender({read: () => setTimeout(resolve)}, {injector});
143146
});
144147
}

0 commit comments

Comments
 (0)