Skip to content

Commit 56a21da

Browse files
atscottAndrewKushnir
authored andcommitted
refactor(router): resolve view transition promise in a timeout when unsupported (angular#55327)
Related to angular#51131, this change ensures that the router navigation exits the current event loop before rendering the route when the view transition feature is enabled, when the browser does not support view transitions. PR Close angular#55327
1 parent 8483721 commit 56a21da

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
@@ -108,7 +108,10 @@ export function createViewTransition(
108108
return injector.get(NgZone).runOutsideAngular(() => {
109109
if (!document.startViewTransition || transitionOptions.skipNextTransition) {
110110
transitionOptions.skipNextTransition = false;
111-
return Promise.resolve();
111+
// The timing of `startViewTransition` is closer to a macrotask. It won't be called
112+
// until the current event loop exits so we use a promise resolved in a timeout instead
113+
// of Promise.resolve().
114+
return new Promise((resolve) => setTimeout(resolve));
112115
}
113116

114117
let resolveViewTransitionStarted: () => void;

0 commit comments

Comments
 (0)