Skip to content
Open
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
12 changes: 12 additions & 0 deletions e2e/react-start/basic-nitro-spa/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node_modules
.DS_Store
.cache
.env
dist
.output
.nitro

/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
42 changes: 42 additions & 0 deletions e2e/react-start/basic-nitro-spa/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "tanstack-react-start-e2e-basic-nitro-spa",
"private": true,
"sideEffects": false,
"type": "module",
"scripts": {
"dev:v2": "vite dev -c vite.config.v2.ts --port 3000",
"dev:v3": "vite dev -c vite.config.v3.ts --port 3000",
"dev:e2e:v2": "vite dev -c vite.config.v2.ts",
"dev:e2e:v3": "vite dev -c vite.config.v3.ts",
"build:v2": "vite build -c vite.config.v2.ts && tsc --noEmit",
"build:v3": "vite build -c vite.config.v3.ts && tsc --noEmit",
"preview:v2": "vite preview -c vite.config.v2.ts",
"preview:v3": "vite preview -c vite.config.v3.ts",
"test:e2e:shared": "rm -rf port*.txt; playwright test --project=chromium",
"test:e2e:v2": "rm -rf .output dist .nitro && NITRO_VARIANT=v2 pnpm run test:e2e:shared",
"test:e2e:v3": "rm -rf .output dist .nitro && NITRO_VARIANT=v3 pnpm run test:e2e:shared",
"test:e2e": "pnpm run test:e2e:v2 && pnpm run test:e2e:v3"
},
"dependencies": {
"@tanstack/react-router": "workspace:^",
"@tanstack/react-router-devtools": "workspace:^",
"@tanstack/react-start": "workspace:^",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@playwright/test": "^1.50.1",
"@tailwindcss/postcss": "^4.1.15",
"@tanstack/router-e2e-utils": "workspace:^",
"@tanstack/nitro-v2-vite-plugin": "workspace:^",
"@types/node": "^22.10.2",
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"nitro": "npm:nitro-nightly@latest",
"postcss": "^8.5.1",
"tailwindcss": "^4.1.15",
"typescript": "^5.7.2",
"vite": "^7.1.7",
"vite-tsconfig-paths": "^5.1.4"
}
}
44 changes: 44 additions & 0 deletions e2e/react-start/basic-nitro-spa/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { defineConfig, devices } from '@playwright/test'
import { getTestServerPort } from '@tanstack/router-e2e-utils'
import packageJson from './package.json' with { type: 'json' }

const PORT = await getTestServerPort(packageJson.name)
const baseURL = `http://localhost:${PORT}`
const nitroVariant = process.env.NITRO_VARIANT
if (nitroVariant !== 'v2' && nitroVariant !== 'v3') {
throw new Error('Set NITRO_VARIANT to "v2" or "v3" for Nitro e2e tests.')
}
const buildScript = nitroVariant === 'v2' ? 'build:v2' : 'build:v3'
const buildCommand = `pnpm run ${buildScript}`

/**
* 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: {
// Note: We run node directly instead of vite preview because Nitro's
// configurePreviewServer spawns on a random port. The prerendering during
// build uses vite.preview() correctly.
command: `${buildCommand} && PORT=${PORT} node .output/server/index.mjs`,
url: baseURL,
reuseExistingServer: !process.env.CI,
stdout: 'pipe',
},

projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],
})
5 changes: 5 additions & 0 deletions e2e/react-start/basic-nitro-spa/postcss.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
plugins: {
'@tailwindcss/postcss': {},
},
}
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.
19 changes: 19 additions & 0 deletions e2e/react-start/basic-nitro-spa/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"
}
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-sm text-white uppercase font-extrabold`}
>
Try Again
</button>
{isRoot ? (
<Link
to="/"
className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded-sm text-white uppercase font-extrabold`}
>
Home
</Link>
) : (
<Link
to="/"
className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded-sm text-white uppercase font-extrabold`}
onClick={(e) => {
e.preventDefault()
window.history.back()
}}
>
Go Back
</Link>
Comment on lines +39 to +48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Use a button element instead of Link for the "Go Back" action.

The Link component with to="/" generates an href="/" attribute, but the onClick handler prevents default navigation and uses window.history.back() instead. This creates several issues:

  • Accessibility: Screen readers will announce this as a link to the home page ("/"), but it actually navigates backward in history.
  • User experience: Right-click "Open in new tab", middle-click, or keyboard navigation could navigate to "/" instead of going back.
  • Semantics: A non-navigation action (going back in history) should use a button element, not a Link.
🔎 Recommended fix
-        <Link
-          to="/"
+        <button
+          onClick={() => {
+            window.history.back()
+          }}
           className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded-sm text-white uppercase font-extrabold`}
-          onClick={(e) => {
-            e.preventDefault()
-            window.history.back()
-          }}
         >
           Go Back
-        </Link>
+        </button>
🤖 Prompt for AI Agents
In e2e/react-start/basic-nitro-spa/src/components/DefaultCatchBoundary.tsx
around lines 39–48, replace the Link element used for the "Go Back" action with
a semantic button: remove the to="/" href, render a <button type="button"> that
keeps the same className/styling, attach the onClick handler to call
window.history.back(), and include an accessible label (e.g. aria-label="Go
back") if the visible text is not sufficient; ensure you no longer call
e.preventDefault() since there is no link navigation to prevent.

)}
</div>
</div>
)
}
25 changes: 25 additions & 0 deletions e2e/react-start/basic-nitro-spa/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-sm uppercase font-black text-sm"
>
Go back
</button>
<Link
to="/"
className="bg-cyan-600 text-white px-2 py-1 rounded-sm uppercase font-black text-sm"
>
Start Over
</Link>
</p>
</div>
)
}
86 changes: 86 additions & 0 deletions e2e/react-start/basic-nitro-spa/src/routeTree.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* eslint-disable */

