{post.title}
-- By {post.authors.join(', ')} on {post.published} -
+{post.title}
++ By {post.authors.join(', ')} on {post.published} +
+diff --git a/.changeset/intent-skill-cross-package-links.md b/.changeset/intent-skill-cross-package-links.md
new file mode 100644
index 0000000000..9d655e9e75
--- /dev/null
+++ b/.changeset/intent-skill-cross-package-links.md
@@ -0,0 +1,14 @@
+---
+'@tanstack/react-router': patch
+'@tanstack/react-start': patch
+'@tanstack/router-core': patch
+'@tanstack/router-plugin': patch
+'@tanstack/solid-router': patch
+'@tanstack/solid-start': patch
+'@tanstack/start-client-core': patch
+'@tanstack/start-server-core': patch
+'@tanstack/vue-router': patch
+'@tanstack/vue-start': patch
+---
+
+Reference agent skills in other packages by their `intent load` identifier (`@tanstack/ {post.excerpt} {post.description}
- By {post.authors.join(', ')} on {post.published}
-
+ By {post.authors.join(', ')} on {post.published}
+ {error instanceof Error ? error.message : String(error)} {Route.useLoaderData()} {Route.useLoaderData()} page
+ )
+ }
+ }
+ },
+ }
+
+ return
,
- }}
->
- {content}
-
Blog
{sortedPosts.map((post) => (
-
+ {post.title}
+ {post.title}
- {post.title}
+ {title}
- {frontmatter.title}
+ ` elements. Unknown languages fall back to plain text. Add a `dark` class to an ancestor to select the dark theme. See the [syntax highlighting guide](https://tanstack.com/markdown/latest/docs/guides/syntax-highlighting) for line numbers and highlighted lines.
+## Summary
-## Table of Contents
+| Approach | Best For | Pros | Cons |
+| ------------------- | ----------------------------------------- | ---------------------------------------------- | ----------------------------------------- |
+| content-collections | Blog posts, static docs bundled with app | Type-safe, build-time processing, fast runtime | Requires rebuild for content updates |
+| Dynamic fetching | External docs, frequently updated content | Always fresh, no rebuild needed | Runtime overhead, requires error handling |
-To collect headings, add the docs preset when parsing the document:
-
-```ts
-import { docsMarkdownExtensions } from '@tanstack/markdown/extensions/docs'
-import { parseMarkdown } from '@tanstack/markdown/parser'
-
-const document = parseMarkdown(content, {
- extensions: docsMarkdownExtensions(),
-})
-
-const headings = document.headings ?? []
-// Each heading has an id, text, and level.
-```
-
-Use this in the server function, then render links to each heading's `id`. The [docs preset guide](https://tanstack.com/markdown/latest/docs/guides/docs-preset) also covers callouts and custom comment components. Those features need the same extensions passed to the renderer.
+Choose the approach that best fits your content update frequency and deployment workflow. For hybrid scenarios, you can use both methods in the same application.
diff --git a/docs/start/framework/react/guide/server-functions.md b/docs/start/framework/react/guide/server-functions.md
index 879aa9e867..68a6b8ac72 100644
--- a/docs/start/framework/react/guide/server-functions.md
+++ b/docs/start/framework/react/guide/server-functions.md
@@ -425,9 +425,7 @@ Customization:
You can customize function ID generation for the production build by providing a `generateFunctionId` function when configuring the TanStack Start build tool plugin.
-Return `undefined` (or an empty string) to use the default ID. Prefer deterministic inputs (filename + functionName) so IDs remain stable between builds.
-
-The ID becomes one segment of the server function's URL (`/_serverFn/
child
- - ) - vi.stubGlobal('window', undefined) - const html = renderToString(app()) - vi.unstubAllGlobals() - const failed: Array<{ tasks: number; errors: Array{JSON.stringify(value)}}ERROR {error}
+} + +class Boundary extends Component<{ children: React.ReactNode }, { error?: string }> { + state: { error?: string } = {} + static getDerivedStateFromError(error: unknown) { + return { error: String(error) } + } + render() { + return this.state.error ?MARK_PLAIN
) +} +`, + 'src/render.ts': `export { renderServerComponent as renderThing } from '@tanstack/react-start/rsc'\n`, + 'src/wrap.tsx': `import { renderServerComponent } from '@tanstack/react-start/rsc' +export const wrap = (node: React.ReactNode) => renderServerComponent(node) +`, + 'node_modules/other-rsc/package.json': JSON.stringify({ + name: 'other-rsc', + type: 'module', + exports: './index.js', + }), + 'node_modules/other-rsc/index.js': `export const renderServerComponent = (...args) => ({ arity: args.length, label: args[0].props['data-label'], children: args[0].props.children, scalars: args.slice(1, 3), effects: [...args[0].props['data-effects']] })\n`, + }, + // The app's own package (a look-alike row), pre-bundled like the rest. + config: { optimizeDeps: { include: ['other-rsc'] } }, + }) + + test('two render helpers in one module each carry their component CSS', async ({ + onTestFinished, + }) => { + // Separate browser contexts/results: renderA's stylesheet must not mask + // renderB missing its own delivery, even though both helpers share CSS. + for (const [name, marker, selector, expected] of [ + ['a', 'MARK_A', '[data-testid=card]', CARD_BACKGROUND], + ['b', 'MARK_B', '[data-testid=badge]', BADGE_BACKGROUND], + ] as const) { + const page = await openRscPage(app.server(), `/pair-${name}`, { + registerCleanup: onTestFinished, + }) + await page.waitForText(marker, { selector: 'main' }) + await waitForHydration(page) + expect( + await settledValue( + page, + () => computedStyle(page, selector, 'background-color'), + (value) => value === expected, + ), + ).toBe(expected) + expect(page.errors).toEqual([]) + } + }) + + test('a JavaScript provider carries its stylesheet with the RSC payload', async () => { + expect(await app.text(rows.javascript)).toBe('MARK_CARD') + expect( + await app.style( + rows.javascript, + '[data-testid=card]', + 'background-color', + CARD_BACKGROUND, + ), + ).toBe(CARD_BACKGROUND) + }) + + const cardBackground = (row: Row) => + app.style(row, '[data-testid=card]', 'background-color', CARD_BACKGROUND) + + // A JSX fragment root must get the CSS of every child, + // like an element root. + test.each([ + { name: 'renderServerComponent', row: rows.fragmentRenderable }, + { name: 'createCompositeComponent', row: rows.fragmentComposite }, + { name: 'renderToReadableStream', row: rows.fragmentFlight }, + ])('$name with a fragment root styles every child', async ({ row }) => { + expect({ + card: await cardBackground(row), + badge: await app.style( + row, + '[data-testid=badge]', + 'background-color', + BADGE_BACKGROUND, + ), + }).toEqual({ card: CARD_BACKGROUND, badge: BADGE_BACKGROUND }) + }) + + test('a render call in a helper module, with a global stylesheet, styles the server component', async () => { + expect( + await app.style( + rows.globalCss, + '[data-testid=plain]', + 'color', + GLOBAL_COLOR, + ), + ).toBe(GLOBAL_COLOR) + }) + + test.each([ + { wrapped: '(ssr {data.own} provider {data.provider}
+called {called}
+browser {browser}
+ + +loaded {Route.useLoaderData()}
+called {called}
+ +ssr {data.own} provider {data.provider}
+called {called}
+browser {browser}
+ + +${text} {label}
+called {called}
+ + +MARK_LABEL_${version} {label}
+called {called}
+ +ssr {data.own} provider {data.provider}
+called {called}
+browser {browser}
+ + +Bar from its lazy file
', + '}', + '', + ].join('\n'), + 'double-quotes.tsx': template.replace( + "createFileRoute('/foo/bar')", + 'createFileRoute("/foo/bar")', + ), + // (a template literal id may be replaced or reported, SPEC J1.1: + // route-file-upkeep.test.ts) + 'duplicate-import.tsx': [ + "import { createFileRoute } from '@tanstack/react-router'", + "import * as React from 'react'", + "import { Link, Outlet } from '@tanstack/react-router'", + '', + "export const Route = createFileRoute('/foo/bar')({", + ' component: PostsLayoutComponent,', + '})', + '', + 'function PostsLayoutComponent() {', + ' return (', + ' <>', + ' Home', + 'Post not found
- }, - component: PostComponent, -}) - -export function PostErrorComponent({ error }: ErrorComponentProps) { - returnPost not found
- }, - component: PostComponent, -}) - -export function PostErrorComponent({ error }: ErrorComponentProps) { - returnPost not found
- }, - component: PostComponent, -}) - -export function PostErrorComponent({ error }: ErrorComponentProps) { - returnPost not found
- }, - component: PostComponent, -}) - -export function PostErrorComponent({ error }: ErrorComponentProps) { - returnPost not found
- }, - component: PostComponent, -}) - -export function PostErrorComponent({ error }: ErrorComponentProps) { - returnnative async page
', + }, + expected: { __root__: ['/', null], '/': ['/', '__root__'] }, + visits: { '/': '/' }, + pages: { '/': ['native async page'] }, +} + +test.each([...frameworkCases, ...shapeCases, groupLayout, nativeAsyncVue])( + 'the browser renders $name', + (testCase) => checkApp(testCase, { types: false, client: true }), +) diff --git a/packages/router-generator/tests/integration/route-types.test.ts b/packages/router-generator/tests/integration/route-types.test.ts new file mode 100644 index 0000000000..87ab762aa0 --- /dev/null +++ b/packages/router-generator/tests/integration/route-types.test.ts @@ -0,0 +1,126 @@ +/** + * The types of generated route trees (SPEC J1.13), checked by the real + * TypeScript compiler with the real router types: the trees of the apps of + * real-router-cases.ts type the routes the real router builds from them + * (real-router.test.ts, real-router-frameworks.test.ts) alike, and `to` and + * full paths stand for the right routes. Slow tier: one TypeScript program + * per app (each tree augments the router's types globally). + */ +import { describe, expect, test } from 'vitest' +import { + createApp, + fileRoute, + generate, + lazyFileRoute, + rootRoute, +} from '../app' +import { checkApp } from '../real-router' +import { frameworkCases, groupLayout, shapeCases } from '../real-router-cases' +import { typeAssertions, typeErrorsOf } from '../type-check' + +/** An app with a root route and a route file for each of `files`. */ +async function appWithRoutes(files: Array${text}
+text
` and, with `outlet`, its child routes; `constructor` is + * `createRootRoute`, `createFileRoute` or `createLazyFileRoute` (whose id + * the generator fixes). + */ +export const page = ( + target: 'react' | 'solid', + constructor: string, + text: string, + outlet = false, +) => `${target === 'solid' ? '/** @jsxImportSource solid-js */\n' : ''}import { Outlet, ${constructor} } from '@tanstack/${target}-router' + +export const Route = ${constructor === 'createRootRoute' ? constructor : `${constructor}('/wrong')`}({ + component: () => ( + <> +${text}
+ ${outlet ? '` elements of server-rendered `html`, in order. */ +const paragraphs = (html: string) => + [...html.matchAll(/
]*>([^<]*)<\/p>/g)].map((match) => match[1])
+
+/**
+ * Generates the app of a case and checks the router over its route tree
+ * (`runtime`) and the tree's types (`types`) against the expected routes.
+ */
+export async function checkApp(
+ { files, config, expected, visits, pages }: Case,
+ { runtime = true, types = true, client = false } = {},
+) {
+ const root = await createApp({ ...files, 'src/vue-shim.d.ts': vueShim })
+ const { generatedRouteTree } = await generate(root, config)
+
+ if (runtime) {
+ await checkRouter(generatedRouteTree, { expected, visits, pages }, client)
+ }
+ if (types) {
+ await checkTypes(root, expected)
+ }
+}
+
+/** Checks the router over the route tree at `treeFile`. */
+async function checkRouter(
+ treeFile: string,
+ { expected, visits, pages }: Pick