You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
createLocationState: option to drop state written with an older shape (version / validate) #994
A createLocationState key is derived from the file path and export name (src/vite/plugins/expose-ids/handler-transform.ts:48-53), so it stays the same across deploys. The read is an unchecked cast (src/browser/react/location-state.ts:20).
A tab that stays open across a deploy that changed the state's shape restores the old value typed as the new one. Code then reads missing or renamed fields, or a changed structure, with no type error and no runtime check. History entries survive reloads and back/forward indefinitely, so long-lived tabs hit this after an ordinary release.
Seen on 0.18.0.
Proposal
An option on createLocationState that lets a definition reject state it can't trust, for example:
exportconstGridState=createLocationState<GridSnapshot>({version: 2});// stored as { v: 2, value }; a different or missing version reads as undefinedexportconstGridState=createLocationState<GridSnapshot>({validate: (value): value is GridSnapshot=>isGridSnapshot(value),});// run on read; a failing value reads as undefined
version is cheap and covers deliberate shape changes. validate also covers state written by other code under the same key. Either keeps the typed read honest. An entry that fails the check reads as undefined, which is the same result as no state.
Activity
feat(router): createLocationState can reject an older stored shape
feat(router): createLocationState can reject an older stored shape
feat(router)!: version location state by the app version, drop the ve…
test(router): e2e and consumer coverage for the app version of locati…
docs(router): location state is versioned by the app version; the ver…
feat(router): drop the validate option of createLocationState (#994)
fix(router): location state belongs to the entry on screen; evicted s…