{post.title}
-- By {post.authors.join(', ')} on {post.published} -
-{post.title}
++ By {post.authors.join(', ')} on {post.published} +
From 08a419c109ea2739fef0b893e09f4919fbd1b0d8 Mon Sep 17 00:00:00 2001
From: Flo {post.excerpt} {post.description}
- By {post.authors.join(', ')} on {post.published}
-
+ By {post.authors.join(', ')} on {post.published}
+ hmr
- )
- }
- }
- },
- }
-
- return
,
+ }}
+>
+ {content}
+
Blog
{sortedPosts.map((post) => (
- {post.title}
- {post.title}
- {post.title}
+ {frontmatter.title}
- {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.
-| 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 |
+## Table of Contents
-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.
+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.
From da2adec76dbe6c0da6d6a0d5640f7b9388217f45 Mon Sep 17 00:00:00 2001
From: Nicolas Beaussart
child
+ + ) + vi.stubGlobal('window', undefined) + const html = renderToString(app()) + vi.unstubAllGlobals() + const failed: Array<{ tasks: number; errors: Arraypage v1
}) +`, + autoCodeSplitting: false, + }, + ])( + 'an edit of $name is a hot update, not a page reload', + async ({ file, code, autoCodeSplitting }) => { + const app = await startDevApp({ [file]: code }, { autoCodeSplitting }) + try { + expect(app.statuses[`/${file}`]).toBe(200) + expect(await app.edit(file, code.replace('v1', 'v2'))).toBe('update') + } finally { + await app.close() + } + }, + 30_000, + ) + + it('serves a route file with a binding named hot', async () => { + const app = await startDevApp( + { + 'routes/index.tsx': `import { createFileRoute } from '@tanstack/react-router' +const hot = 'hot' +export const Route = createFileRoute('/')({ component: () =>{hot}
}) +`, + }, + // Unsplit, so the binding stays in the module the HMR code goes into + { autoCodeSplitting: false }, + ) + try { + expect(app.statuses['/routes/index.tsx']).toBe(200) + expect(app.served['/routes/index.tsx']).toMatch(/const hot = ["']hot["']/) + } finally { + await app.close() + } + }, 30_000) +}) diff --git a/packages/router-plugin/tests/add-hmr/snapshots/react/arrow-function@true.tsx b/packages/router-plugin/tests/add-hmr/snapshots/react/arrow-function@true.tsx index c771483895..e45f8b634a 100644 --- a/packages/router-plugin/tests/add-hmr/snapshots/react/arrow-function@true.tsx +++ b/packages/router-plugin/tests/add-hmr/snapshots/react/arrow-function@true.tsx @@ -20,9 +20,8 @@ export const Route = createFileRoute('/posts')({ loader: fetchPosts, component: TSRSplitComponent, }) -const hot = import.meta.hot -if (hot && typeof window !== 'undefined') { - hot.data ??= {} +if (import.meta.hot && typeof window !== 'undefined') { + import.meta.hot.data ??= {} const tsrReactRefresh = (window.__TSR_REACT_REFRESH__ ??= (() => { const ignoredExportsById = new Map() const previousGetIgnoredExports = window.__getReactRefreshIgnoredExports @@ -39,8 +38,7 @@ export function TSRFastRefreshAnchor() { return null } if (import.meta.hot) { - const hot = import.meta.hot - const hotData = (hot.data ??= {}) + const hotData = (import.meta.hot.data ??= {}) const handleRouteUpdate = function handleRouteUpdate(routeId, newRoute) { const router = window.__TSR_ROUTER__ const oldRoute = router.routesById[routeId] @@ -101,7 +99,7 @@ if (import.meta.hot) { handleRouteUpdate(initialRouteId, Route) hotData['tsr-route-update-handled'] = Route } - hot.accept((newModule) => { + import.meta.hot.accept((newModule) => { if (Route && newModule && newModule.Route) { const routeId = hotData['tsr-route-id'] ?? Route.id if (routeId) { diff --git a/packages/router-plugin/tests/add-hmr/snapshots/react/createFileRoute-lowercase-components@true.tsx b/packages/router-plugin/tests/add-hmr/snapshots/react/createFileRoute-lowercase-components@true.tsx index bf94d5d3fd..441852d762 100644 --- a/packages/router-plugin/tests/add-hmr/snapshots/react/createFileRoute-lowercase-components@true.tsx +++ b/packages/router-plugin/tests/add-hmr/snapshots/react/createFileRoute-lowercase-components@true.tsx @@ -36,9 +36,8 @@ export const Route = createFileRoute('/lowercase-components')({ function TSRPendingComponent() { return{(Store as any).label}
, +}) +`, + `const component = entry.Route.options.component +return [entry.Store.label, typeof component.preload, await entry.render(component)]`, + { + files: { + 'tsconfig.json': JSON.stringify({ + compilerOptions: { experimentalDecorators: true }, + }), + }, + }, + ) + expect(result).toEqual(['decorated', 'function', 'decorated
']) + }) }) diff --git a/packages/router-utils/src/ast.ts b/packages/router-utils/src/ast.ts index 46e319c2c4..6448adcbad 100644 --- a/packages/router-utils/src/ast.ts +++ b/packages/router-utils/src/ast.ts @@ -39,7 +39,7 @@ function getDefaultParserPluginsForFilename( 'explicitResourceManagement', 'importAttributes', 'deprecatedImportAssert', - ['decorators', { decoratorsBeforeExport: true }], + 'decorators', 'decoratorAutoAccessors', ] From d05c6c66e7efc659286f37a56b3b1d4d267139e7 Mon Sep 17 00:00:00 2001 From: Flo{error instanceof Error ? error.message : String(error)}
+ ), +}) + +function Result() { + return{Route.useLoaderData()}
+} diff --git a/e2e/react-start/basic/src/routes/execution-rpc.tsx b/e2e/react-start/basic/src/routes/execution-rpc.tsx new file mode 100644 index 0000000000..f934015522 --- /dev/null +++ b/e2e/react-start/basic/src/routes/execution-rpc.tsx @@ -0,0 +1,18 @@ +import { createFileRoute, Link } from '@tanstack/react-router' +import { readThroughRpc } from '~/utils/execution-functions' + +export const Route = createFileRoute('/execution-rpc')({ + loader: () => readThroughRpc(), + component: Result, +}) + +function Result() { + return ( + <> +{Route.useLoaderData()}
+ + Call the server-only helper directly + + > + ) +} diff --git a/e2e/react-start/basic/src/utils/execution-functions.ts b/e2e/react-start/basic/src/utils/execution-functions.ts new file mode 100644 index 0000000000..97e66573d8 --- /dev/null +++ b/e2e/react-start/basic/src/utils/execution-functions.ts @@ -0,0 +1,5 @@ +import { createServerFn, createServerOnlyFn } from '@tanstack/react-start' + +export const readOnlyOnServer = createServerOnlyFn(() => 'Read on the server') + +export const readThroughRpc = createServerFn().handler(() => readOnlyOnServer()) diff --git a/e2e/react-start/basic/tests/client-only.spec.ts b/e2e/react-start/basic/tests/client-only.spec.ts index a3b6f99442..299744f636 100644 --- a/e2e/react-start/basic/tests/client-only.spec.ts +++ b/e2e/react-start/basic/tests/client-only.spec.ts @@ -1,5 +1,6 @@ import { expect } from '@playwright/test' import { test } from '@tanstack/router-e2e-utils' +import { isSpaMode } from './utils/isSpaMode' /** * These tests verify the