Skip to content
Source
Sign inSign up
TanStack/router

perf(router-plugin): write dev snippets as typed templates compiled into AST builders at build time #8684

OpenSheraff(GitHub profile, opens in a new tab)wants to merge 7 commits intoperf/direct-builders-pr fromproto/hmr-typed-templatesopened

Showing 29 changed files with 97 additions and 41 deletions (loading 26).

x
0 of 29 viewed, 29 left
5 additions and 0 deletions.changeset/router-plugin-typed-templates.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/router-plugin': patch
+---
+​
+Build the route HMR and React Refresh code the plugin inserts during development directly instead of parsing it, for faster dev transforms. The inserted code is also smaller: it no longer carries comments, redundant parentheses or a few intermediate variables and wrappers, and behaves the same.
52 additions and 25 deletionspackages/router-plugin/src/core/code-splitter/plugins/react-refresh-ignored-route-exports.tsModified
View file
@@ -1,7 +1,54 @@
-import { parseStatements } from '@tanstack/router-utils'
import { getUniqueProgramIdentifier } from '../../utils'
+import { astTemplate, hole, importMeta } from '../../ast-template'
import type { ReferenceRouteCompilerPlugin } from '../plugins'
​
+type GetIgnoredExports = (ctx: { id: string }) => Array<string>
+​
+/** `window` in a route module running in Vite with React Refresh */
+declare const window: {
+ // Asked by @vitejs/plugin-react for the exports a module may update without
+ // being a React Refresh boundary
+ __getReactRefreshIgnoredExports?: GetIgnoredExports
+ __TSR_REACT_REFRESH__?: {
+ ignoredExportsById: Map<string, Array<string>>
+ }
+}
+​