-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(router-ssr): ensure charset meta is placed before dehydration script #5038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jsedlacek
wants to merge
4
commits into
TanStack:main
Choose a base branch
from
jsedlacek:charset-bug
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
**/build | ||
**/public | ||
pnpm-lock.yaml | ||
routeTree.gen.ts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "tanstack-react-start-e2e-encoding", | ||
"private": true, | ||
"sideEffects": false, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite dev --port 3000", | ||
"dev:e2e": "vite dev", | ||
"build": "vite build && tsc --noEmit", | ||
"start": "node .output/server/index.mjs", | ||
"test:e2e": "rm -rf port*.txt; 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" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { defineConfig, devices } from '@playwright/test' | ||
import { | ||
getDummyServerPort, | ||
getTestServerPort, | ||
} from '@tanstack/router-e2e-utils' | ||
import packageJson from './package.json' with { type: 'json' } | ||
|
||
const PORT = await getTestServerPort(packageJson.name) | ||
const EXTERNAL_PORT = await getDummyServerPort(packageJson.name) | ||
const baseURL = `http://localhost:${PORT}` | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: './tests', | ||
workers: 1, | ||
|
||
reporter: [['line']], | ||
|
||
globalSetup: './tests/setup/global.setup.ts', | ||
globalTeardown: './tests/setup/global.teardown.ts', | ||
|
||
use: { | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
baseURL, | ||
}, | ||
|
||
webServer: { | ||
command: `VITE_NODE_ENV="test" VITE_EXTERNAL_PORT=${EXTERNAL_PORT} pnpm build && VITE_NODE_ENV="test" VITE_EXTERNAL_PORT=${EXTERNAL_PORT} VITE_SERVER_PORT=${PORT} PORT=${PORT} pnpm start`, | ||
url: baseURL, | ||
reuseExistingServer: !process.env.CI, | ||
stdout: 'pipe', | ||
}, | ||
|
||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
], | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>, | ||
) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
53 changes: 53 additions & 0 deletions
53
e2e/react-start/encoding/src/components/DefaultCatchBoundary.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
/* 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 type { CreateFileRoute, FileRoutesByPath } from '@tanstack/react-router' | ||
import type { | ||
CreateServerFileRoute, | ||
ServerFileRoutesByPath, | ||
} from '@tanstack/react-start/server' | ||
|
||
import { Route as rootRouteImport } from './routes/__root' | ||
import { Route as NoCharsetRouteImport } from './routes/no-charset' | ||
import { Route as CharsetRouteImport } from './routes/charset' | ||
import { Route as IndexRouteImport } from './routes/index' | ||
|
||
const NoCharsetRoute = NoCharsetRouteImport.update({ | ||
id: '/no-charset', | ||
path: '/no-charset', | ||
getParentRoute: () => rootRouteImport, | ||
} as any) | ||
const CharsetRoute = CharsetRouteImport.update({ | ||
id: '/charset', | ||
path: '/charset', | ||
getParentRoute: () => rootRouteImport, | ||
} as any) | ||
const IndexRoute = IndexRouteImport.update({ | ||
id: '/', | ||
path: '/', | ||
getParentRoute: () => rootRouteImport, | ||
} as any) | ||
|
||
export interface FileRoutesByFullPath { | ||
'/': typeof IndexRoute | ||
'/charset': typeof CharsetRoute | ||
'/no-charset': typeof NoCharsetRoute | ||
} | ||
export interface FileRoutesByTo { | ||
'/': typeof IndexRoute | ||
'/charset': typeof CharsetRoute | ||
'/no-charset': typeof NoCharsetRoute | ||
} | ||
export interface FileRoutesById { | ||
__root__: typeof rootRouteImport | ||
'/': typeof IndexRoute | ||
'/charset': typeof CharsetRoute | ||
'/no-charset': typeof NoCharsetRoute | ||
} | ||
export interface FileRouteTypes { | ||
fileRoutesByFullPath: FileRoutesByFullPath | ||
fullPaths: '/' | '/charset' | '/no-charset' | ||
fileRoutesByTo: FileRoutesByTo | ||
to: '/' | '/charset' | '/no-charset' | ||
id: '__root__' | '/' | '/charset' | '/no-charset' | ||
fileRoutesById: FileRoutesById | ||
} | ||
export interface RootRouteChildren { | ||
IndexRoute: typeof IndexRoute | ||
CharsetRoute: typeof CharsetRoute | ||
NoCharsetRoute: typeof NoCharsetRoute | ||
} | ||
|
||
declare module '@tanstack/react-router' { | ||
interface FileRoutesByPath { | ||
'/': { | ||
id: '/' | ||
path: '/' | ||
fullPath: '/' | ||
preLoaderRoute: typeof IndexRouteImport | ||
parentRoute: typeof rootRouteImport | ||
} | ||
'/charset': { | ||
id: '/charset' | ||
path: '/charset' | ||
fullPath: '/charset' | ||
preLoaderRoute: typeof CharsetRouteImport | ||
parentRoute: typeof rootRouteImport | ||
} | ||
'/no-charset': { | ||
id: '/no-charset' | ||
path: '/no-charset' | ||
fullPath: '/no-charset' | ||
preLoaderRoute: typeof NoCharsetRouteImport | ||
parentRoute: typeof rootRouteImport | ||
} | ||
} | ||
} | ||
|
||
declare module './routes/index' { | ||
const createFileRoute: CreateFileRoute< | ||
'/', | ||
FileRoutesByPath['/']['parentRoute'], | ||
FileRoutesByPath['/']['id'], | ||
FileRoutesByPath['/']['path'], | ||
FileRoutesByPath['/']['fullPath'] | ||
> | ||
|
||
const createServerFileRoute: CreateServerFileRoute< | ||
ServerFileRoutesByPath['/']['parentRoute'], | ||
ServerFileRoutesByPath['/']['id'], | ||
ServerFileRoutesByPath['/']['path'], | ||
ServerFileRoutesByPath['/']['fullPath'], | ||
unknown | ||
> | ||
} | ||
declare module './routes/charset' { | ||
const createFileRoute: CreateFileRoute< | ||
'/charset', | ||
FileRoutesByPath['/charset']['parentRoute'], | ||
FileRoutesByPath['/charset']['id'], | ||
FileRoutesByPath['/charset']['path'], | ||
FileRoutesByPath['/charset']['fullPath'] | ||
> | ||
|
||
const createServerFileRoute: CreateServerFileRoute< | ||
ServerFileRoutesByPath['/charset']['parentRoute'], | ||
ServerFileRoutesByPath['/charset']['id'], | ||
ServerFileRoutesByPath['/charset']['path'], | ||
ServerFileRoutesByPath['/charset']['fullPath'], | ||
unknown | ||
> | ||
} | ||
declare module './routes/no-charset' { | ||
const createFileRoute: CreateFileRoute< | ||
'/no-charset', | ||
FileRoutesByPath['/no-charset']['parentRoute'], | ||
FileRoutesByPath['/no-charset']['id'], | ||
FileRoutesByPath['/no-charset']['path'], | ||
FileRoutesByPath['/no-charset']['fullPath'] | ||
> | ||
|
||
const createServerFileRoute: CreateServerFileRoute< | ||
ServerFileRoutesByPath['/no-charset']['parentRoute'], | ||
ServerFileRoutesByPath['/no-charset']['id'], | ||
ServerFileRoutesByPath['/no-charset']['path'], | ||
ServerFileRoutesByPath['/no-charset']['fullPath'], | ||
unknown | ||
> | ||
} | ||
|
||
const rootRouteChildren: RootRouteChildren = { | ||
IndexRoute: IndexRoute, | ||
CharsetRoute: CharsetRoute, | ||
NoCharsetRoute: NoCharsetRoute, | ||
} | ||
export const routeTree = rootRouteImport | ||
._addFileChildren(rootRouteChildren) | ||
._addFileTypes<FileRouteTypes>() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Make test cleanup cross‑platform.
rm -rf
breaks on Windows runners. Userimraf
.Apply:
And add devDependency:
"devDependencies": { + "rimraf": "^6.0.0",
📝 Committable suggestion
🤖 Prompt for AI Agents