Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation API #435

Closed
1 of 3 tasks
rd3k opened this issue Sep 16, 2023 · 7 comments
Closed
1 of 3 tasks

Navigation API #435

rd3k opened this issue Sep 16, 2023 · 7 comments
Labels
focus-area-proposal Focus Area Proposal

Comments

@rd3k
Copy link

rd3k commented Sep 16, 2023

Description

The Navigation API was previously submitted for consideration in Interop 2023.

Since then it has matured, graduated from being a HTML Spec PR to a part of the spec and landed in Chrome 110 (~ February 7th 2023, plus other Chromium-based browsers since).

Please note that I do not represent an implementer. I am a web developer that is enthusiastic about this massive improvement over the History API.

Some excellent features include:

  • The navigate event: a powerful way to conditionally convert cross-document navigations to same-document navigations
  • entries: exposing a list of NavigationHistoryEntry as an abstraction over same-origin session history entries
  • Focus reset and scroll behaviour
  • Handling a 'traverse' navigation event is much more intuitive than a popstate. You can avoid reacting to it, derive whether the direction was forward or backwards by comparing entry index, and much more.

Specification

https://html.spec.whatwg.org/multipage/nav-history-apis.html#navigation-api

Open Issues

Tests

https://wpt.fyi/results/navigation-api

Current Implementations

  • Blink
  • Gecko
  • WebKit

Standards Positions

Browser bug reports

Developer discussions

Various, including:

Polls & Surveys

Existing Usage

No response

Workarounds

Accessibility Impact

No response

Privacy Impact

Other

TAG design reviews:

MDN documentation

@rd3k rd3k added the focus-area-proposal Focus Area Proposal label Sep 16, 2023
@foolip
Copy link
Member

foolip commented Oct 5, 2023

For survey data and web developer demand, in preliminary results from State of HTML 2023, Navigation API was a somewhat common response to the freeform question "Which existing HTML features or browser APIs are you unable to use because of browser differences or lack of support?"

@atscott
Copy link

atscott commented Oct 26, 2023

Angular router package caretaker here. I've been following the development of the Navigation API for quite some time now and I feel that this is a huge step forward from the current set of APIs we have available to us. Just a few of the things that require custom implementations in the Angular router (and certainly other framework routers) that are more easily solved with the Navigation API:

  • Being able to inspect the entries is extremely valuable for restoring history when the application configuration wants to reject a navigation. Currently, we have to leave "breadcrumbs" on the history.state and use this to calculate where to move back to if we want to reject a back button click and restore history. This is done in Angular and Vue and likely other framework Router implementations.
  • The above breadcrumbs for determining navigation direction aren't exposed in the Angular Router's public API. Getting this information as an application developer would require accessing the private router state on history, duplicating the state breadcrumbs, or waiting for the framework to make those things public. With the navigation API, this was easy to do in an app by just adding a currententrychange listener and comparing entry indexes, which I did when creating a view transition demo for different animations on back traversals.
  • Similar "breadcrumbs" are used for scroll position restoration. Scrolling in SPA routers in general is often done with a lot of custom code. A few examples of the custom scroll behavior of SPA routers: Angular, React, and Vue.
    The current history.scrollRestoration is a lot less capable than the navigation API's ability to imperatively call scroll after the router knows the page is fully rendered.
  • The ability to intercept any navigation would be powerful. Currently, forgetting to use the RouterLink directive in Angular and just using a plain anchor tag <a href="/"... can't be handled as a SPA navigation but this could be intercepted with the Navigation API. In addition, the fact that history.pushState and history.replaceState are not observable makes these direct history navigations hidden from the framework Router.
  • The ability to let the browser know a navigation is happening is not possible with the history API. Without the applications putting this directly in the UI, site visitors have no good indication of ongoing navigations. In addition, intercepting the navigate event and keeping it unresolved for the duration of the framework router's navigation opens up the possibility for canceling the navigation directly from the browser API. This isn't possible either for SPA routers today.

Those are just a few points off of the top of my head. I'm sure we'll come across a whole host of other items that have previously been difficult to achieve with the current set of APIs or otherwise not at all possible while we continue to experiment with the Navigation API in the router.

@wpt-interop
Copy link

Thank you for proposing Navigation API for inclusion in Interop 2024.

We wanted to let you know that this proposal was not selected to be part of Interop this year.

This is because we got many more proposals than we could include in this year's project. Note that individual vendors may nevertheless choose to advance work in this area during the forthcoming year. We would welcome this proposal being resubmitted again next year if necessary.

For an overview of our process, see proposal selection. Thank you again for contributing to Interop 2024!

Posted on behalf of the Interop team.

@foolip

This comment was marked as duplicate.

@foolip foolip closed this as completed Feb 1, 2024
@ryanflorence
Copy link

Bummer, was looking forward to using this in React Router ASAP because the history API is rough for users and completely lacking for accessibility.

For survey data and web developer demand

It's also one of those features many web developers don't know they want because frameworks have abstracted the current capabilities with lots of caveats.

Hopefully can make it into 2025!

@ryantownsend
Copy link

@ryanflorence I believe this API is being worked on in WebKit already: WebKit/WebKit@eabae2c so just because it's not in Interop, doesn't mean we won't see it in 2024.

I mirror your viewpoint that this isn't many are even aware of to know how important it is – frameworks have been abstracting this away for years. Let's just hope WebKit land it this year! 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus-area-proposal Focus Area Proposal
7 participants