Skip to content

Commit c70a2ce

Browse files
ryansolidclaudecursoragent
committed
fix(solid-router): declare a not-found whose unloaded match stays pending
The Transitioner tells the pending offer (`offerPending`, published while the loaders run) from the publish that lands by a match with `status: 'pending'`. A not-found under a route with a loader lands with that route's match pending too: it sits below the not-found boundary and never loads. So the landing publish was taken for the offer, published undeclared, and the navigation had no record. Solid Router records an unmatched path under a route with data like any other, named by its pathname. A publish is the offer only when a match at or above the not-found boundary is pending. With a pending component, router-core offers the same matches (pending below the boundary) before it lands; that offer already shows the destination, the not-found rendering above the pending match, so it is the publish declared and the landing that repeats it is not. Co-authored-by: Claude <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 0d78d79 commit c70a2ce

3 files changed

Lines changed: 55 additions & 8 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/solid-router': patch
3+
---
4+
5+
Observe tier (Solid's dev and observe builds only): a not-found under a route with a loader (`/users/2/nope` under `/users/$id`) is recorded, named by its pathname, as `@solidjs/router` records an unmatched path. The route's match sits below the not-found boundary and never loads, so it stays `pending` in the publish that lands, which was mistaken for the pending offer and published undeclared: the navigation had no record. Only a match pending at or above the not-found boundary marks the pending offer now. Nothing changes in production, where `OBSERVE` is undefined.

‎packages/solid-router/src/Transitioner.tsx‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ import type { AnyRouteMatch, ParsedLocation } from '@tanstack/router-core'
99
/** The history change was the arrival's own canonicalization, not a request. */
1010
const ARRIVAL = Symbol()
1111

12+
/**
13+
* `offerPending`'s publish: a match still `pending` at or above the
14+
* not-found boundary. The matches below a not-found never load, and stay
15+
* `pending` in the publish that lands; an offer whose pending match is
16+
* below one already shows the destination, the not-found.
17+
*/
18+
function isPendingOffer(matches: Array<AnyRouteMatch>) {
19+
for (const match of matches) {
20+
if (match.status === 'pending') return true
21+
if (match._notFound) return false
22+
}
23+
return false
24+
}
25+
1226
function getResolvedLocation(router: ReturnType<typeof useRouter>) {
1327
const resolvedLocation = router.stores.resolvedLocation.get()
1428
if (
@@ -60,13 +74,10 @@ export function Transitioner() {
6074
const ack: Ack = [expectedMatches, resolve]
6175
acks.push(ack)
6276
let publish = fn
63-
// The pending offer (`offerPending`, a match with `status: 'pending'`)
64-
// is not the destination: published undeclared, the request kept for
65-
// the publish that lands. Every other publish answers the request.
66-
if (
67-
Solid.OBSERVE !== undefined &&
68-
!expectedMatches.some((match) => match.status === 'pending')
69-
) {
77+
// The pending offer (`offerPending`) is not the destination: published
78+
// undeclared, the request kept for the publish that lands. Every other
79+
// publish answers the request.
80+
if (Solid.OBSERVE !== undefined && !isPendingOffer(expectedMatches)) {
7081
const answered = request
7182
request = undefined
7283
const ref =

‎packages/solid-router/tests/observe-navigation.test.tsx‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms))
3838
const navigations = () =>
3939
attribution.history('navigation').filter((nav) => !nav.initial)
4040

41-
function makeRouter(loaderMs: number, initialEntry = '/') {
41+
function makeRouter(
42+
loaderMs: number,
43+
initialEntry = '/',
44+
options: { pendingComponent?: boolean } = {},
45+
) {
4246
const rootRoute = createRootRoute({
4347
component: () => (
4448
<>
@@ -105,6 +109,10 @@ function makeRouter(loaderMs: number, initialEntry = '/') {
105109
return createRouter({
106110
routeTree,
107111
history: createMemoryHistory({ initialEntries: [initialEntry] }),
112+
...(options.pendingComponent && {
113+
defaultPendingComponent: () => <p>pending</p>,
114+
defaultPendingMs: 0,
115+
}),
108116
})
109117
}
110118

@@ -332,6 +340,29 @@ test('a not-found is named by its pathname, not by the route above it', async ()
332340
])
333341
})
334342

343+
test.each([false, true])(
344+
'a not-found under a route with a loader is declared, its unloaded match below the boundary notwithstanding (pending component: %s)',
345+
async (pendingComponent) => {
346+
// The not-found boundary renders above `/users/$id`, whose loader never
347+
// runs: its match stays `pending` in the publish that lands. With a
348+
// pending component the offer publishes the same matches first, and
349+
// already shows the destination — the not-found, from above the pending
350+
// match — so it is the publish declared.
351+
const router = makeRouter(0, '/', { pendingComponent })
352+
render(() => <RouterProvider router={router} />)
353+
await waitFor(() => expect(screen.getByTestId('home')).toBeTruthy())
354+
355+
await router.navigate({ to: '/users/2/nope' as any })
356+
await sleep(20)
357+
358+
const navs = navigations()
359+
expect(navs.map((nav) => [nav.name, nav.to, nav.from])).toEqual([
360+
['/users/2/nope', '/users/2/nope', '/'],
361+
])
362+
expect(navs[0]!.outcome).toBe('committed')
363+
},
364+
)
365+
335366
test('params are the strings the path bound, before `params.parse`', async () => {
336367
const router = makeRouter(0)
337368
render(() => <RouterProvider router={router} />)

0 commit comments

Comments
 (0)