@tanstack/router-plugin 1.167.24 → 1.167.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,27 +13,26 @@ _babel_template = require_runtime.__toESM(_babel_template);
13
13
  * `routeId` out of `hot.data`. `hot.dispose` stashes it for the next run, and
14
14
  * `hot.accept()` (no callback) enrolls us as a self-accepting boundary.
15
15
  *
16
- * Returns an array of statements so that for React we can prepend an
17
- * `import { performReactRefresh } from 'react-refresh/runtime'` hoisted to the
18
- * top of the module.
16
+ * Returns an array of statements that patches route definitions during HMR.
19
17
  */
20
18
  function createWebpackHmrStatement(stableRouteOptionKeys, opts) {
21
19
  const handleRouteUpdateCode = require_handle_route_update.getHandleRouteUpdateCode(stableRouteOptionKeys);
22
20
  const staticRouteIdLiteral = typeof opts.routeId === "string" ? JSON.stringify(opts.routeId) : "undefined";
23
- const statements = [];
24
21
  const reactRefreshCall = opts.targetFramework === "react" ? `
25
- const tsrRefreshState = globalThis.__TSR_HMR__ ??= {}
26
22
  try {
27
- if (!tsrRefreshState.refreshScheduled) {
28
- tsrRefreshState.refreshScheduled = true
29
- setTimeout(() => {
30
- tsrRefreshState.refreshScheduled = false
31
- try { __tsr_performReactRefresh() } catch (_e) { /* noop */ }
32
- }, 30)
23
+ const tsrReactRefreshUtils =
24
+ typeof __react_refresh_utils__ !== 'undefined'
25
+ ? __react_refresh_utils__
26
+ : undefined
27
+ const tsrEnqueueUpdate =
28
+ tsrReactRefreshUtils && typeof tsrReactRefreshUtils.enqueueUpdate === 'function'
29
+ ? tsrReactRefreshUtils.enqueueUpdate
30
+ : undefined
31
+ if (tsrEnqueueUpdate) {
32
+ tsrEnqueueUpdate(() => {})
33
33
  }
34
34
  } catch (_err) { /* noop */ }` : "";
35
- if (opts.targetFramework === "react") statements.push(_babel_template.statement(`import { performReactRefresh as __tsr_performReactRefresh } from 'react-refresh/runtime'`)());
36
- statements.push(_babel_template.statement(`
35
+ return [_babel_template.statement(`
37
36
  if (import.meta.webpackHot) {
38
37
  const hot = import.meta.webpackHot
39
38
  const hotData = hot.data ??= {}
@@ -55,8 +54,7 @@ if (import.meta.webpackHot) {
55
54
  })
56
55
  hot.accept()
57
56
  }
58
- `, { syntacticPlaceholders: true })());
59
- return statements;
57
+ `, { syntacticPlaceholders: true })()];
60
58
  }
61
59
  //#endregion
62
60
  exports.createWebpackHmrStatement = createWebpackHmrStatement;
