Pages router: API for shallow routing

Aperta
#833 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
frontend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
684
Fork
83
Merge medio
15h 22m
PR unite (30g)
219

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di voidzero-dev/void

Tutte le issue di voidzero-dev/void

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.