Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions e2e/react-start/optional-params/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
node_modules
package-lock.json
yarn.lock

.DS_Store
.cache
.env
.vercel
.output

/build/
/api/
/server/build
/public/build
# Sentry Config File
.env.sentry-build-plugin
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
38 changes: 38 additions & 0 deletions e2e/react-start/optional-params/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "tanstack-react-start-e2e-optional-params",
"private": true,
"sideEffects": false,
"type": "module",
"scripts": {
"dev": "vite dev --port 3002",
"dev:e2e": "vite dev",
"build": "vite build && tsc --noEmit",
"start": "node .output/server/index.mjs",
"test:e2e": "playwright test --project=chromium"
},
"dependencies": {
"@tanstack/react-router": "workspace:^",
"@tanstack/react-router-devtools": "workspace:^",
"@tanstack/react-start": "workspace:^",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"redaxios": "^0.5.1",
"tailwind-merge": "^2.6.0",
"vite": "6.3.5",
"zod": "^3.24.2"
},
"devDependencies": {
"@playwright/test": "^1.50.1",
"@tanstack/router-e2e-utils": "workspace:^",
"@types/node": "^22.10.2",
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@vitejs/plugin-react": "^4.3.4",
"autoprefixer": "^10.4.20",
"combinate": "^1.1.11",
"postcss": "^8.5.1",
"tailwindcss": "^3.4.17",
"typescript": "^5.7.2",
"vite-tsconfig-paths": "^5.1.4"
}
}
35 changes: 35 additions & 0 deletions e2e/react-start/optional-params/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { defineConfig, devices } from '@playwright/test'
import { derivePort } from '@tanstack/router-e2e-utils'
import packageJson from './package.json' with { type: 'json' }

const PORT = derivePort(packageJson.name)
const baseURL = `http://localhost:${PORT}`

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
workers: 1,

reporter: [['line']],

use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL,
},

webServer: {
command: `pnpm build && VITE_SERVER_PORT=${PORT} PORT=${PORT} pnpm start`,
url: baseURL,
reuseExistingServer: !process.env.CI,
stdout: 'pipe',
},

projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],
})
6 changes: 6 additions & 0 deletions e2e/react-start/optional-params/postcss.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions e2e/react-start/optional-params/public/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
console.log('SCRIPT_1 loaded')
window.SCRIPT_1 = true
2 changes: 2 additions & 0 deletions e2e/react-start/optional-params/public/script2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
console.log('SCRIPT_2 loaded')
window.SCRIPT_2 = true
19 changes: 19 additions & 0 deletions e2e/react-start/optional-params/public/site.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "",
"short_name": "",
"icons": [
{
"src": "/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"theme_color": "#ffffff",
"background_color": "#ffffff",
"display": "standalone"
}
19 changes: 19 additions & 0 deletions e2e/react-start/optional-params/src/client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// DO NOT DELETE THIS FILE!!!
// This file is a good smoke test to make sure the custom client entry is working
import { StrictMode, startTransition } from 'react'
import { hydrateRoot } from 'react-dom/client'
import { StartClient } from '@tanstack/react-start'
import { createRouter } from './router'

console.log("[client-entry]: using custom client entry in 'src/client.tsx'")

const router = createRouter()

startTransition(() => {
hydrateRoot(
document,
<StrictMode>
<StartClient router={router} />
</StrictMode>,
)
})
10 changes: 10 additions & 0 deletions e2e/react-start/optional-params/src/components/CustomMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as React from 'react'

export function CustomMessage({ message }: { message: string }) {
return (
<div className="py-2">
<div className="italic">This is a custom message:</div>
<p>{message}</p>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {
ErrorComponent,
Link,
rootRouteId,
useMatch,
useRouter,
} from '@tanstack/react-router'
import type { ErrorComponentProps } from '@tanstack/react-router'

export function DefaultCatchBoundary({ error }: ErrorComponentProps) {
const router = useRouter()
const isRoot = useMatch({
strict: false,
select: (state) => state.id === rootRouteId,
})

console.error(error)

return (
<div className="min-w-0 flex-1 p-4 flex flex-col items-center justify-center gap-6">
<ErrorComponent error={error} />
<div className="flex gap-2 items-center flex-wrap">
<button
onClick={() => {
router.invalidate()
}}
className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded text-white uppercase font-extrabold`}
>
Try Again
</button>
{isRoot ? (
<Link
to="/"
className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded text-white uppercase font-extrabold`}
>
Home
</Link>
) : (
<Link
to="/"
className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded text-white uppercase font-extrabold`}
onClick={(e) => {
e.preventDefault()
window.history.back()
}}
>
Go Back
</Link>
)}
</div>
</div>
)
}
25 changes: 25 additions & 0 deletions e2e/react-start/optional-params/src/components/NotFound.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Link } from '@tanstack/react-router'

export function NotFound({ children }: { children?: any }) {
return (
<div className="space-y-2 p-2" data-testid="default-not-found-component">
<div className="text-gray-600 dark:text-gray-400">
{children || <p>The page you are looking for does not exist.</p>}
</div>
<p className="flex items-center gap-2 flex-wrap">
<button
onClick={() => window.history.back()}
className="bg-emerald-500 text-white px-2 py-1 rounded uppercase font-black text-sm"
>
Go back
</button>
<Link
to="/"
className="bg-cyan-600 text-white px-2 py-1 rounded uppercase font-black text-sm"
>
Start Over
</Link>
</p>
</div>
)
}
26 changes: 26 additions & 0 deletions e2e/react-start/optional-params/src/components/RedirectOnClick.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useServerFn } from '@tanstack/react-start'
import { throwRedirect } from './throwRedirect'

interface RedirectOnClickProps {
target: 'internal' | 'external'
reloadDocument?: boolean
externalHost?: string
}

export function RedirectOnClick({
target,
reloadDocument,
externalHost,
}: RedirectOnClickProps) {
const execute = useServerFn(throwRedirect)
return (
<button
data-testid="redirect-on-click"
onClick={() =>
execute({ data: { target, reloadDocument, externalHost } })
}
>
click me
</button>
)
}
23 changes: 23 additions & 0 deletions e2e/react-start/optional-params/src/components/throwRedirect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { redirect } from '@tanstack/react-router'
import { createServerFn } from '@tanstack/react-start'

export const throwRedirect = createServerFn()
.validator(
(opts: {
target: 'internal' | 'external'
reloadDocument?: boolean
externalHost?: string
}) => opts,
)
.handler((ctx) => {
if (ctx.data.target === 'internal') {
throw redirect({
to: '/blog/{-$category}',
reloadDocument: ctx.data.reloadDocument,
})
}
const href = ctx.data.externalHost ?? 'http://example.com'
throw redirect({
href,
})
})
Loading
Loading