Skip to content

Conversation

@noamr
Copy link
Collaborator

@noamr noamr commented Nov 19, 2025

Deferred same-origin cross-document commit

This gives a way for authors to defer a same-origin cross-document navigation commit.

The API is used in this way:

// It's called "deferPageSwap" rather than "deferCommit"
// because it does "commit" a same-document navigation.
navigateEvent.deferPageSwap({
  // This means that the history is swapped immediately, like a `pushState`,
  // and the navigation becomes a `replace`.
  historyChange: "immediate",
  async handler(controller) {
     const transition = document.startViewTransition(show_skeleton);

     // The restore callback will be called if the navigation is aborted, or if this document is restored from BFCache.
     controller.addRestoreCallback(() => hide_skeleton());
     return transition.finished;
  }
});

See explainer.
Closes #11819

  • At least two implementers are interested (and none opposed):
  • Tests are written and can be reviewed and commented upon at:
  • Implementation bugs are filed:
    • Chromium: …
    • Gecko: …
    • WebKit: …
    • Deno (only for timers, structured clone, base64 utils, channel messaging, module resolution, web workers, and web storage): …
    • Node.js (only for timers, structured clone, base64 utils, channel messaging, and module resolution): …
  • Corresponding HTML AAM & ARIA in HTML issues & PRs:
  • MDN issue is filed: …
  • The top of this comment includes a clear commit message to use.

(See WHATWG Working Mode: Changes for more details.)


/browsing-the-web.html ( diff )
/index.html ( diff )
/nav-history-apis.html ( diff )

@noamr noamr marked this pull request as draft November 19, 2025 15:46
@noamr noamr changed the title Defer Deferring same-origin cross-document commit Nov 19, 2025
@noamr noamr changed the title Deferring same-origin cross-document commit Allow deferring same-origin cross-document commit Nov 20, 2025
@noamr noamr marked this pull request as ready for review November 20, 2025 16:34
@noamr noamr marked this pull request as draft December 8, 2025 15:16
noamr and others added 23 commits December 8, 2025 15:19
"commit a navigate event" is a noop when the navigation is not
intercepted in the first place.

Instead of calling it and checking for the interception state
internally, only call it for intercepted navigations, and rename it
to "commit an intercepted navigate event". Also remove internal
logic that tests whether the navigation is same-document
(intercepted navigations are always same-document).
This specifies a way for authors to defer a same-origin cross-document navigation
commit.

It exposes:
- `navigateEvent.deferCommit(promise)`

Allows a listener to the `navigate` event to defer a cross-document commit, without intercepting it.
Returns a promise that can be used to clean up any intermediate state.

- `navigateEvent.destination.ready`

A boolean getter that returns true when the navigation is expected to be instant, i.e.
when the destination already has a document and that document is not render-blocked
(which by and large would imply prerendering).

Closes whatwg#11819
@noamr noamr marked this pull request as ready for review December 11, 2025 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Allow deferring commit of a same-origin cross-document navigation

1 participant