liveBook · Manning

History entry state

As explained in Vanilla Web

History entry state is serializable transient data associated with an individual browser session-history entry.

History entry state is small, serializable data attached to one browser session-history entry. Use it for transient view details—such as an active tab or panel scroll position—that should return with Back and Forward navigation. Keep important, shareable route state in the URL. section 11.2

With the Navigation API, pass state to navigation.navigate(), read it with navigation.currentEntry.getState(), and update it without navigating with navigation.updateCurrentEntry(). The older History API accepts state in pushState() or replaceState(); read it through history.state or popstate event.state. It has no current-entry update method, so updating state requires replaceState() with the current URL. section 11.2

Choose storage according to whether the state belongs in a shareable route or only in the current browsing session:

  • Put a selected product in the URL; it should be shareable. section 11.2
  • Put search filters in the URL unless they are private or temporary. section 11.2
  • Use entry state for a panel’s scroll position or a convenience-only disclosure panel. section 11.2
Table 11.1 Deciding on storing state data in URL or in history entry

State

Belongs in the URL

Belongs in history entry state

Selected product

Yes, as /products/42.

No, because the route should be shareable.

Search filters

Usually, as query parameters.

Only if the filters are private or temporary.

Scroll position inside a panel

No.

Yes, because it belongs to the current browsing session.

Open disclosure panel

Maybe, if it should be shareable.

Yes, if it is only UI convenience.

Compare which kinds of state belong in the URL and which belong in an individual history entry. section 11.2

How Vanilla Web covers it

How deep it goes
Defines entry state, explains read and write APIs, and distinguishes it from URL state without covering serialization details.
Examples
Uses active tabs, panel scroll positions, search filters, and disclosure panels as examples.
What you can do after
Apply it via the Navigation API or History API to preserve transient view details per history entry.
How it connects
Connects URL state and history entry state with the Navigation API, History API, and scroll restoration.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Vanilla Web. The section links point to the parts of the book it draws on.