HackerTrans
TopNewTrendsCommentsPastAskShowJobs

fabiancook

no profile record

Submissions

The Future of Routing with the Navigation API – Eduardo San Martin Morote [video]

youtube.com
2 points·by fabiancook·8 เดือนที่ผ่านมา·1 comments

comments

fabiancook
·8 เดือนที่ผ่านมา·discuss
On and off working on the Navigation API for Node, Bun, Deno, & as a browser polyfill.

Has 90% test coverage, makes use of web platform tests to verify compatibility, and is in use by some larger companies already with the Navigation API soon to become a baseline in evergreen browsers.

The Navigation API effectively is async state navigations. The likes of React has recently added Navigation API support to make use of the browser reload indicator.

https://github.com/virtualstate/navigation

Along with working on a startup day to day :)
fabiancook
·8 เดือนที่ผ่านมา·discuss
Do you want just JSX in browsers?

Or do you want a "native virtual DOM".... that is the DOM we have today.

There is various new tools coming available that make working with a browser so much easier.

In the past for example there was no way to do a SPA transition between pages, this was one of the big things handled by the likes of react alongside of the vdoms, but by tooling like react-router for the likes of react. This made it pretty much that you needed to use the likes of react to make state based changes to the DOM.

Now... we have the navigation API where you can have an async change happen on navigate and prevent

Very soon you'll be able to do this:

    navigation.addEventListener("navigate", event => {
      event.intercept({
        async handler() {
          const state = event.destination.getState();
          document.body.setHTML(`
      <div>
        <p>Paragraph to inject into shadow DOM.
          <button clicked the button with value ${state.key}!')">Click me</button>
        </p>
        <script src="path/to/a/module.js" type="module"><\/script>
        <p data-id="${state.key}">Para with <code>data-id</code> attribute with value <code>${state.key}</code></p>
      </div>
          `)
        }
      })
    });

(where `setHTML` is the pending API here, the navigation API available in chrome, and polyfill available for firefox/safari)

Yes this use of just setting a string is not giving all the nice things like diffing and all... but, we have then a state API tied to the browser navigation, along with a way to know the navigation was successful:

    await navigation.navigate("/somewhere", { state: { key: "value } }).finished;
Flipping things around a bit gives the power back to the browser like it seems you're after, rather than reaching for every tool available... but, a standard JSX feels a while away... maybe expressing JSX just for pure DOM elements would be enough though, without any functional components, but I guess that is what makes JSX, JSX.
fabiancook
·8 เดือนที่ผ่านมา·discuss
Awesome to see the Navigation API being talked about at DevFest.

The API is available in chrome today. Safari & Firefox are actively developing their implementations too.

MDN Documentation: https://developer.mozilla.org/en-US/docs/Web/API/Navigation_...

JavaScript implementation usable as polyfill: https://github.com/virtualstate/navigation (I am the author of this repository)