@@ -1 +1 @@
1
- {"version":3,"file":"webpack-adapter.cjs","names":[],"sources":["../../../../src/core/hmr/webpack-adapter.ts"],"sourcesContent":["import * as template from '@babel/template'\nimport { getHandleRouteUpdateCode } from './handle-route-update'\nimport type { Config } from '../config'\nimport type * as t from '@babel/types'\n\n/**\n * Emits HMR accept code for bundlers with webpack-compatible `module.hot`\n * semantics (classic webpack via `import.meta.webpackHot`, and Rspack).\n *\n * Unlike Vite's `hot.accept((newModule) => {...})` — where the callback receives\n * the freshly re-imported module — webpack re-executes the module factory on\n * accept, so our HMR logic must live at module top level and read the previous\n * `routeId` out of `hot.data`. `hot.dispose` stashes it for the next run, and\n * `hot.accept()` (no callback) enrolls us as a self-accepting boundary.\n *\n * Returns an array of statements so that for React we can prepend an\n * `import { performReactRefresh } from 'react-refresh/runtime'` hoisted to the\n * top of the module.\n */\nexport function createWebpackHmrStatement(\n stableRouteOptionKeys: Array<string>,\n opts: {\n targetFramework: Config['target']\n routeId?: string\n },\n): Array<t.Statement> {\n const handleRouteUpdateCode = getHandleRouteUpdateCode(stableRouteOptionKeys)\n const staticRouteIdLiteral =\n typeof opts.routeId === 'string'\n ? JSON.stringify(opts.routeId)\n : 'undefined'\n\n const statements: Array<t.Statement> = []\n\n // React-only: route modules aren't React Refresh \"boundaries\" (they export\n // a non-component `Route`), so the bundler's react-refresh runtime won't\n // call `performReactRefresh` for us. We kick it manually after swapping\n // route options so newly-registered component bodies get patched into live\n // fibers.\n //\n // We import `performReactRefresh` directly from `react-refresh/runtime` —\n // the canonical public API — rather than relying on the ProvidePlugin-\n // injected `__react_refresh_utils__` global, whose name is an internal\n // detail of `@rspack/plugin-react-refresh`. The rspack plugin aliases\n // `react-refresh` its bundled runtime (getRefreshRuntimeDirPath), so this\n // resolves to the same singleton the plugin itself uses and shares the\n // registry React was patched against.\n //\n // Use the same delayed refresh style as Rspack's React Refresh runtime.\n // Route modules and their split component chunks can arrive in separate HMR\n // steps under CI load; a microtask can run before the split chunk registers\n // its new component family, causing the refresh to no-op or remount.\n //\n // For non-React frameworks we skip this entirely.\n const reactRefreshCall =\n opts.targetFramework === 'react'\n ? `\n const tsrRefreshState = globalThis.__TSR_HMR__ ??= {}\n try {\n if (!tsrRefreshState.refreshScheduled) {\n tsrRefreshState.refreshScheduled = true\n setTimeout(() => {\n tsrRefreshState.refreshScheduled = false\n try { __tsr_performReactRefresh() } catch (_e) { /* noop */ }\n }, 30)\n }\n } catch (_err) { /* noop */ }`\n : ''\n\n if (opts.targetFramework === 'react') {\n statements.push(\n template.statement(\n `import { performReactRefresh as __tsr_performReactRefresh } from 'react-refresh/runtime'`,\n )(),\n )\n }\n\n statements.push(\n template.statement(\n `\nif (import.meta.webpackHot) {\n const hot = import.meta.webpackHot\n const hotData = hot.data ??= {}\n const routeId = hotData['tsr-route-id'] ?? Route.id ?? (Route.isRoot ? '__root__' : ${staticRouteIdLiteral})\n if (routeId) {\n hotData['tsr-route-id'] = routeId\n }\n const existingRoute =\n typeof window !== 'undefined' && routeId\n ? window.__TSR_ROUTER__?.routesById?.[routeId]\n : undefined\n if (routeId && existingRoute && existingRoute !== Route) {\n (${handleRouteUpdateCode})(routeId, Route)${reactRefreshCall}\n }\n hot.dispose((data) => {\n if (routeId) {\n data['tsr-route-id'] = routeId\n }\n })\n hot.accept()\n}\n`,\n {\n syntacticPlaceholders: true,\n },\n )(),\n )\n\n return statements\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,0BACd,uBACA,MAIoB;CACpB,MAAM,wBAAwB,4BAAA,yBAAyB,sBAAsB;CAC7E,MAAM,uBACJ,OAAO,KAAK,YAAY,WACpB,KAAK,UAAU,KAAK,QAAQ,GAC5B;CAEN,MAAM,aAAiC,EAAE;CAsBzC,MAAM,mBACJ,KAAK,oBAAoB,UACrB;;;;;;;;;;qCAWA;AAEN,KAAI,KAAK,oBAAoB,QAC3B,YAAW,KACT,gBAAS,UACP,2FACD,EAAE,CACJ;AAGH,YAAW,KACT,gBAAS,UACP;;;;wFAIkF,qBAAqB;;;;;;;;;OAStG,sBAAsB,mBAAmB,iBAAiB;;;;;;;;;GAU3D,EACE,uBAAuB,MACxB,CACF,EAAE,CACJ;AAED,QAAO"}
1
+ {"version":3,"file":"webpack-adapter.cjs","names":[],"sources":["../../../../src/core/hmr/webpack-adapter.ts"],"sourcesContent":["import * as template from '@babel/template'\nimport { getHandleRouteUpdateCode } from './handle-route-update'\nimport type { Config } from '../config'\nimport type * as t from '@babel/types'\n\n/**\n * Emits HMR accept code for bundlers with webpack-compatible `module.hot`\n * semantics (classic webpack via `import.meta.webpackHot`, and Rspack).\n *\n * Unlike Vite's `hot.accept((newModule) => {...})` — where the callback receives\n * the freshly re-imported module — webpack re-executes the module factory on\n * accept, so our HMR logic must live at module top level and read the previous\n * `routeId` out of `hot.data`. `hot.dispose` stashes it for the next run, and\n * `hot.accept()` (no callback) enrolls us as a self-accepting boundary.\n *\n * Returns an array of statements that patches route definitions during HMR.\n */\nexport function createWebpackHmrStatement(\n stableRouteOptionKeys: Array<string>,\n opts: {\n targetFramework: Config['target']\n routeId?: string\n },\n): Array<t.Statement> {\n const handleRouteUpdateCode = getHandleRouteUpdateCode(stableRouteOptionKeys)\n const staticRouteIdLiteral =\n typeof opts.routeId === 'string'\n ? JSON.stringify(opts.routeId)\n : 'undefined'\n\n // React-only: route modules aren't React Refresh \"boundaries\" (they export\n // a non-component `Route`), so the bundler's react-refresh runtime won't\n // call `performReactRefresh` for us. We kick it manually after swapping\n // route options so newly-registered component bodies get patched into live\n // fibers.\n //\n // Webpack and Rspack refresh plugins inject `__react_refresh_utils__` via\n // ProvidePlugin. Use it when present instead of importing\n // `react-refresh/runtime`, because Rsbuild apps may use React without the\n // React plugin and therefore may not have that optional dependency installed.\n //\n // Use the same delayed refresh style as Rspack's React Refresh runtime.\n // Route modules and their split component chunks can arrive in separate HMR\n // steps under CI load; a microtask can run before the split chunk registers\n // its new component family, causing the refresh to no-op or remount.\n //\n // For non-React frameworks we skip this entirely.\n const reactRefreshCall =\n opts.targetFramework === 'react'\n ? `\n try {\n const tsrReactRefreshUtils =\n typeof __react_refresh_utils__ !== 'undefined'\n ? __react_refresh_utils__\n : undefined\n const tsrEnqueueUpdate =\n tsrReactRefreshUtils && typeof tsrReactRefreshUtils.enqueueUpdate === 'function'\n ? tsrReactRefreshUtils.enqueueUpdate\n : undefined\n if (tsrEnqueueUpdate) {\n tsrEnqueueUpdate(() => {})\n }\n } catch (_err) { /* noop */ }`\n : ''\n\n return [\n template.statement(\n `\nif (import.meta.webpackHot) {\n const hot = import.meta.webpackHot\n const hotData = hot.data ??= {}\n const routeId = hotData['tsr-route-id'] ?? Route.id ?? (Route.isRoot ? '__root__' : ${staticRouteIdLiteral})\n if (routeId) {\n hotData['tsr-route-id'] = routeId\n }\n const existingRoute =\n typeof window !== 'undefined' && routeId\n ? window.__TSR_ROUTER__?.routesById?.[routeId]\n : undefined\n if (routeId && existingRoute && existingRoute !== Route) {\n (${handleRouteUpdateCode})(routeId, Route)${reactRefreshCall}\n }\n hot.dispose((data) => {\n if (routeId) {\n data['tsr-route-id'] = routeId\n }\n })\n hot.accept()\n}\n`,\n {\n syntacticPlaceholders: true,\n },\n )(),\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAgB,0BACd,uBACA,MAIoB;CACpB,MAAM,wBAAwB,4BAAA,yBAAyB,sBAAsB;CAC7E,MAAM,uBACJ,OAAO,KAAK,YAAY,WACpB,KAAK,UAAU,KAAK,QAAQ,GAC5B;CAmBN,MAAM,mBACJ,KAAK,oBAAoB,UACrB;;;;;;;;;;;;;qCAcA;AAEN,QAAO,CACL,gBAAS,UACP;;;;wFAIkF,qBAAqB;;;;;;;;;OAStG,sBAAsB,mBAAmB,iBAAiB;;;;;;;;;GAU3D,EACE,uBAAuB,MACxB,CACF,EAAE,CACJ"}
@@ -10,9 +10,7 @@ import type * as t from '@babel/types';
10
10
  * `routeId` out of `hot.data`. `hot.dispose` stashes it for the next run, and
11
11
  * `hot.accept()` (no callback) enrolls us as a self-accepting boundary.
12
12
  *
13
- * Returns an array of statements so that for React we can prepend an
14
- * `import { performReactRefresh } from 'react-refresh/runtime'` hoisted to the
15
- * top of the module.
13
+ * Returns an array of statements that patches route definitions during HMR.
16
14
  */
17
15
  export declare function createWebpackHmrStatement(stableRouteOptionKeys: Array<string>, opts: {
18
16
  targetFramework: Config['target'];
@@ -10,9 +10,7 @@ import type * as t from '@babel/types';
10
10
  * `routeId` out of `hot.data`. `hot.dispose` stashes it for the next run, and
11
11
  * `hot.accept()` (no callback) enrolls us as a self-accepting boundary.
12
12
  *
13
- * Returns an array of statements so that for React we can prepend an
14
- * `import { performReactRefresh } from 'react-refresh/runtime'` hoisted to the
15
- * top of the module.
13
+ * Returns an array of statements that patches route definitions during HMR.
16
14
  */
17
15
  export declare function createWebpackHmrStatement(stableRouteOptionKeys: Array<string>, opts: {
18
16
  targetFramework: Config['target'];
@@ -11,27 +11,26 @@ import * as template from "@babel/template";
11
11
  * `routeId` out of `hot.data`. `hot.dispose` stashes it for the next run, and
12
12
  * `hot.accept()` (no callback) enrolls us as a self-accepting boundary.
13
13
  *
14
- * Returns an array of statements so that for React we can prepend an
15
- * `import { performReactRefresh } from 'react-refresh/runtime'` hoisted to the
16
- * top of the module.
14
+ * Returns an array of statements that patches route definitions during HMR.
17
15
  */
18
16
  function createWebpackHmrStatement(stableRouteOptionKeys, opts) {
19
17
  const handleRouteUpdateCode = getHandleRouteUpdateCode(stableRouteOptionKeys);
20
18
  const staticRouteIdLiteral = typeof opts.routeId === "string" ? JSON.stringify(opts.routeId) : "undefined";
21
- const statements = [];
22
19
  const reactRefreshCall = opts.targetFramework === "react" ? `
23
- const tsrRefreshState = globalThis.__TSR_HMR__ ??= {}
24
20
  try {
25
- if (!tsrRefreshState.refreshScheduled) {
26
- tsrRefreshState.refreshScheduled = true
27
- setTimeout(() => {
28
- tsrRefreshState.refreshScheduled = false
29
- try { __tsr_performReactRefresh() } catch (_e) { /* noop */ }
30
- }, 30)
21
+ const tsrReactRefreshUtils =
22
+ typeof __react_refresh_utils__ !== 'undefined'
23
+ ? __react_refresh_utils__
24
+ : undefined
25
+ const tsrEnqueueUpdate =
26
+ tsrReactRefreshUtils && typeof tsrReactRefreshUtils.enqueueUpdate === 'function'
27
+ ? tsrReactRefreshUtils.enqueueUpdate
28
+ : undefined
29
+ if (tsrEnqueueUpdate) {
30
+ tsrEnqueueUpdate(() => {})
31
31
  }
32
32
  } catch (_err) { /* noop */ }` : "";
33
- if (opts.targetFramework === "react") statements.push(template.statement(`import { performReactRefresh as __tsr_performReactRefresh } from 'react-refresh/runtime'`)());
34
- statements.push(template.statement(`
33
+ return [template.statement(`
35
34
  if (import.meta.webpackHot) {
36
35
  const hot = import.meta.webpackHot
37
36
  const hotData = hot.data ??= {}
@@ -53,8 +52,7 @@ if (import.meta.webpackHot) {
53
52
  })
54
53
  hot.accept()
55
54
  }
56
- `, { syntacticPlaceholders: true })());
57
- return statements;
55
+ `, { syntacticPlaceholders: true })()];
58
56
  }
59
57
  //#endregion
60
58
  export { createWebpackHmrStatement };
@@ -1 +1 @@
1
- {"version":3,"file":"webpack-adapter.js","names":[],"sources":["../../../../src/core/hmr/webpack-adapter.ts"],"sourcesContent":["import * as template from '@babel/template'\nimport { getHandleRouteUpdateCode } from './handle-route-update'\nimport type { Config } from '../config'\nimport type * as t from '@babel/types'\n\n/**\n * Emits HMR accept code for bundlers with webpack-compatible `module.hot`\n * semantics (classic webpack via `import.meta.webpackHot`, and Rspack).\n *\n * Unlike Vite's `hot.accept((newModule) => {...})` — where the callback receives\n * the freshly re-imported module — webpack re-executes the module factory on\n * accept, so our HMR logic must live at module top level and read the previous\n * `routeId` out of `hot.data`. `hot.dispose` stashes it for the next run, and\n * `hot.accept()` (no callback) enrolls us as a self-accepting boundary.\n *\n * Returns an array of statements so that for React we can prepend an\n * `import { performReactRefresh } from 'react-refresh/runtime'` hoisted to the\n * top of the module.\n */\nexport function createWebpackHmrStatement(\n stableRouteOptionKeys: Array<string>,\n opts: {\n targetFramework: Config['target']\n routeId?: string\n },\n): Array<t.Statement> {\n const handleRouteUpdateCode = getHandleRouteUpdateCode(stableRouteOptionKeys)\n const staticRouteIdLiteral =\n typeof opts.routeId === 'string'\n ? JSON.stringify(opts.routeId)\n : 'undefined'\n\n const statements: Array<t.Statement> = []\n\n // React-only: route modules aren't React Refresh \"boundaries\" (they export\n // a non-component `Route`), so the bundler's react-refresh runtime won't\n // call `performReactRefresh` for us. We kick it manually after swapping\n // route options so newly-registered component bodies get patched into live\n // fibers.\n //\n // We import `performReactRefresh` directly from `react-refresh/runtime` —\n // the canonical public API — rather than relying on the ProvidePlugin-\n // injected `__react_refresh_utils__` global, whose name is an internal\n // detail of `@rspack/plugin-react-refresh`. The rspack plugin aliases\n // `react-refresh` its bundled runtime (getRefreshRuntimeDirPath), so this\n // resolves to the same singleton the plugin itself uses and shares the\n // registry React was patched against.\n //\n // Use the same delayed refresh style as Rspack's React Refresh runtime.\n // Route modules and their split component chunks can arrive in separate HMR\n // steps under CI load; a microtask can run before the split chunk registers\n // its new component family, causing the refresh to no-op or remount.\n //\n // For non-React frameworks we skip this entirely.\n const reactRefreshCall =\n opts.targetFramework === 'react'\n ? `\n const tsrRefreshState = globalThis.__TSR_HMR__ ??= {}\n try {\n if (!tsrRefreshState.refreshScheduled) {\n tsrRefreshState.refreshScheduled = true\n setTimeout(() => {\n tsrRefreshState.refreshScheduled = false\n try { __tsr_performReactRefresh() } catch (_e) { /* noop */ }\n }, 30)\n }\n } catch (_err) { /* noop */ }`\n : ''\n\n if (opts.targetFramework === 'react') {\n statements.push(\n template.statement(\n `import { performReactRefresh as __tsr_performReactRefresh } from 'react-refresh/runtime'`,\n )(),\n )\n }\n\n statements.push(\n template.statement(\n `\nif (import.meta.webpackHot) {\n const hot = import.meta.webpackHot\n const hotData = hot.data ??= {}\n const routeId = hotData['tsr-route-id'] ?? Route.id ?? (Route.isRoot ? '__root__' : ${staticRouteIdLiteral})\n if (routeId) {\n hotData['tsr-route-id'] = routeId\n }\n const existingRoute =\n typeof window !== 'undefined' && routeId\n ? window.__TSR_ROUTER__?.routesById?.[routeId]\n : undefined\n if (routeId && existingRoute && existingRoute !== Route) {\n (${handleRouteUpdateCode})(routeId, Route)${reactRefreshCall}\n }\n hot.dispose((data) => {\n if (routeId) {\n data['tsr-route-id'] = routeId\n }\n })\n hot.accept()\n}\n`,\n {\n syntacticPlaceholders: true,\n },\n )(),\n )\n\n return statements\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,SAAgB,0BACd,uBACA,MAIoB;CACpB,MAAM,wBAAwB,yBAAyB,sBAAsB;CAC7E,MAAM,uBACJ,OAAO,KAAK,YAAY,WACpB,KAAK,UAAU,KAAK,QAAQ,GAC5B;CAEN,MAAM,aAAiC,EAAE;CAsBzC,MAAM,mBACJ,KAAK,oBAAoB,UACrB;;;;;;;;;;qCAWA;AAEN,KAAI,KAAK,oBAAoB,QAC3B,YAAW,KACT,SAAS,UACP,2FACD,EAAE,CACJ;AAGH,YAAW,KACT,SAAS,UACP;;;;wFAIkF,qBAAqB;;;;;;;;;OAStG,sBAAsB,mBAAmB,iBAAiB;;;;;;;;;GAU3D,EACE,uBAAuB,MACxB,CACF,EAAE,CACJ;AAED,QAAO"}
1
+ {"version":3,"file":"webpack-adapter.js","names":[],"sources":["../../../../src/core/hmr/webpack-adapter.ts"],"sourcesContent":["import * as template from '@babel/template'\nimport { getHandleRouteUpdateCode } from './handle-route-update'\nimport type { Config } from '../config'\nimport type * as t from '@babel/types'\n\n/**\n * Emits HMR accept code for bundlers with webpack-compatible `module.hot`\n * semantics (classic webpack via `import.meta.webpackHot`, and Rspack).\n *\n * Unlike Vite's `hot.accept((newModule) => {...})` — where the callback receives\n * the freshly re-imported module — webpack re-executes the module factory on\n * accept, so our HMR logic must live at module top level and read the previous\n * `routeId` out of `hot.data`. `hot.dispose` stashes it for the next run, and\n * `hot.accept()` (no callback) enrolls us as a self-accepting boundary.\n *\n * Returns an array of statements that patches route definitions during HMR.\n */\nexport function createWebpackHmrStatement(\n stableRouteOptionKeys: Array<string>,\n opts: {\n targetFramework: Config['target']\n routeId?: string\n },\n): Array<t.Statement> {\n const handleRouteUpdateCode = getHandleRouteUpdateCode(stableRouteOptionKeys)\n const staticRouteIdLiteral =\n typeof opts.routeId === 'string'\n ? JSON.stringify(opts.routeId)\n : 'undefined'\n\n // React-only: route modules aren't React Refresh \"boundaries\" (they export\n // a non-component `Route`), so the bundler's react-refresh runtime won't\n // call `performReactRefresh` for us. We kick it manually after swapping\n // route options so newly-registered component bodies get patched into live\n // fibers.\n //\n // Webpack and Rspack refresh plugins inject `__react_refresh_utils__` via\n // ProvidePlugin. Use it when present instead of importing\n // `react-refresh/runtime`, because Rsbuild apps may use React without the\n // React plugin and therefore may not have that optional dependency installed.\n //\n // Use the same delayed refresh style as Rspack's React Refresh runtime.\n // Route modules and their split component chunks can arrive in separate HMR\n // steps under CI load; a microtask can run before the split chunk registers\n // its new component family, causing the refresh to no-op or remount.\n //\n // For non-React frameworks we skip this entirely.\n const reactRefreshCall =\n opts.targetFramework === 'react'\n ? `\n try {\n const tsrReactRefreshUtils =\n typeof __react_refresh_utils__ !== 'undefined'\n ? __react_refresh_utils__\n : undefined\n const tsrEnqueueUpdate =\n tsrReactRefreshUtils && typeof tsrReactRefreshUtils.enqueueUpdate === 'function'\n ? tsrReactRefreshUtils.enqueueUpdate\n : undefined\n if (tsrEnqueueUpdate) {\n tsrEnqueueUpdate(() => {})\n }\n } catch (_err) { /* noop */ }`\n : ''\n\n return [\n template.statement(\n `\nif (import.meta.webpackHot) {\n const hot = import.meta.webpackHot\n const hotData = hot.data ??= {}\n const routeId = hotData['tsr-route-id'] ?? Route.id ?? (Route.isRoot ? '__root__' : ${staticRouteIdLiteral})\n if (routeId) {\n hotData['tsr-route-id'] = routeId\n }\n const existingRoute =\n typeof window !== 'undefined' && routeId\n ? window.__TSR_ROUTER__?.routesById?.[routeId]\n : undefined\n if (routeId && existingRoute && existingRoute !== Route) {\n (${handleRouteUpdateCode})(routeId, Route)${reactRefreshCall}\n }\n hot.dispose((data) => {\n if (routeId) {\n data['tsr-route-id'] = routeId\n }\n })\n hot.accept()\n}\n`,\n {\n syntacticPlaceholders: true,\n },\n )(),\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,SAAgB,0BACd,uBACA,MAIoB;CACpB,MAAM,wBAAwB,yBAAyB,sBAAsB;CAC7E,MAAM,uBACJ,OAAO,KAAK,YAAY,WACpB,KAAK,UAAU,KAAK,QAAQ,GAC5B;CAmBN,MAAM,mBACJ,KAAK,oBAAoB,UACrB;;;;;;;;;;;;;qCAcA;AAEN,QAAO,CACL,SAAS,UACP;;;;wFAIkF,qBAAqB;;;;;;;;;OAStG,sBAAsB,mBAAmB,iBAAiB;;;;;;;;;GAU3D,EACE,uBAAuB,MACxB,CACF,EAAE,CACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/router-plugin",
3
- "version": "1.167.24",
3
+ "version": "1.167.26",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -97,7 +97,7 @@
97
97
  "@babel/traverse": "^7.28.5",
98
98
  "@babel/types": "^7.28.5",
99
99
  "chokidar": "^3.6.0",
100
- "unplugin": "^2.1.2",
100
+ "unplugin": "^3.0.0",
101
101
  "zod": "^3.24.2",
102
102
  "@tanstack/router-core": "1.168.16",
103
103
  "@tanstack/router-generator": "1.166.34",
@@ -13,9 +13,7 @@ import type * as t from '@babel/types'
13
13
  * `routeId` out of `hot.data`. `hot.dispose` stashes it for the next run, and
14
14
  * `hot.accept()` (no callback) enrolls us as a self-accepting boundary.
15
15
  *
16
- * Returns an array of statements so that for React we can prepend an
17
- * `import { performReactRefresh } from 'react-refresh/runtime'` hoisted to the
18
- * top of the module.
16
+ * Returns an array of statements that patches route definitions during HMR.
19
17
  */
20
18
  export function createWebpackHmrStatement(
21
19
  stableRouteOptionKeys: Array<string>,
@@ -30,21 +28,16 @@ export function createWebpackHmrStatement(
30
28
  ? JSON.stringify(opts.routeId)
31
29
  : 'undefined'
32
30
 
33
- const statements: Array<t.Statement> = []
34
-
35
31
  // React-only: route modules aren't React Refresh "boundaries" (they export
36
32
  // a non-component `Route`), so the bundler's react-refresh runtime won't
37
33
  // call `performReactRefresh` for us. We kick it manually after swapping
38
34
  // route options so newly-registered component bodies get patched into live
39
35
  // fibers.
40
36
  //
41
- // We import `performReactRefresh` directly from `react-refresh/runtime`
42
- // the canonical public API rather than relying on the ProvidePlugin-
43
- // injected `__react_refresh_utils__` global, whose name is an internal
44
- // detail of `@rspack/plugin-react-refresh`. The rspack plugin aliases
45
- // `react-refresh` → its bundled runtime (getRefreshRuntimeDirPath), so this
46
- // resolves to the same singleton the plugin itself uses and shares the
47
- // registry React was patched against.
37
+ // Webpack and Rspack refresh plugins inject `__react_refresh_utils__` via
38
+ // ProvidePlugin. Use it when present instead of importing
39
+ // `react-refresh/runtime`, because Rsbuild apps may use React without the
40
+ // React plugin and therefore may not have that optional dependency installed.
48
41
  //
49
42
  // Use the same delayed refresh style as Rspack's React Refresh runtime.
50
43
  // Route modules and their split component chunks can arrive in separate HMR
@@ -55,27 +48,22 @@ export function createWebpackHmrStatement(
55
48
  const reactRefreshCall =
56
49
  opts.targetFramework === 'react'
57
50
  ? `
58
- const tsrRefreshState = globalThis.__TSR_HMR__ ??= {}
59
51
  try {
60
- if (!tsrRefreshState.refreshScheduled) {
61
- tsrRefreshState.refreshScheduled = true
62
- setTimeout(() => {
63
- tsrRefreshState.refreshScheduled = false
64
- try { __tsr_performReactRefresh() } catch (_e) { /* noop */ }
65
- }, 30)
52
+ const tsrReactRefreshUtils =
53
+ typeof __react_refresh_utils__ !== 'undefined'
54
+ ? __react_refresh_utils__
55
+ : undefined
56
+ const tsrEnqueueUpdate =
57
+ tsrReactRefreshUtils && typeof tsrReactRefreshUtils.enqueueUpdate === 'function'
58
+ ? tsrReactRefreshUtils.enqueueUpdate
59
+ : undefined
60
+ if (tsrEnqueueUpdate) {
61
+ tsrEnqueueUpdate(() => {})
66
62
  }
67
63
  } catch (_err) { /* noop */ }`
68
64
  : ''
69
65
 
70
- if (opts.targetFramework === 'react') {
71
- statements.push(
72
- template.statement(
73
- `import { performReactRefresh as __tsr_performReactRefresh } from 'react-refresh/runtime'`,
74
- )(),
75
- )
76
- }
77
-
78
- statements.push(
66
+ return [
79
67
  template.statement(
80
68
  `
81
69
  if (import.meta.webpackHot) {
@@ -104,7 +92,5 @@ if (import.meta.webpackHot) {
104
92
  syntacticPlaceholders: true,
105
93
  },
106
94
  )(),
107
- )
108
-
109
- return statements
95
+ ]
110
96
  }