Pages router: API for shallow routing

Offen
#833 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
typescript
Bereich
frontend

Rechercherichtung

Read the implementation of router.visit first and trace what it does in order: the fetch, the route-state update, the history write and the scroll-restoration bookkeeping. Compare that with the raw history.replaceState fallback described here, which leaves useRouter().url and .query stale, and identify where route state is derived so a shallow variant can update it without fetching. Done means router.visit(url, { replace: true, shallow: true }) changes history and router state while no request runs and deferred props are untouched, with a test covering the no-fetch guarantee.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Void version: 1.9.1, affecting every adapter

Use case

The simplest that I hit: A page has multiple side panels with info. Which panel is open depends on the query string (/page?panel=X), so the view can be shared and other pages can link to it.
The server ignores the param: it's left out of revalidateQueryAllowlist, so every variant shares one ISR entry, and the panel opens on the client.

When the user opens, switches or closes a panel, ?panel= should change in place: no new history entry, no request, no re-render.

Current status with today's API

The only Void way to change the query is

router.visit(url, { replace: true, preserveState: true, preserveScroll: true });

which is a full GET navigation. For state the server doesn't render, that means:

  • The page data is fetched again on every change, in our case that's about 122 KB except the exact entry was cached already.
  • Deferred props go back to loading, which would include our panel.

So instead of using it we fall back to the raw history.replaceState. That works, but the router no longer matches the address bar: useRouter().url / .query keep reporting the old query until the next navigation.

API Proposal

Something like

router.replaceUrl(url); // or router.visit(url, { replace: true, shallow: true })

This would:

  • write history (replace, or push as an option),
  • update the router's route state
  • keep scroll-restoration bookkeeping in step,
  • does not fetch, re-render, or touch deferred props.

This is similar to what other meta frameworks do, e.g. SvelteKit's replaceState or Next.js's shallow routing.

Vorherrschende Sprache
TypeScript
Sterne
684
Forks
83
Ø Merge
15 Std. 22 Min.
Gemergte PRs (30 T.)
219

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus voidzero-dev/void

Alle Issues in voidzero-dev/void

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.