Repository navigation
Commit a55c2b5
authored
* fix(router): useLocationState changes with its entry's tree, not before it (#1029)
A mounted useLocationState reader received the destination entry's state
as soon as the router pushed the entry (on back/forward, at the popstate
event), in a render of its own. For as long as a navigation was held, the
page being left rendered with the next entry's state: a "load more" list
showed the current page's items twice until the next page landed.
The hook read history.state through useSyncExternalStore, and tx.commit
told it with a window event. A store snapshot is the latest value in every
tree at once, so it cannot stay behind in the tree a transition is holding.
Location state now rides the route-state notification. A commit site moves
an identity on the event controller (commitLocationState); the hook keeps
its slot in React state and re-reads history.state when the identity
moves. NavigationProvider already flushes that notification inside the
payload update, so the read takes the payload's lane and commits with the
destination's tree. useSyncExternalStore stays for its server snapshot.
- push, replace, back/forward (cached restore and refetch) and server-set
state on a navigation commit with the tree.
- A revalidate:false navigation and a server action's state commit no
tree and are delivered at once, as before.
- clientUrls(): OptimisticLocation carries the entry the navigation will
push, so the optimistic destination reads its own state on its first
render instead of the entry being left.
- The __rsc_locationstate window event and its dispatch sites are gone.
- A reader whose slot a commit leaves as it was sets no state.
- renderRoute: navigations commit through the controller,
router.navigate() takes state/replace, and a popstate event is a
back/forward onto the current history.state.
The hook carries "use no memo": compiled by the React Compiler it grows a
29-slot memo cache (296B gzip in the router chunk). Router chunk on
cloudflare-basic: 47077B -> 47100B gzip (limit 47104B).
* test(e2e): location state commits with its entry's tree, in both apps (#1029)
Browser coverage for #1029 in the router test-app and cloudflare-basic,
dev and production, with the bodies shared in tests/shared-e2e.
- The load-more fixture loads its page through a loader (`?hold=<ms>`
delays it) and lists carried items plus the loader's page with no
duplicate filter. `location-state.commit` holds a navigation for 2.5s
and checks the screen during the hold, every DOM state in between and
every list the fixture committed; then back/forward across cached
entries and a return to an evicted entry, with a reader in a layout the
two #994 fixtures now share.
- The slow clientUrls group gets a reader in chrome outside the group, in
the group layout and in each page: the optimistic destination reads the
state its navigation carries, held content keeps its entry's state until
the canonical commit, and a superseded or cancelled navigation leaves
none behind.
- The render-stability pages get a useLocationState probe: same render and
commit counts as on main.
- cloudflare-basic's dogfood unit test seeds the list's loader and pins the
pending window through renderRoute.
No route was added or renamed.
* docs: location state changes with its entry's page; drop the load-more duplicate filter (#1029)
- skills/hooks/state.md: the contract ("When a reader sees an entry's
state") with a table per kind of change, and the load-more example as
the plain concatenation. The paragraph that described the duplicate
filter as a workaround is gone.
- skills/client-urls, docs/client-urls.md: inside the optimistic branch
useLocationState reads the state the navigation carries; outside it and
in held content, the committed entry's.
- skills/testing, docs/testing.md: router.navigate(url, { state, loaders })
for a component across a pending navigation, and a popstate event as a
back/forward.
- docs/internal/feature-map.md, feature-file-map.md: location state on the
route-state notification, the commit sites, and why the hook is React
state with useSyncExternalStore kept for the server snapshot only.
- docs site hooks reference, shallow-navigation design note: same rule.
* fix(router): location state is NavigationProvider state, read by context (#1029)
A reader that mounted while a navigation was pending read the destination
entry's state in the tree still on screen: useLocationState took its first
value from history.state, which has already moved by then. The first fix
covered readers that were mounted and left this one open.
The location state of the entry on screen is now React state owned by
NavigationProvider, set in the same update as the payload and delivered by
LocationStateContext. A transition React holds renders the destination's
value; an urgent render of the content on screen, a reader mounting there
included, renders the value of the entry being left. The hook is a context
read behind the per-reader hydration snapshot: no identity, no mirror ref, no
subscription, no frozen first read.
- Every commit site hands the controller the entry state it pushed, restored
or merged (EventController.commitLocationState(entryState)); the snapshot
is built from that object, under the version and clearOnReload rules, not
from a later read of history.state. The provider takes it next to
setPayload. A commit no payload follows (shallow navigation, a commit that
keeps every segment, an action's state) is marked treeless and taken with
that commit's state notification, in the batch of the location.
- A value keeps its identity when a navigation carries the reader's own
value forward or an action changes another slot; any other object is a new
value, and a structured clone of what the caller passed.
- An action's state is added to what readers hold instead of re-reading the
entry, so a flash value on screen survives it.
- write()/delete() and the flash clear change history only: readers see them
when the entry is next restored. A flash value is shown until the entry's
state is next committed.
- Outside a NavigationProvider a reader has no location state.
- The "use no memo" directive is gone. Router chunk 47077B -> 47262B gzip;
limit raised 46KB -> 47KB with a dated note (47167B with the directive, so
it would not have fit either).
- renderRoute commits through the same calls: its popstate listener is the
bridge's registerLinkInterception, and router.navigate() writes history
only for `state` or `replace: true`.
- The optimistic clientUrls() entry state is built only when the group
presents the target.
* test(e2e): a reader mounted during a held navigation reads the entry on screen (#1029)
Both apps, dev and production: the load-more fixture mounts a second reader
of the carried items on demand. Pressed while the next page's loader holds
the navigation, it mounts in the page still on screen and must read that
page's entry, then change with the list. The DOM sampler flags any state in
which the late reader disagrees with the list it is in.
The cloudflare-basic dogfood test covers the same through renderRoute.
The test-app's load-more and app-version routes move to their own urls()
module, included at the same paths and names, so location-state.tsx keeps
its existing patterns untouched.
* fix(router): back/forward to an evicted same-route entry restores that entry's page (#1030)
Going back or forward to an entry of the same route that differs only in
search params, after the history cache dropped it, changed the URL and the
entry's location state and left the page being left on screen: a load-more
list past 20 pages showed the wrong page's items on Back.
Cause: the partial fetch tells the server which page the client is on
(X-RSC-Router-Client-Path) from the transaction's URL, window.location at the
time the transaction is created. On a back/forward the popstate event has
already moved it to the target, so the server diffed the target against
itself: on the same route nothing revalidates, the diff is empty, and the
client commits without a tree. A different route still got its segments,
which is why only the same-route case showed.
A traversal now names the store's URL, the committed entry's, as the
leave-intercept path already did for the same reason. An intercept restore
keeps naming the intercept's source; push and replace keep the transaction's
URL.
Tests: partial-update unit tests for the three cases, and an e2e in both
apps, dev and production, that evicts through the same route and returns
with the refetch held by its loader.
* docs: location state is the entry on screen's; #1030 changelog; the popstate limit (#1029, #1030, #1031)
The hooks skill and the docs-site page state the contract as built: a reader
gets an entry's location state with that entry's page, including a reader
that mounts while a navigation is pending, and what follows from the provider
holding it (identity of values, write()/delete(), flash, a reader outside the
provider). Both name the limit that remains: usePathname and useSearchParams
still change at popstate on back/forward (#1031).
CHANGELOG: the #1029 entry is rewritten around the same contract and lists
every change in when a reader updates that an existing app could notice; a
#1030 entry is added.
Also: the optimistic clientUrls() value is the object the navigation passed
and becomes the entry's copy at the commit (documented, not cloned);
renderRoute's navigate() history options and its popstate listener; the
internal feature maps and the shallow-navigation design note follow the
provider-owned delivery.
* test(e2e): the offscreen-prefetch test waits for the streamed layout before measuring
cloudflare-basic's `default-prefetch-none › an offscreen viewport override
waits for intersection` read the link's position right after the shell
hydrated. When the document streams the layout as its own segment, React
reveals it a moment later (measured: 179ms); until then the link sits in a
hidden `S:1` node and has no box: `Expected: > 920 Received: 0`.
The three client-urls-slow tests this branch adds run next to it in a local
two-worker dev run, and with them it lost that race in 2 of 2 full runs and 3
of 3 runs of the nine files around it. Alone it passed 4 of 4, and on the same
source without those three tests the nine files pass. On origin/main it passed
2 of 2 full dev runs.
Wait for the link to be visible, then measure. The assertion is unchanged.
1 parent eed288b commit a55c2b5
63 files changed
Lines changed: 3688 additions & 625 deletions
File tree
- apps/docs/content/docs/rango/reference
- packages/rangojs-router
- docs
- design
- internal
- e2e
- test-app/src
- components
- urls
- skills
- client-urls
- hooks
- testing
- src
- __tests__
- browser
- react
- client-urls
- __tests__
- ssr
- testing
- __tests__
- tests
- cloudflare-basic
- e2e
- src
- client-urls
- components
- loaders
- test
- tools
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
337 | 341 | | |
338 | 342 | | |
339 | 343 | | |
340 | 344 | | |
341 | 345 | | |
342 | 346 | | |
343 | | - | |
| 347 | + | |
344 | 348 | | |
345 | | - | |
| 349 | + | |
346 | 350 | | |
347 | 351 | | |
348 | 352 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 73 | + | |
78 | 74 | | |
79 | 75 | | |
80 | 76 | | |
| |||
114 | 110 | | |
115 | 111 | | |
116 | 112 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | 113 | | |
122 | 114 | | |
123 | 115 | | |
| |||
131 | 123 | | |
132 | 124 | | |
133 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
134 | 286 | | |
135 | 287 | | |
136 | 288 | | |
| |||
0 commit comments