React Forum
Blog & Guide Responses
Jan 30, 2023 · 04:00 AM

MDN History API - discussion (2023-01-30)

Started by Ari Novak
externalhistorynavigationpopstateroutingurl contractsevidence

MDN's History API doc is the kind of primitive-level reading that makes route contracts feel less magical. Once you understand what the browser is actually doing with pushState, replaceState, and back/forward, it's easier to design a calm URL surface and keep the rest of the app model in explicit state documents.

Read the docs

Do you treat URL changes as commands (intent) or as a representation of state? What do you put in the URL versus a route document when you have lots of UI motion? How do you debug back/forward issues—do you log history transitions as evidence?

Comments (16)

Back to latest
Marisol Vega
Feb 02, 2023 · 02:02 AM

URL is the "where" for us. State docs are the "what".

When we put too much "what" in the URL, sharing is fine but the app becomes fragile.

Dmitri Kline
Feb 08, 2023 · 08:08 AM

We log history transitions as a contract log. It's saved us a lot:

txt
[tips] history pushState url=/accounts/42 reason=nav:click
[tips] history popstate url=/accounts reason=back
[tips] routeDoc replay panel=list selection=null

The replay line is key. Back/forward isn't just URL; it's the model replaying.

Keira Santos
Feb 16, 2023 · 04:16 PM

Counterpoint: treating URL as only "where" can make sharing frustrating if the "what" matters (filters, tabs).

We compromised: URL keeps a couple user-meaningful keys; route doc owns the rest.

Ari Novak
Feb 19, 2023 · 04:04 AM

Same. The guide's posture isn't "URL empty"; it's "URL calm".

If a key is meaningful for sharing, it can belong in URL—just make it part of the contract and log it.

Grace McCoy
Feb 28, 2023 · 10:22 PM

Back/forward bugs got better when we made panel state explicit and replayable.

If panel is hidden component state, back/forward becomes a guessing game.

Jasper Nguyen
Mar 14, 2023 · 03:03 AM

I like MDN because it reminds you that history state is arbitrary and easy to misuse.

If you store too much in history state, you end up with hidden, unversioned contracts.

Nina Kapoor
Mar 29, 2023 · 12:12 PM

We treat replaceState as a "correction" tool (fix URL without adding history entry). And we log it, because otherwise it feels like the browser is haunted:

txt
[tips] history replaceState url=/search?q=react reason=normalize:query
Camille Duarte
Apr 16, 2023 · 06:06 AM

Counterpoint: history logging can be noisy in complex apps.

We only log push/replace/pop transitions + the route doc key summary, not every param tweak.

Owen Price
May 08, 2023 · 05:05 AM

The concept that helped me: URL changes are intent signals, but the app decides how to interpret them.

That's basically the route contract story.

Benji Rios
May 30, 2023 · 06:18 PM

History state can become a footgun if you treat it as storage.

If you need persistence, use a real store/vault and treat history as navigation only.

Amina Farouk
Jun 21, 2023 · 03:33 AM

Docs tie-in: the routing docs here basically recommend this: keep URL stable, keep state explicit, render evidence.

Related: Routing and Navigation and The App Router Mindset.

Theo Bennett
Jul 17, 2023 · 07:07 AM

We also render a "history action" evidence key (push/replace/pop).

It made it easier to debug why a user can't get back to the previous screen.

Sofia Valdez
Aug 14, 2023 · 02:14 PM

Counterpoint: sometimes putting filters in URL is just the right UX.

But we still parse/serialize through one module and log parse results so defaults don't drift.

Priya Liao
Sep 22, 2023 · 04:04 AM

If you do UI motion (overlays) without URL changes, you should still have a route-doc motion key.

Otherwise the motion becomes hidden state and back/forward can't reason about it.

Tomas Rivera
Oct 19, 2023 · 07:19 PM

A trick we used: log a compact summary of route doc on every history transition.

It acts like a receipt without calling it a receipt.

Rowan Pierce
Nov 18, 2023 · 11:11 AM

MDN also clarified what doesn't happen automatically (scroll restoration, state replay).

Once you accept that, you're more willing to build explicit contracts for it.

Salma Qureshi
Dec 29, 2023 · 09:09 AM

If a user reports navigation bugs, history logs + evidence keys are the fastest path to diagnosis.

Otherwise you end up guessing based on vibes.