-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: wait for async loaders before executing head functions #6222
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
yanghuidong
wants to merge
29
commits into
TanStack:main
Choose a base branch
from
yanghuidong:fix/head-premature-execution
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
29 commits
Select commit
Hold shift + click to select a range
eb0dfa6
fix: wait for async loaders before executing head functions
yanghuidong 39f9df9
fix: re-execute head() after async loaders complete (non-blocking)
yanghuidong db2089c
refactor: extract executeAllHeadFns to eliminate duplication
yanghuidong 1086e22
fix: ensure head() executes even when async loaders fail
yanghuidong e365b3d
fix: prevent race condition when navigation changes during head() re-…
yanghuidong f5c1251
test(solid-query): add e2e example for head() async loader bug
yanghuidong a8c1210
test(solid-query): add e2e tests for head() async loader fix
yanghuidong 88e2203
fix: add null check for match in async loader finally block
yanghuidong a1c1802
revert: move promise resolution back to try block
yanghuidong b4eda4f
fix: add null checks in both async and sync loader paths
yanghuidong 0cd8ff6
fix: revert unnecessary null check that broke TypeScript
yanghuidong 8874f7d
fix: capture match reference before redirect navigation removes it
yanghuidong b517fb8
add Minimal e2e example to demo the head function's set title bug
yanghuidong 98f1319
re-enable head function re-run, confirming that the dynamic title bug…
yanghuidong 3d51361
fix: prevent stale head() re-runs from polluting state
yanghuidong 9ed4a52
test: add e2e/solid-start/basic-head to validate generation counter fix
yanghuidong 8247071
ci: apply automated fixes
autofix-ci[bot] ddea67c
fix: use button instead of Link for 'Go Back' in DefaultCatchBoundary
yanghuidong 67eebb8
fix: e2e test 'stale head re-run aborts when route invalidation happe…
yanghuidong d5581a4
test: add console log verification to invalidation abort test
yanghuidong 34a337f
test: add console log verification to navigation abort test
yanghuidong 43bfdc4
refactor: remove test-head routes and fake-auth utils from basic exam…
yanghuidong a9e1224
refactor: delete obsolete e2e test on head func from basic-solid-query
yanghuidong dd5437c
fix: resolve ESLint errors in router.ts
yanghuidong 94cc154
use latestHeadRerunPromise pattern for stale head re-run detection
schiller-manuel 97b78dc
test: update store update count after head re-run refactoring
yanghuidong 271abe0
Merge maintainer's simpler implementation using promise reference
schiller-manuel 3272beb
fix: restore async for startViewTransition callback to satisfy TypeSc…
yanghuidong 42e730e
test: add extra wait to fix race condition in Link navigation test
yanghuidong 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 @@ | ||
| /test-results/ |
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,43 @@ | ||
| { | ||
| "name": "tanstack-solid-start-e2e-basic-head", | ||
| "private": true, | ||
| "sideEffects": false, | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "vite dev --port 3000", | ||
| "dev:e2e": "vite dev", | ||
| "build": "vite build && tsc --noEmit", | ||
| "build:spa": "MODE=spa vite build && tsc --noEmit", | ||
| "build:prerender": "MODE=prerender vite build && tsc --noEmit", | ||
| "preview": "vite preview", | ||
| "start": "pnpm exec srvx --prod -s ../client dist/server/server.js", | ||
| "start:spa": "node server.js", | ||
| "test:e2e:startDummyServer": "node -e 'import(\"./tests/setup/global.setup.ts\").then(m => m.default())' &", | ||
| "test:e2e:stopDummyServer": "node -e 'import(\"./tests/setup/global.teardown.ts\").then(m => m.default())'", | ||
| "test:e2e:spaMode": "rm -rf port*.txt; MODE=spa playwright test --project=chromium", | ||
| "test:e2e:ssrMode": "rm -rf port*.txt; playwright test --project=chromium", | ||
| "test:e2e:prerender": "rm -rf port*.txt; MODE=prerender playwright test --project=chromium", | ||
| "test:e2e:preview": "rm -rf port*.txt; MODE=preview playwright test --project=chromium", | ||
| "test:e2e": "pnpm run test:e2e:spaMode && pnpm run test:e2e:ssrMode && pnpm run test:e2e:prerender && pnpm run test:e2e:preview" | ||
| }, | ||
| "dependencies": { | ||
| "@tanstack/solid-router": "workspace:^", | ||
| "@tanstack/solid-router-devtools": "workspace:^", | ||
| "@tanstack/solid-start": "workspace:^", | ||
| "express": "^5.1.0", | ||
| "http-proxy-middleware": "^3.0.5", | ||
| "solid-js": "^1.9.10", | ||
| "vite": "^7.1.7" | ||
| }, | ||
| "devDependencies": { | ||
| "@playwright/test": "^1.50.1", | ||
| "@tailwindcss/vite": "^4.1.18", | ||
| "@tanstack/router-e2e-utils": "workspace:^", | ||
| "@types/node": "^22.10.2", | ||
| "srvx": "^0.9.8", | ||
| "tailwindcss": "^4.1.18", | ||
| "typescript": "^5.7.2", | ||
| "vite-plugin-solid": "^2.11.10", | ||
| "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,72 @@ | ||
| import { defineConfig, devices } from '@playwright/test' | ||
| import { | ||
| getDummyServerPort, | ||
| getTestServerPort, | ||
| } from '@tanstack/router-e2e-utils' | ||
| import { isSpaMode } from './tests/utils/isSpaMode' | ||
| import { isPrerender } from './tests/utils/isPrerender' | ||
| import { isPreview } from './tests/utils/isPreview' | ||
| import packageJson from './package.json' with { type: 'json' } | ||
|
|
||
| const PORT = await getTestServerPort( | ||
| `${packageJson.name}${isSpaMode ? '_spa' : ''}${isPreview ? '_preview' : ''}`, | ||
| ) | ||
| const START_PORT = await getTestServerPort( | ||
| `${packageJson.name}${isSpaMode ? '_spa_start' : ''}`, | ||
| ) | ||
| const EXTERNAL_PORT = await getDummyServerPort(packageJson.name) | ||
| const baseURL = `http://localhost:${PORT}` | ||
| const spaModeCommand = `pnpm build:spa && pnpm start:spa` | ||
| const ssrModeCommand = `pnpm build && pnpm start` | ||
| const prerenderModeCommand = `pnpm run test:e2e:startDummyServer && pnpm build:prerender && pnpm run test:e2e:stopDummyServer && pnpm start` | ||
| const previewModeCommand = `pnpm build && pnpm preview --port ${PORT}` | ||
|
|
||
| const getCommand = () => { | ||
| if (isSpaMode) return spaModeCommand | ||
| if (isPrerender) return prerenderModeCommand | ||
| if (isPreview) return previewModeCommand | ||
| return ssrModeCommand | ||
| } | ||
| console.log('running in spa mode: ', isSpaMode.toString()) | ||
| console.log('running in prerender mode: ', isPrerender.toString()) | ||
| console.log('running in preview mode: ', isPreview.toString()) | ||
| /** | ||
| * 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: getCommand(), | ||
| url: baseURL, | ||
| reuseExistingServer: !process.env.CI, | ||
| stdout: 'pipe', | ||
| env: { | ||
| MODE: process.env.MODE || '', | ||
| VITE_NODE_ENV: 'test', | ||
| VITE_EXTERNAL_PORT: String(EXTERNAL_PORT), | ||
| VITE_SERVER_PORT: String(PORT), | ||
| START_PORT: String(START_PORT), | ||
| PORT: String(PORT), | ||
| }, | ||
| }, | ||
|
|
||
| projects: [ | ||
| { | ||
| name: 'chromium', | ||
| use: { | ||
| ...devices['Desktop Chrome'], | ||
| }, | ||
| }, | ||
| ], | ||
| }) |
Binary file not shown.
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,67 @@ | ||
| import { toNodeHandler } from 'srvx/node' | ||
| import path from 'node:path' | ||
| import express from 'express' | ||
| import { createProxyMiddleware } from 'http-proxy-middleware' | ||
|
|
||
| const port = process.env.PORT || 3000 | ||
|
|
||
| const startPort = process.env.START_PORT || 3001 | ||
|
|
||
| export async function createStartServer() { | ||
| const server = (await import('./dist/server/server.js')).default | ||
| const nodeHandler = toNodeHandler(server.fetch) | ||
|
|
||
| const app = express() | ||
|
|
||
| app.use(express.static('./dist/client')) | ||
|
|
||
| app.use(async (req, res, next) => { | ||
| try { | ||
| await nodeHandler(req, res) | ||
| } catch (error) { | ||
| next(error) | ||
| } | ||
| }) | ||
|
|
||
| return { app } | ||
| } | ||
|
|
||
| export async function createSpaServer() { | ||
| const app = express() | ||
|
|
||
| app.use( | ||
| '/api', | ||
| createProxyMiddleware({ | ||
| target: `http://localhost:${startPort}/api`, // Replace with your target server's URL | ||
| changeOrigin: false, // Needed for virtual hosted sites, | ||
| }), | ||
| ) | ||
|
|
||
| app.use( | ||
| '/_serverFn', | ||
| createProxyMiddleware({ | ||
| target: `http://localhost:${startPort}/_serverFn`, // Replace with your target server's URL | ||
| changeOrigin: false, // Needed for virtual hosted sites, | ||
| }), | ||
| ) | ||
|
|
||
| app.use(express.static('./dist/client')) | ||
|
|
||
| app.get('/{*splat}', (req, res) => { | ||
| res.sendFile(path.resolve('./dist/client/index.html')) | ||
| }) | ||
|
|
||
| return { app } | ||
| } | ||
|
|
||
| createSpaServer().then(async ({ app }) => | ||
| app.listen(port, () => { | ||
| console.info(`Client Server: http://localhost:${port}`) | ||
| }), | ||
| ) | ||
|
|
||
| createStartServer().then(async ({ app }) => | ||
| app.listen(startPort, () => { | ||
| console.info(`Start Server: http://localhost:${startPort}`) | ||
| }), | ||
| ) |
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 @@ | ||
| // DO NOT DELETE THIS FILE!!! | ||
| // This file is a good smoke test to make sure the custom client entry is working | ||
| import { hydrate } from 'solid-js/web' | ||
| import { StartClient, hydrateStart } from '@tanstack/solid-start/client' | ||
|
|
||
| console.log("[client-entry]: using custom client entry in 'src/client.tsx'") | ||
|
|
||
| hydrateStart().then((router) => { | ||
| hydrate(() => <StartClient router={router} />, document) | ||
| }) |
51 changes: 51 additions & 0 deletions
51
e2e/solid-start/basic-head/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,51 @@ | ||
| import { | ||
| ErrorComponent, | ||
| Link, | ||
| rootRouteId, | ||
| useMatch, | ||
| useRouter, | ||
| } from '@tanstack/solid-router' | ||
| import type { ErrorComponentProps } from '@tanstack/solid-router' | ||
|
|
||
| export function DefaultCatchBoundary({ error }: ErrorComponentProps) { | ||
| const router = useRouter() | ||
| const isRoot = useMatch({ | ||
| strict: false, | ||
| select: (state) => state.id === rootRouteId, | ||
| }) | ||
|
|
||
| console.error(error) | ||
|
|
||
| return ( | ||
| <div class="min-w-0 flex-1 p-4 flex flex-col items-center justify-center gap-6"> | ||
| <ErrorComponent error={error} /> | ||
| <div class="flex gap-2 items-center flex-wrap"> | ||
| <button | ||
| type="button" | ||
| onClick={() => { | ||
| router.invalidate() | ||
| }} | ||
| class={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded-sm text-white uppercase font-extrabold`} | ||
| > | ||
| Try Again | ||
| </button> | ||
| {isRoot() ? ( | ||
| <Link | ||
| to="/" | ||
| class={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded-sm text-white uppercase font-extrabold`} | ||
| > | ||
| Home | ||
| </Link> | ||
| ) : ( | ||
| <button | ||
| type="button" | ||
| onClick={() => window.history.back()} | ||
| class={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded-sm text-white uppercase font-extrabold`} | ||
| > | ||
| Go Back | ||
| </button> | ||
| )} | ||
| </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/solid-router' | ||
|
|
||
| export function NotFound({ children }: { children?: any }) { | ||
| return ( | ||
| <div class="space-y-2 p-2" data-testid="default-not-found-component"> | ||
| <div class="text-gray-600 dark:text-gray-400"> | ||
| {children || <p>The page you are looking for does not exist.</p>} | ||
| </div> | ||
| <p class="flex items-center gap-2 flex-wrap"> | ||
| <button | ||
| onClick={() => window.history.back()} | ||
| class="bg-emerald-500 text-white px-2 py-1 rounded-sm uppercase font-black text-sm" | ||
| > | ||
| Go back | ||
| </button> | ||
| <Link | ||
| to="/" | ||
| class="bg-cyan-600 text-white px-2 py-1 rounded-sm 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,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 IndexRouteImport } from './routes/index' | ||
| import { Route as ArticleIdRouteImport } from './routes/article.$id' | ||
|
|
||
| const IndexRoute = IndexRouteImport.update({ | ||
| id: '/', | ||
| path: '/', | ||
| getParentRoute: () => rootRouteImport, | ||
| } as any) | ||
| const ArticleIdRoute = ArticleIdRouteImport.update({ | ||
| id: '/article/$id', | ||
| path: '/article/$id', | ||
| getParentRoute: () => rootRouteImport, | ||
| } as any) | ||
|
|
||
| export interface FileRoutesByFullPath { | ||
| '/': typeof IndexRoute | ||
| '/article/$id': typeof ArticleIdRoute | ||
| } | ||
| export interface FileRoutesByTo { | ||
| '/': typeof IndexRoute | ||
| '/article/$id': typeof ArticleIdRoute | ||
| } | ||
| export interface FileRoutesById { | ||
| __root__: typeof rootRouteImport | ||
| '/': typeof IndexRoute | ||
| '/article/$id': typeof ArticleIdRoute | ||
| } | ||
| export interface FileRouteTypes { | ||
| fileRoutesByFullPath: FileRoutesByFullPath | ||
| fullPaths: '/' | '/article/$id' | ||
| fileRoutesByTo: FileRoutesByTo | ||
| to: '/' | '/article/$id' | ||
| id: '__root__' | '/' | '/article/$id' | ||
| fileRoutesById: FileRoutesById | ||
| } | ||
| export interface RootRouteChildren { | ||
| IndexRoute: typeof IndexRoute | ||
| ArticleIdRoute: typeof ArticleIdRoute | ||
| } | ||
|
|
||
| declare module '@tanstack/solid-router' { | ||
| interface FileRoutesByPath { | ||
| '/': { | ||
| id: '/' | ||
| path: '/' | ||
| fullPath: '/' | ||
| preLoaderRoute: typeof IndexRouteImport | ||
| parentRoute: typeof rootRouteImport | ||
| } | ||
| '/article/$id': { | ||
| id: '/article/$id' | ||
| path: '/article/$id' | ||
| fullPath: '/article/$id' | ||
| preLoaderRoute: typeof ArticleIdRouteImport | ||
| parentRoute: typeof rootRouteImport | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const rootRouteChildren: RootRouteChildren = { | ||
| IndexRoute: IndexRoute, | ||
| ArticleIdRoute: ArticleIdRoute, | ||
| } | ||
| export const routeTree = rootRouteImport | ||
| ._addFileChildren(rootRouteChildren) | ||
| ._addFileTypes<FileRouteTypes>() | ||
|
|
||
| import type { getRouter } from './router.tsx' | ||
| import type { createStart } from '@tanstack/solid-start' | ||
| declare module '@tanstack/solid-start' { | ||
| interface Register { | ||
| ssr: true | ||
| router: Awaited<ReturnType<typeof getRouter>> | ||
| } | ||
| } |
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,16 @@ | ||
| import { createRouter } from '@tanstack/solid-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 | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.