@@ -42,20 +42,45 @@ To achieve that, proposing two provide the following:
4242
4343``` js
4444// Returns a boolean if the page is prerendered/BFCached and not render-blocked.
45- navigateEvent .nextDocumentReadyToRender
45+ navigateEvent .destination . ready
4646
47- // Allows delaying the commit *without* intercepting as a same-document navigation.
48- navigateEvent .deferCommit (promise)
49- ```
47+ // Allows delaying the cross-document commit (aka page-swap) *without* intercepting this as a same-document navigation.
48+ navigateEvent .deferPageSwap ({
49+ // "immediate", which is also the default, means that the history is swapped immediately, like a `pushState`,
50+ // and the navigation becomes a `replace`.
51+ historyChange: " immediate" | " after-transition" ,
52+
53+ // When the returned promise resovles, the navigation can proceed.
54+ // The handler can register a "restore" callback, to be called if the navigation is aborted
55+ // or if the page is restored from BFCache.
56+ handler : (controller ) => Promise
57+ });` ` `
5058
5159Possible usage:
5260` ` ` js
53- if (! navigateEvent .nextDocumentReadyToRender ) {
54- const transition = document .startViewTransition (show_preview);
55- navigateEvent .deferCommit (transition .finished );
56- }
61+ navigation .addEventListener (" navigate" , event => {
62+ if (! event .destination .ready ) {
63+ event .deferPageSwap ({
64+ // This means that the history is swapped immediately, like a `pushState`,
65+ // and the navigation becomes a `replace`.
66+ historyChange: " immediate" ,
67+ async handler (controller ) {
68+ const transition = document .startViewTransition (() => show_preview ());
69+
70+ // The restore callback will be called if the navigation is aborted, or if this document is restored from BFCache.
71+ controller .addRestoreCallback (() => hide_preview ());
72+ return transition .finished ;
73+ }
74+ });
75+ }
76+ });
5777```
5878
79+ ### Some more details for deferred commit/page-swap
80+ - By default, the new history entry applies immediately, like a ` pushState ` or ` replaceState ` .
81+ This makes it so that a quick press on "back" or so doesn't go too far back. The ` historyChange ` option can opt out of this behavior.
82+ - Only same-origin navigations without cross-origin redirects are deferrable.
83+
5984
6085## Allowing animations to defer commit for a short period
6186
0 commit comments