// @ts-nocheck

// noinspection JSUnusedGlobalSymbols

// This file was automatically generated by TanStack Router.
// You should NOT make any changes in this file as it will be overwritten.
// 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: '/',
getParentRoute: () => rootRouteImport,
} as any)

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: '/' | '/static'
fileRoutesByTo: FileRoutesByTo
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: '/'
fullPath: '/'
preLoaderRoute: typeof IndexRouteImport
parentRoute: typeof rootRouteImport
}
}
}

const rootRouteChildren: RootRouteChildren = {
IndexRoute: IndexRoute,
StaticRoute: StaticRoute,
}
export const routeTree = rootRouteImport
._addFileChildren(rootRouteChildren)
._addFileTypes<FileRouteTypes>()

import type { getRouter } from './router.tsx'
import type { createStart } from '@tanstack/react-start'
declare module '@tanstack/react-start' {
interface Register {
ssr: true
router: Awaited<ReturnType<typeof getRouter>>
}
}
16 changes: 16 additions & 0 deletions e2e/react-start/basic-nitro-spa/src/router.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createRouter } from '@tanstack/react-router'
import { routeTree } from './routeTree.gen'
import { DefaultCatchBoundary } from './components/DefaultCatchBoundary'
import { NotFound } from './components/NotFound'

export function getRouter() {
const router = createRouter({
routeTree,
defaultPreload: 'intent',
defaultErrorComponent: DefaultCatchBoundary,
defaultNotFoundComponent: () => <NotFound />,
scrollRestoration: true,
})

return router
}
73 changes: 73 additions & 0 deletions e2e/react-start/basic-nitro-spa/src/routes/__root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/// <reference types="vite/client" />
import {
HeadContent,
Link,
Scripts,
createRootRoute,
} from '@tanstack/react-router'
import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
import * as React from 'react'
import { DefaultCatchBoundary } from '~/components/DefaultCatchBoundary'
import { NotFound } from '~/components/NotFound'
import appCss from '~/styles/app.css?url'
import { seo } from '~/utils/seo'

export const Route = createRootRoute({
head: () => ({
meta: [
{
charSet: 'utf-8',
},
{
name: 'viewport',
content: 'width=device-width, initial-scale=1',
},
...seo({
title: 'TanStack Start + Nitro E2E Test',
description: 'Testing nitro integration with TanStack Start',
}),
],
links: [
{ rel: 'stylesheet', href: appCss },
{ rel: 'icon', href: '/favicon.ico' },
],
}),
errorComponent: DefaultCatchBoundary,
notFoundComponent: () => <NotFound />,
shellComponent: RootDocument,
})

function RootDocument({ children }: { children: React.ReactNode }) {
return (
<html>
<head>
<HeadContent />
</head>
<body>
<div className="p-2 flex gap-2 text-lg">
<Link
to="/"
activeProps={{
className: 'font-bold',
}}
activeOptions={{ exact: true }}
>
Home
</Link>
<Link
to="/static"
activeProps={{
className: 'font-bold',
}}
>
Static
</Link>
</div>
<hr />
{children}
<TanStackRouterDevtools position="bottom-right" />
<Scripts />
</body>
</html>
)
}
Loading
Loading