Skip to content

Commit d09f5da

Browse files
fix: spa mode with prerendering (#4811)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 73ab338 commit d09f5da

File tree

18 files changed

+58
-55
lines changed

18 files changed

+58
-55
lines changed

e2e/react-start/spa-mode/src/routes/__root.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
createRootRoute,
1010
useRouterState,
1111
} from '@tanstack/react-router'
12-
import appCss from '~/styles/app.css?url'
1312
import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
13+
import appCss from '~/styles/app.css?url'
1414

1515
export const Route = createRootRoute({
1616
head: () => ({
@@ -28,9 +28,6 @@ export const Route = createRootRoute({
2828
],
2929
links: [{ rel: 'stylesheet', href: appCss }],
3030
}),
31-
ssr: () => {
32-
throw new Error('ssr() should not be called in SPA mode')
33-
},
3431
beforeLoad: () => {
3532
console.log(
3633
`beforeLoad for ${Route.id} called on the ${typeof window !== 'undefined' ? 'client' : 'server'}`,

e2e/react-start/spa-mode/src/routes/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Link, createFileRoute, linkOptions } from '@tanstack/react-router'
1+
import { Link, createFileRoute } from '@tanstack/react-router'
22

33
export const Route = createFileRoute('/')({
44
component: Home,

e2e/react-start/spa-mode/src/routes/posts.$postId.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { createFileRoute } from '@tanstack/react-router'
22

33
export const Route = createFileRoute('/posts/$postId')({
4-
ssr: () => {
5-
throw new Error('ssr() should not be called in SPA mode')
6-
},
74
beforeLoad: () => {
85
console.log(
96
`beforeLoad for ${Route.id} called on the ${typeof window !== 'undefined' ? 'client' : 'server'}`,

e2e/react-start/spa-mode/src/routes/posts.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { Outlet, createFileRoute } from '@tanstack/react-router'
22

33
export const Route = createFileRoute('/posts')({
4-
ssr: () => {
5-
throw new Error('ssr() should not be called in SPA mode')
6-
},
74
beforeLoad: () => {
85
console.log(
96
`beforeLoad for ${Route.id} called on the ${typeof window !== 'undefined' ? 'client' : 'server'}`,

e2e/react-start/spa-mode/tests/app.spec.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { expect, Page } from '@playwright/test'
1+
import { expect } from '@playwright/test'
22
import { test } from './fixture'
3+
import type { Page } from '@playwright/test'
34

45
async function runTest(
56
page: Page,
67
expectedData: {
78
root: 'server' | 'client'
8-
posts: 'client'
9-
postId: 'client'
9+
posts: 'server' | 'client'
10+
postId: 'server' | 'client'
1011
},
1112
) {
1213
// wait for page to be loaded by waiting for the leaf route to be rendered
@@ -16,23 +17,23 @@ async function runTest(
1617
await Promise.all(
1718
Object.entries(expectedData).map(async ([route, expectedData]) => {
1819
await expect(page.getByTestId(`${route}-loader`)).toContainText(
19-
expectedData!,
20+
expectedData,
2021
)
2122
await expect(page.getByTestId(`${route}-context`)).toContainText(
22-
expectedData!,
23+
expectedData,
2324
)
2425
}),
2526
)
2627
await expect(page.getByTestId('router-isLoading')).toContainText('false')
2728
await expect(page.getByTestId('router-status')).toContainText('idle')
2829
}
2930
test.describe('SPA mode', () => {
30-
test(`directly visiting /posts/1`, async ({ page }) => {
31+
test(`directly visiting prerendered /posts/1`, async ({ page }) => {
3132
await page.goto('/posts/1')
3233
await runTest(page, {
3334
root: 'server',
34-
posts: 'client',
35-
postId: 'client',
35+
posts: 'server',
36+
postId: 'server',
3637
})
3738
})
3839

e2e/solid-start/spa-mode/src/routes/__root.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
/// <reference types="vite/client" />
22
import {
33
ClientOnly,
4-
HeadContent,
54
Link,
65
Outlet,
76
Scripts,
87
createRootRoute,
98
useRouterState,
109
} from '@tanstack/solid-router'
10+
import { TanStackRouterDevtools } from '@tanstack/solid-router-devtools'
1111
import type * as Solid from 'solid-js'
1212
import appCss from '~/styles/app.css?url'
13-
import { TanStackRouterDevtools } from '@tanstack/solid-router-devtools'
1413

1514
export const Route = createRootRoute({
1615
head: () => ({
@@ -28,9 +27,6 @@ export const Route = createRootRoute({
2827
],
2928
links: [{ rel: 'stylesheet', href: appCss }],
3029
}),
31-
ssr: () => {
32-
throw new Error('ssr() should not be called in SPA mode')
33-
},
3430
beforeLoad: () => {
3531
console.log(
3632
`beforeLoad for ${Route.id} called on the ${typeof window !== 'undefined' ? 'client' : 'server'}`,

e2e/solid-start/spa-mode/src/routes/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Link, createFileRoute, linkOptions } from '@tanstack/solid-router'
1+
import { Link, createFileRoute } from '@tanstack/solid-router'
22

33
export const Route = createFileRoute('/')({
44
component: Home,

e2e/solid-start/spa-mode/src/routes/posts.$postId.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { createFileRoute } from '@tanstack/solid-router'
22

33
export const Route = createFileRoute('/posts/$postId')({
4-
ssr: () => {
5-
throw new Error('ssr() should not be called in SPA mode')
6-
},
74
beforeLoad: () => {
85
console.log(
96
`beforeLoad for ${Route.id} called on the ${typeof window !== 'undefined' ? 'client' : 'server'}`,

e2e/solid-start/spa-mode/src/routes/posts.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { Outlet, createFileRoute } from '@tanstack/solid-router'
22

33
export const Route = createFileRoute('/posts')({
4-
ssr: () => {
5-
throw new Error('ssr() should not be called in SPA mode')
6-
},
74
beforeLoad: () => {
85
console.log(
96
`beforeLoad for ${Route.id} called on the ${typeof window !== 'undefined' ? 'client' : 'server'}`,

e2e/solid-start/spa-mode/tests/app.spec.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { expect, Page } from '@playwright/test'
1+
import { expect } from '@playwright/test'
22
import { test } from './fixture'
3+
import type { Page } from '@playwright/test'
34

45
async function runTest(
56
page: Page,
67
expectedData: {
78
root: 'server' | 'client'
8-
posts: 'client'
9-
postId: 'client'
9+
posts: 'server' | 'client'
10+
postId: 'server' | 'client'
1011
},
1112
) {
1213
// wait for page to be loaded by waiting for the leaf route to be rendered
@@ -16,23 +17,23 @@ async function runTest(
1617
await Promise.all(
1718
Object.entries(expectedData).map(async ([route, expectedData]) => {
1819
await expect(page.getByTestId(`${route}-loader`)).toContainText(
19-
expectedData!,
20+
expectedData,
2021
)
2122
await expect(page.getByTestId(`${route}-context`)).toContainText(
22-
expectedData!,
23+
expectedData,
2324
)
2425
}),
2526
)
2627
await expect(page.getByTestId('router-isLoading')).toContainText('false')
2728
await expect(page.getByTestId('router-status')).toContainText('idle')
2829
}
2930
test.describe('SPA mode', () => {
30-
test(`directly visiting /posts/1`, async ({ page }) => {
31+
test(`directly visiting prerendered /posts/1`, async ({ page }) => {
3132
await page.goto('/posts/1')
3233
await runTest(page, {
3334
root: 'server',
34-
posts: 'client',
35-
postId: 'client',
35+
posts: 'server',
36+
postId: 'server',
3637
})
3738
})
3839

0 commit comments

Comments
 (0)