Skip to content

Commit e99e855

Browse files
add regression tests (#7557)
1 parent 65ad906 commit e99e855

6 files changed

Lines changed: 139 additions & 0 deletions

File tree

‎e2e/react-start/streaming-ssr/src/routeTree.gen.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { Route as QueryHeavyRouteImport } from './routes/query-heavy'
1616
import { Route as NestedDeferredRouteImport } from './routes/nested-deferred'
1717
import { Route as ManyPromisesRouteImport } from './routes/many-promises'
1818
import { Route as FastSerialRouteImport } from './routes/fast-serial'
19+
import { Route as DeferredRejectionRouteImport } from './routes/deferred-rejection'
1920
import { Route as DeferredRouteImport } from './routes/deferred'
2021
import { Route as ConcurrentRouteImport } from './routes/concurrent'
2122
import { Route as IndexRouteImport } from './routes/index'
@@ -55,6 +56,11 @@ const FastSerialRoute = FastSerialRouteImport.update({
5556
path: '/fast-serial',
5657
getParentRoute: () => rootRouteImport,
5758
} as any)
59+
const DeferredRejectionRoute = DeferredRejectionRouteImport.update({
60+
id: '/deferred-rejection',
61+
path: '/deferred-rejection',
62+
getParentRoute: () => rootRouteImport,
63+
} as any)
5864
const DeferredRoute = DeferredRouteImport.update({
5965
id: '/deferred',
6066
path: '/deferred',
@@ -75,6 +81,7 @@ export interface FileRoutesByFullPath {
7581
'/': typeof IndexRoute
7682
'/concurrent': typeof ConcurrentRoute
7783
'/deferred': typeof DeferredRoute
84+
'/deferred-rejection': typeof DeferredRejectionRoute
7885
'/fast-serial': typeof FastSerialRoute
7986
'/many-promises': typeof ManyPromisesRoute
8087
'/nested-deferred': typeof NestedDeferredRoute
@@ -87,6 +94,7 @@ export interface FileRoutesByTo {
8794
'/': typeof IndexRoute
8895
'/concurrent': typeof ConcurrentRoute
8996
'/deferred': typeof DeferredRoute
97+
'/deferred-rejection': typeof DeferredRejectionRoute
9098
'/fast-serial': typeof FastSerialRoute
9199
'/many-promises': typeof ManyPromisesRoute
92100
'/nested-deferred': typeof NestedDeferredRoute
@@ -100,6 +108,7 @@ export interface FileRoutesById {
100108
'/': typeof IndexRoute
101109
'/concurrent': typeof ConcurrentRoute
102110
'/deferred': typeof DeferredRoute
111+
'/deferred-rejection': typeof DeferredRejectionRoute
103112
'/fast-serial': typeof FastSerialRoute
104113
'/many-promises': typeof ManyPromisesRoute
105114
'/nested-deferred': typeof NestedDeferredRoute
@@ -114,6 +123,7 @@ export interface FileRouteTypes {
114123
| '/'
115124
| '/concurrent'
116125
| '/deferred'
126+
| '/deferred-rejection'
117127
| '/fast-serial'
118128
| '/many-promises'
119129
| '/nested-deferred'
@@ -126,6 +136,7 @@ export interface FileRouteTypes {
126136
| '/'
127137
| '/concurrent'
128138
| '/deferred'
139+
| '/deferred-rejection'
129140
| '/fast-serial'
130141
| '/many-promises'
131142
| '/nested-deferred'
@@ -138,6 +149,7 @@ export interface FileRouteTypes {
138149
| '/'
139150
| '/concurrent'
140151
| '/deferred'
152+
| '/deferred-rejection'
141153
| '/fast-serial'
142154
| '/many-promises'
143155
| '/nested-deferred'
@@ -151,6 +163,7 @@ export interface RootRouteChildren {
151163
IndexRoute: typeof IndexRoute
152164
ConcurrentRoute: typeof ConcurrentRoute
153165
DeferredRoute: typeof DeferredRoute
166+
DeferredRejectionRoute: typeof DeferredRejectionRoute
154167
FastSerialRoute: typeof FastSerialRoute
155168
ManyPromisesRoute: typeof ManyPromisesRoute
156169
NestedDeferredRoute: typeof NestedDeferredRoute
@@ -211,6 +224,13 @@ declare module '@tanstack/react-router' {
211224
preLoaderRoute: typeof FastSerialRouteImport
212225
parentRoute: typeof rootRouteImport
213226
}
227+
'/deferred-rejection': {
228+
id: '/deferred-rejection'
229+
path: '/deferred-rejection'
230+
fullPath: '/deferred-rejection'
231+
preLoaderRoute: typeof DeferredRejectionRouteImport
232+
parentRoute: typeof rootRouteImport
233+
}
214234
'/deferred': {
215235
id: '/deferred'
216236
path: '/deferred'
@@ -239,6 +259,7 @@ const rootRouteChildren: RootRouteChildren = {
239259
IndexRoute: IndexRoute,
240260
ConcurrentRoute: ConcurrentRoute,
241261
DeferredRoute: DeferredRoute,
262+
DeferredRejectionRoute: DeferredRejectionRoute,
242263
FastSerialRoute: FastSerialRoute,
243264
ManyPromisesRoute: ManyPromisesRoute,
244265
NestedDeferredRoute: NestedDeferredRoute,

‎e2e/react-start/streaming-ssr/src/routes/__root.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ function RootDocument({ children }: { children: React.ReactNode }) {
8484
<Link to="/deferred" style={{ marginRight: '10px' }}>
8585
Deferred
8686
</Link>
87+
<Link to="/deferred-rejection" style={{ marginRight: '10px' }}>
88+
Deferred Rejection
89+
</Link>
8790
<Link to="/stream" style={{ marginRight: '10px' }}>
8891
Stream
8992
</Link>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Await, createFileRoute } from '@tanstack/react-router'
2+
import { Suspense } from 'react'
3+
4+
const deferredErrorMessage = 'Error in deferred object'
5+
6+
export const Route = createFileRoute('/deferred-rejection')({
7+
loader: async () => {
8+
return {
9+
deferredData: new Promise<string>((_resolve, reject) => {
10+
setTimeout(() => {
11+
reject(new Error(deferredErrorMessage))
12+
}, 1000)
13+
}),
14+
}
15+
},
16+
errorComponent: ({ error }) => (
17+
<div data-testid="deferred-error-boundary">{error.message}</div>
18+
),
19+
component: DeferredRejection,
20+
})
21+
22+
function DeferredRejection() {
23+
const { deferredData } = Route.useLoaderData()
24+
25+
return (
26+
<div style={{ padding: '20px' }}>
27+
<h2>Deferred Rejection Test</h2>
28+
<Suspense
29+
fallback={<div data-testid="deferred-loading">Loading deferred...</div>}
30+
>
31+
<Await
32+
promise={deferredData}
33+
children={(data) => <div data-testid="deferred-data">{data}</div>}
34+
/>
35+
</Suspense>
36+
</div>
37+
)
38+
}

‎e2e/react-start/streaming-ssr/src/routes/index.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ function Index() {
2222
</Link>{' '}
2323
- Tests deferred promises resolving after initial render
2424
</li>
25+
<li>
26+
<Link to="/deferred-rejection" data-testid="link-deferred-rejection">
27+
Deferred Rejection
28+
</Link>{' '}
29+
- Tests deferred promise rejections render through the error boundary
30+
</li>
2531
<li>
2632
<Link to="/stream" data-testid="link-stream">
2733
ReadableStream
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expect, test } from './fixtures'
2+
3+
test.use({
4+
whitelistErrors: ['Error in deferred object'],
5+
})
6+
7+
test('rejected deferred Await renders the route error boundary without killing SSR', async ({
8+
page,
9+
}) => {
10+
await page.goto('/deferred-rejection')
11+
12+
await expect(page.getByTestId('deferred-error-boundary')).toContainText(
13+
'Error in deferred object',
14+
{ timeout: 5000 },
15+
)
16+
17+
await page.goto('/sync-only')
18+
await expect(page.getByTestId('sync-message')).toContainText(
19+
'Hello from sync loader!',
20+
)
21+
})

‎packages/router-core/tests/build-location.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,56 @@ describe('buildLocation - search params', () => {
509509
})
510510
})
511511

512+
test('retainSearchParams(true) should preserve nested search when navigating to the same route', async () => {
513+
const rootRoute = new BaseRootRoute({
514+
validateSearch: (search: Record<string, unknown>) => ({
515+
filter: Array.isArray(search.filter) ? search.filter : ['default'],
516+
filterOrder:
517+
typeof search.filterOrder === 'object' && search.filterOrder
518+
? search.filterOrder
519+
: {},
520+
anotherFilterOrder: Array.isArray(search.anotherFilterOrder)
521+
? search.anotherFilterOrder
522+
: [],
523+
}),
524+
search: {
525+
middlewares: [retainSearchParams(true)],
526+
},
527+
})
528+
const indexRoute = new BaseRoute({
529+
getParentRoute: () => rootRoute,
530+
path: '/',
531+
})
532+
533+
const routeTree = rootRoute.addChildren([indexRoute])
534+
535+
const router = createTestRouter({
536+
routeTree,
537+
history: createMemoryHistory({ initialEntries: ['/'] }),
538+
})
539+
540+
await router.load()
541+
542+
await router.navigate({
543+
to: '/',
544+
search: { filterOrder: { filter1: [1], filter2: [0] } },
545+
} as any)
546+
547+
expect(router.latestLocation.search).toEqual({
548+
filter: ['default'],
549+
filterOrder: { filter1: [1], filter2: [0] },
550+
anotherFilterOrder: [],
551+
})
552+
553+
await router.navigate({ to: '/' })
554+
555+
expect(router.latestLocation.search).toEqual({
556+
filter: ['default'],
557+
filterOrder: { filter1: [1], filter2: [0] },
558+
anotherFilterOrder: [],
559+
})
560+
})
561+
512562
test('retainSearchParams should preserve root search during navigation', async () => {
513563
const rootRoute = new BaseRootRoute({
514564
validateSearch: (search: Record<string, unknown>) => ({

0 commit comments

Comments
 (0)