Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions e2e/react-start/basic-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"react-dom": "^19.0.0"
},
"devDependencies": {
"@cloudflare/vite-plugin": "^1.13.7",
"@cloudflare/vite-plugin": "^1.15.1",
"@playwright/test": "^1.50.1",
"@tailwindcss/postcss": "^4.1.15",
"@tanstack/router-e2e-utils": "workspace:^",
Expand All @@ -33,6 +33,6 @@
"typescript": "^5.7.2",
"vite": "^7.1.7",
"vite-tsconfig-paths": "^5.1.4",
"wrangler": "^4.40.2"
"wrangler": "^4.49.1"
}
}
24 changes: 21 additions & 3 deletions e2e/react-start/basic-cloudflare/src/routeTree.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.

import { Route as rootRouteImport } from './routes/__root'
import { Route as StaticRouteImport } from './routes/static'
import { Route as IndexRouteImport } from './routes/index'

const StaticRoute = StaticRouteImport.update({
id: '/static',
path: '/static',
getParentRoute: () => rootRouteImport,
} as any)
const IndexRoute = IndexRouteImport.update({
id: '/',
path: '/',
Expand All @@ -19,28 +25,39 @@ const IndexRoute = IndexRouteImport.update({

export interface FileRoutesByFullPath {
'/': typeof IndexRoute
'/static': typeof StaticRoute
}
export interface FileRoutesByTo {
'/': typeof IndexRoute
'/static': typeof StaticRoute
}
export interface FileRoutesById {
__root__: typeof rootRouteImport
'/': typeof IndexRoute
'/static': typeof StaticRoute
}
export interface FileRouteTypes {
fileRoutesByFullPath: FileRoutesByFullPath
fullPaths: '/'
fullPaths: '/' | '/static'
fileRoutesByTo: FileRoutesByTo
to: '/'
id: '__root__' | '/'
to: '/' | '/static'
id: '__root__' | '/' | '/static'
fileRoutesById: FileRoutesById
}
export interface RootRouteChildren {
IndexRoute: typeof IndexRoute
StaticRoute: typeof StaticRoute
}

declare module '@tanstack/react-router' {
interface FileRoutesByPath {
'/static': {
id: '/static'
path: '/static'
fullPath: '/static'
preLoaderRoute: typeof StaticRouteImport
parentRoute: typeof rootRouteImport
}
'/': {
id: '/'
path: '/'
Expand All @@ -53,6 +70,7 @@ declare module '@tanstack/react-router' {

const rootRouteChildren: RootRouteChildren = {
IndexRoute: IndexRoute,
StaticRoute: StaticRoute,
}
export const routeTree = rootRouteImport
._addFileChildren(rootRouteChildren)
Expand Down
25 changes: 25 additions & 0 deletions e2e/react-start/basic-cloudflare/src/routes/static.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { createFileRoute } from '@tanstack/react-router'
import { createServerFn } from '@tanstack/react-start'
import { env } from 'cloudflare:workers'

export const Route = createFileRoute('/static')({
loader: () => getData(),
component: StaticPage,
})

const getData = createServerFn().handler(() => {
return {
myVar: env.MY_VAR,
}
})

function StaticPage() {
const data = Route.useLoaderData()

return (
<div>
<h1 data-testid="static-heading">Static Page</h1>
<p data-testid="static-content">The value is {data.myVar}</p>
</div>
)
}
15 changes: 15 additions & 0 deletions e2e/react-start/basic-cloudflare/tests/app.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { existsSync } from 'node:fs'
import { join } from 'node:path'
import { expect } from '@playwright/test'
import { test } from '@tanstack/router-e2e-utils'

Expand All @@ -14,3 +16,16 @@ test('returns the correct value from a Cloudflare binding', async ({
await page.goto('/')
await expect(page.getByTestId('myVar')).toHaveText('Hello from Cloudflare')
})

test('prerender with Cloudflare Workers runtime', async ({ page }) => {
// Verify the static page was prerendered during build
const distDir = join(process.cwd(), 'dist', 'client')
expect(existsSync(join(distDir, 'static', 'index.html'))).toBe(true)

// Verify the page loads correctly
await page.goto('/static')
await expect(page.getByTestId('static-heading')).toHaveText('Static Page')
await expect(page.getByTestId('static-content')).toHaveText(
'The value is Hello from Cloudflare',
)
})
7 changes: 6 additions & 1 deletion e2e/react-start/basic-cloudflare/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ export default defineConfig({
projects: ['./tsconfig.json'],
}),
cloudflare({ viteEnvironment: { name: 'ssr' }, inspectorPort: false }),
tanstackStart(),
tanstackStart({
Comment thread
birkskyum marked this conversation as resolved.
prerender: {
enabled: true,
filter: (page) => page.path === '/static',
},
}),
viteReact(),
],
})
Loading
Loading