@tanstack/router-plugin 1.167.23 → 1.167.25
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.
- package/dist/cjs/core/hmr/webpack-adapter.cjs +13 -15
- package/dist/cjs/core/hmr/webpack-adapter.cjs.map +1 -1
- package/dist/cjs/core/hmr/webpack-adapter.d.cts +1 -3
- package/dist/cjs/core/router-composed-plugin.cjs +28 -1
- package/dist/cjs/core/router-composed-plugin.cjs.map +1 -1
- package/dist/esm/core/hmr/webpack-adapter.d.ts +1 -3
- package/dist/esm/core/hmr/webpack-adapter.js +13 -15
- package/dist/esm/core/hmr/webpack-adapter.js.map +1 -1
- package/dist/esm/core/router-composed-plugin.js +28 -1
- package/dist/esm/core/router-composed-plugin.js.map +1 -1
- package/package.json +4 -4
- package/src/core/hmr/webpack-adapter.ts +17 -31
- package/src/core/router-composed-plugin.ts +52 -2
|
@@ -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
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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'];
|
|
@@ -4,6 +4,16 @@ const require_router_generator_plugin = require("./router-generator-plugin.cjs")
|
|
|
4
4
|
const require_router_hmr_plugin = require("./router-hmr-plugin.cjs");
|
|
5
5
|
let _tanstack_router_generator = require("@tanstack/router-generator");
|
|
6
6
|
//#region src/core/router-composed-plugin.ts
|
|
7
|
+
var INLINE_CSS_DEFAULT_DEFINES = {
|
|
8
|
+
"process.env.TSS_INLINE_CSS_ENABLED": JSON.stringify("false"),
|
|
9
|
+
"import.meta.env.TSS_INLINE_CSS_ENABLED": JSON.stringify("false")
|
|
10
|
+
};
|
|
11
|
+
function applyWebpackInlineCssDefaultDefinePlugin(compiler) {
|
|
12
|
+
new compiler.webpack.DefinePlugin(INLINE_CSS_DEFAULT_DEFINES).apply(compiler);
|
|
13
|
+
}
|
|
14
|
+
function applyRspackInlineCssDefaultDefinePlugin(compiler) {
|
|
15
|
+
new compiler.webpack.DefinePlugin(INLINE_CSS_DEFAULT_DEFINES).apply(compiler);
|
|
16
|
+
}
|
|
7
17
|
var unpluginRouterComposedFactory = (options = {}, meta) => {
|
|
8
18
|
const ROOT = process.cwd();
|
|
9
19
|
const userConfig = (0, _tanstack_router_generator.getConfig)(typeof options === "function" ? options() : options, ROOT);
|
|
@@ -14,7 +24,24 @@ var unpluginRouterComposedFactory = (options = {}, meta) => {
|
|
|
14
24
|
};
|
|
15
25
|
const routerGenerator = getPlugin(require_router_generator_plugin.unpluginRouterGeneratorFactory);
|
|
16
26
|
const routerCodeSplitter = getPlugin(require_router_code_splitter_plugin.unpluginRouterCodeSplitterFactory);
|
|
17
|
-
const result = [
|
|
27
|
+
const result = [{
|
|
28
|
+
name: "tanstack:router-inline-css-defaults",
|
|
29
|
+
vite: { config() {
|
|
30
|
+
return { define: { ...INLINE_CSS_DEFAULT_DEFINES } };
|
|
31
|
+
} },
|
|
32
|
+
webpack(compiler) {
|
|
33
|
+
applyWebpackInlineCssDefaultDefinePlugin(compiler);
|
|
34
|
+
},
|
|
35
|
+
rspack(compiler) {
|
|
36
|
+
applyRspackInlineCssDefaultDefinePlugin(compiler);
|
|
37
|
+
},
|
|
38
|
+
esbuild: { config(options) {
|
|
39
|
+
options.define = {
|
|
40
|
+
...INLINE_CSS_DEFAULT_DEFINES,
|
|
41
|
+
...options.define
|
|
42
|
+
};
|
|
43
|
+
} }
|
|
44
|
+
}, ...routerGenerator];
|
|
18
45
|
if (userConfig.autoCodeSplitting) result.push(...routerCodeSplitter);
|
|
19
46
|
if (!(process.env.NODE_ENV === "production") && !userConfig.autoCodeSplitting) {
|
|
20
47
|
const routerHmr = getPlugin(require_router_hmr_plugin.unpluginRouterHmrFactory);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-composed-plugin.cjs","names":[],"sources":["../../../src/core/router-composed-plugin.ts"],"sourcesContent":["import { getConfig } from '@tanstack/router-generator'\nimport { unpluginRouterGeneratorFactory } from './router-generator-plugin'\nimport { unpluginRouterCodeSplitterFactory } from './router-code-splitter-plugin'\nimport { unpluginRouterHmrFactory } from './router-hmr-plugin'\nimport type { Config } from './config'\nimport type {
|
|
1
|
+
{"version":3,"file":"router-composed-plugin.cjs","names":[],"sources":["../../../src/core/router-composed-plugin.ts"],"sourcesContent":["import { getConfig } from '@tanstack/router-generator'\nimport { unpluginRouterGeneratorFactory } from './router-generator-plugin'\nimport { unpluginRouterCodeSplitterFactory } from './router-code-splitter-plugin'\nimport { unpluginRouterHmrFactory } from './router-hmr-plugin'\nimport type { Config } from './config'\nimport type {\n RspackCompiler,\n UnpluginFactory,\n UnpluginOptions,\n WebpackCompiler,\n} from 'unplugin'\n\nconst INLINE_CSS_DEFAULT_DEFINES = {\n 'process.env.TSS_INLINE_CSS_ENABLED': JSON.stringify('false'),\n 'import.meta.env.TSS_INLINE_CSS_ENABLED': JSON.stringify('false'),\n}\n\ntype EsbuildOptionsWithDefine = Parameters<\n NonNullable<NonNullable<UnpluginOptions['esbuild']>['config']>\n>[0]\n\nfunction applyWebpackInlineCssDefaultDefinePlugin(compiler: WebpackCompiler) {\n new compiler.webpack.DefinePlugin(INLINE_CSS_DEFAULT_DEFINES).apply(compiler)\n}\n\nfunction applyRspackInlineCssDefaultDefinePlugin(compiler: RspackCompiler) {\n new compiler.webpack.DefinePlugin(INLINE_CSS_DEFAULT_DEFINES).apply(compiler)\n}\n\nexport const unpluginRouterComposedFactory: UnpluginFactory<\n Partial<Config | (() => Config)> | undefined\n> = (options = {}, meta) => {\n const ROOT: string = process.cwd()\n const userConfig = getConfig(\n (typeof options === 'function' ? options() : options) as Partial<Config>,\n ROOT,\n )\n\n const getPlugin = (\n pluginFactory: UnpluginFactory<Partial<Config | (() => Config)>>,\n ) => {\n const plugin = pluginFactory(options, meta)\n if (!Array.isArray(plugin)) {\n return [plugin]\n }\n return plugin\n }\n\n const routerGenerator = getPlugin(unpluginRouterGeneratorFactory)\n const routerCodeSplitter = getPlugin(unpluginRouterCodeSplitterFactory)\n\n const result = [\n {\n name: 'tanstack:router-inline-css-defaults',\n vite: {\n config() {\n return {\n define: {\n ...INLINE_CSS_DEFAULT_DEFINES,\n },\n }\n },\n },\n webpack(compiler: WebpackCompiler) {\n applyWebpackInlineCssDefaultDefinePlugin(compiler)\n },\n rspack(compiler: RspackCompiler) {\n applyRspackInlineCssDefaultDefinePlugin(compiler)\n },\n esbuild: {\n config(options: EsbuildOptionsWithDefine) {\n options.define = {\n ...INLINE_CSS_DEFAULT_DEFINES,\n ...options.define,\n }\n },\n },\n },\n ...routerGenerator,\n ]\n if (userConfig.autoCodeSplitting) {\n result.push(...routerCodeSplitter)\n }\n\n const isProduction = process.env.NODE_ENV === 'production'\n\n if (!isProduction && !userConfig.autoCodeSplitting) {\n const routerHmr = getPlugin(unpluginRouterHmrFactory)\n result.push(...routerHmr)\n }\n return result\n}\n"],"mappings":";;;;;;AAYA,IAAM,6BAA6B;CACjC,sCAAsC,KAAK,UAAU,QAAQ;CAC7D,0CAA0C,KAAK,UAAU,QAAQ;CAClE;AAMD,SAAS,yCAAyC,UAA2B;AAC3E,KAAI,SAAS,QAAQ,aAAa,2BAA2B,CAAC,MAAM,SAAS;;AAG/E,SAAS,wCAAwC,UAA0B;AACzE,KAAI,SAAS,QAAQ,aAAa,2BAA2B,CAAC,MAAM,SAAS;;AAG/E,IAAa,iCAER,UAAU,EAAE,EAAE,SAAS;CAC1B,MAAM,OAAe,QAAQ,KAAK;CAClC,MAAM,cAAA,GAAA,2BAAA,WACH,OAAO,YAAY,aAAa,SAAS,GAAG,SAC7C,KACD;CAED,MAAM,aACJ,kBACG;EACH,MAAM,SAAS,cAAc,SAAS,KAAK;AAC3C,MAAI,CAAC,MAAM,QAAQ,OAAO,CACxB,QAAO,CAAC,OAAO;AAEjB,SAAO;;CAGT,MAAM,kBAAkB,UAAU,gCAAA,+BAA+B;CACjE,MAAM,qBAAqB,UAAU,oCAAA,kCAAkC;CAEvE,MAAM,SAAS,CACb;EACE,MAAM;EACN,MAAM,EACJ,SAAS;AACP,UAAO,EACL,QAAQ,EACN,GAAG,4BACJ,EACF;KAEJ;EACD,QAAQ,UAA2B;AACjC,4CAAyC,SAAS;;EAEpD,OAAO,UAA0B;AAC/B,2CAAwC,SAAS;;EAEnD,SAAS,EACP,OAAO,SAAmC;AACxC,WAAQ,SAAS;IACf,GAAG;IACH,GAAG,QAAQ;IACZ;KAEJ;EACF,EACD,GAAG,gBACJ;AACD,KAAI,WAAW,kBACb,QAAO,KAAK,GAAG,mBAAmB;AAKpC,KAAI,EAAA,QAAA,IAAA,aAF0C,iBAEzB,CAAC,WAAW,mBAAmB;EAClD,MAAM,YAAY,UAAU,0BAAA,yBAAyB;AACrD,SAAO,KAAK,GAAG,UAAU;;AAE3B,QAAO"}
|
|
@@ -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
|
|
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
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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
|
|
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"}
|
|
@@ -3,6 +3,16 @@ import { unpluginRouterGeneratorFactory } from "./router-generator-plugin.js";
|
|
|
3
3
|
import { unpluginRouterHmrFactory } from "./router-hmr-plugin.js";
|
|
4
4
|
import { getConfig } from "@tanstack/router-generator";
|
|
5
5
|
//#region src/core/router-composed-plugin.ts
|
|
6
|
+
var INLINE_CSS_DEFAULT_DEFINES = {
|
|
7
|
+
"process.env.TSS_INLINE_CSS_ENABLED": JSON.stringify("false"),
|
|
8
|
+
"import.meta.env.TSS_INLINE_CSS_ENABLED": JSON.stringify("false")
|
|
9
|
+
};
|
|
10
|
+
function applyWebpackInlineCssDefaultDefinePlugin(compiler) {
|
|
11
|
+
new compiler.webpack.DefinePlugin(INLINE_CSS_DEFAULT_DEFINES).apply(compiler);
|
|
12
|
+
}
|
|
13
|
+
function applyRspackInlineCssDefaultDefinePlugin(compiler) {
|
|
14
|
+
new compiler.webpack.DefinePlugin(INLINE_CSS_DEFAULT_DEFINES).apply(compiler);
|
|
15
|
+
}
|
|
6
16
|
var unpluginRouterComposedFactory = (options = {}, meta) => {
|
|
7
17
|
const ROOT = process.cwd();
|
|
8
18
|
const userConfig = getConfig(typeof options === "function" ? options() : options, ROOT);
|
|
@@ -13,7 +23,24 @@ var unpluginRouterComposedFactory = (options = {}, meta) => {
|
|
|
13
23
|
};
|
|
14
24
|
const routerGenerator = getPlugin(unpluginRouterGeneratorFactory);
|
|
15
25
|
const routerCodeSplitter = getPlugin(unpluginRouterCodeSplitterFactory);
|
|
16
|
-
const result = [
|
|
26
|
+
const result = [{
|
|
27
|
+
name: "tanstack:router-inline-css-defaults",
|
|
28
|
+
vite: { config() {
|
|
29
|
+
return { define: { ...INLINE_CSS_DEFAULT_DEFINES } };
|
|
30
|
+
} },
|
|
31
|
+
webpack(compiler) {
|
|
32
|
+
applyWebpackInlineCssDefaultDefinePlugin(compiler);
|
|
33
|
+
},
|
|
34
|
+
rspack(compiler) {
|
|
35
|
+
applyRspackInlineCssDefaultDefinePlugin(compiler);
|
|
36
|
+
},
|
|
37
|
+
esbuild: { config(options) {
|
|
38
|
+
options.define = {
|
|
39
|
+
...INLINE_CSS_DEFAULT_DEFINES,
|
|
40
|
+
...options.define
|
|
41
|
+
};
|
|
42
|
+
} }
|
|
43
|
+
}, ...routerGenerator];
|
|
17
44
|
if (userConfig.autoCodeSplitting) result.push(...routerCodeSplitter);
|
|
18
45
|
if (!(process.env.NODE_ENV === "production") && !userConfig.autoCodeSplitting) {
|
|
19
46
|
const routerHmr = getPlugin(unpluginRouterHmrFactory);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-composed-plugin.js","names":[],"sources":["../../../src/core/router-composed-plugin.ts"],"sourcesContent":["import { getConfig } from '@tanstack/router-generator'\nimport { unpluginRouterGeneratorFactory } from './router-generator-plugin'\nimport { unpluginRouterCodeSplitterFactory } from './router-code-splitter-plugin'\nimport { unpluginRouterHmrFactory } from './router-hmr-plugin'\nimport type { Config } from './config'\nimport type {
|
|
1
|
+
{"version":3,"file":"router-composed-plugin.js","names":[],"sources":["../../../src/core/router-composed-plugin.ts"],"sourcesContent":["import { getConfig } from '@tanstack/router-generator'\nimport { unpluginRouterGeneratorFactory } from './router-generator-plugin'\nimport { unpluginRouterCodeSplitterFactory } from './router-code-splitter-plugin'\nimport { unpluginRouterHmrFactory } from './router-hmr-plugin'\nimport type { Config } from './config'\nimport type {\n RspackCompiler,\n UnpluginFactory,\n UnpluginOptions,\n WebpackCompiler,\n} from 'unplugin'\n\nconst INLINE_CSS_DEFAULT_DEFINES = {\n 'process.env.TSS_INLINE_CSS_ENABLED': JSON.stringify('false'),\n 'import.meta.env.TSS_INLINE_CSS_ENABLED': JSON.stringify('false'),\n}\n\ntype EsbuildOptionsWithDefine = Parameters<\n NonNullable<NonNullable<UnpluginOptions['esbuild']>['config']>\n>[0]\n\nfunction applyWebpackInlineCssDefaultDefinePlugin(compiler: WebpackCompiler) {\n new compiler.webpack.DefinePlugin(INLINE_CSS_DEFAULT_DEFINES).apply(compiler)\n}\n\nfunction applyRspackInlineCssDefaultDefinePlugin(compiler: RspackCompiler) {\n new compiler.webpack.DefinePlugin(INLINE_CSS_DEFAULT_DEFINES).apply(compiler)\n}\n\nexport const unpluginRouterComposedFactory: UnpluginFactory<\n Partial<Config | (() => Config)> | undefined\n> = (options = {}, meta) => {\n const ROOT: string = process.cwd()\n const userConfig = getConfig(\n (typeof options === 'function' ? options() : options) as Partial<Config>,\n ROOT,\n )\n\n const getPlugin = (\n pluginFactory: UnpluginFactory<Partial<Config | (() => Config)>>,\n ) => {\n const plugin = pluginFactory(options, meta)\n if (!Array.isArray(plugin)) {\n return [plugin]\n }\n return plugin\n }\n\n const routerGenerator = getPlugin(unpluginRouterGeneratorFactory)\n const routerCodeSplitter = getPlugin(unpluginRouterCodeSplitterFactory)\n\n const result = [\n {\n name: 'tanstack:router-inline-css-defaults',\n vite: {\n config() {\n return {\n define: {\n ...INLINE_CSS_DEFAULT_DEFINES,\n },\n }\n },\n },\n webpack(compiler: WebpackCompiler) {\n applyWebpackInlineCssDefaultDefinePlugin(compiler)\n },\n rspack(compiler: RspackCompiler) {\n applyRspackInlineCssDefaultDefinePlugin(compiler)\n },\n esbuild: {\n config(options: EsbuildOptionsWithDefine) {\n options.define = {\n ...INLINE_CSS_DEFAULT_DEFINES,\n ...options.define,\n }\n },\n },\n },\n ...routerGenerator,\n ]\n if (userConfig.autoCodeSplitting) {\n result.push(...routerCodeSplitter)\n }\n\n const isProduction = process.env.NODE_ENV === 'production'\n\n if (!isProduction && !userConfig.autoCodeSplitting) {\n const routerHmr = getPlugin(unpluginRouterHmrFactory)\n result.push(...routerHmr)\n }\n return result\n}\n"],"mappings":";;;;;AAYA,IAAM,6BAA6B;CACjC,sCAAsC,KAAK,UAAU,QAAQ;CAC7D,0CAA0C,KAAK,UAAU,QAAQ;CAClE;AAMD,SAAS,yCAAyC,UAA2B;AAC3E,KAAI,SAAS,QAAQ,aAAa,2BAA2B,CAAC,MAAM,SAAS;;AAG/E,SAAS,wCAAwC,UAA0B;AACzE,KAAI,SAAS,QAAQ,aAAa,2BAA2B,CAAC,MAAM,SAAS;;AAG/E,IAAa,iCAER,UAAU,EAAE,EAAE,SAAS;CAC1B,MAAM,OAAe,QAAQ,KAAK;CAClC,MAAM,aAAa,UAChB,OAAO,YAAY,aAAa,SAAS,GAAG,SAC7C,KACD;CAED,MAAM,aACJ,kBACG;EACH,MAAM,SAAS,cAAc,SAAS,KAAK;AAC3C,MAAI,CAAC,MAAM,QAAQ,OAAO,CACxB,QAAO,CAAC,OAAO;AAEjB,SAAO;;CAGT,MAAM,kBAAkB,UAAU,+BAA+B;CACjE,MAAM,qBAAqB,UAAU,kCAAkC;CAEvE,MAAM,SAAS,CACb;EACE,MAAM;EACN,MAAM,EACJ,SAAS;AACP,UAAO,EACL,QAAQ,EACN,GAAG,4BACJ,EACF;KAEJ;EACD,QAAQ,UAA2B;AACjC,4CAAyC,SAAS;;EAEpD,OAAO,UAA0B;AAC/B,2CAAwC,SAAS;;EAEnD,SAAS,EACP,OAAO,SAAmC;AACxC,WAAQ,SAAS;IACf,GAAG;IACH,GAAG,QAAQ;IACZ;KAEJ;EACF,EACD,GAAG,gBACJ;AACD,KAAI,WAAW,kBACb,QAAO,KAAK,GAAG,mBAAmB;AAKpC,KAAI,EAAA,QAAA,IAAA,aAF0C,iBAEzB,CAAC,WAAW,mBAAmB;EAClD,MAAM,YAAY,UAAU,yBAAyB;AACrD,SAAO,KAAK,GAAG,UAAU;;AAE3B,QAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/router-plugin",
|
|
3
|
-
"version": "1.167.
|
|
3
|
+
"version": "1.167.25",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -99,8 +99,8 @@
|
|
|
99
99
|
"chokidar": "^3.6.0",
|
|
100
100
|
"unplugin": "^2.1.2",
|
|
101
101
|
"zod": "^3.24.2",
|
|
102
|
-
"@tanstack/router-core": "1.168.
|
|
103
|
-
"@tanstack/router-generator": "1.166.
|
|
102
|
+
"@tanstack/router-core": "1.168.16",
|
|
103
|
+
"@tanstack/router-generator": "1.166.34",
|
|
104
104
|
"@tanstack/router-utils": "1.161.7",
|
|
105
105
|
"@tanstack/virtual-file-routes": "1.161.7"
|
|
106
106
|
},
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"vite": ">=5.0.0 || >=6.0.0 || >=7.0.0 || >=8.0.0",
|
|
117
117
|
"vite-plugin-solid": "^2.11.10 || ^3.0.0-0",
|
|
118
118
|
"webpack": ">=5.92.0",
|
|
119
|
-
"@tanstack/react-router": "^1.168.
|
|
119
|
+
"@tanstack/react-router": "^1.168.24"
|
|
120
120
|
},
|
|
121
121
|
"peerDependenciesMeta": {
|
|
122
122
|
"@rsbuild/core": {
|
|
@@ -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
|
|
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
|
-
//
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
//
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -3,7 +3,29 @@ import { unpluginRouterGeneratorFactory } from './router-generator-plugin'
|
|
|
3
3
|
import { unpluginRouterCodeSplitterFactory } from './router-code-splitter-plugin'
|
|
4
4
|
import { unpluginRouterHmrFactory } from './router-hmr-plugin'
|
|
5
5
|
import type { Config } from './config'
|
|
6
|
-
import type {
|
|
6
|
+
import type {
|
|
7
|
+
RspackCompiler,
|
|
8
|
+
UnpluginFactory,
|
|
9
|
+
UnpluginOptions,
|
|
10
|
+
WebpackCompiler,
|
|
11
|
+
} from 'unplugin'
|
|
12
|
+
|
|
13
|
+
const INLINE_CSS_DEFAULT_DEFINES = {
|
|
14
|
+
'process.env.TSS_INLINE_CSS_ENABLED': JSON.stringify('false'),
|
|
15
|
+
'import.meta.env.TSS_INLINE_CSS_ENABLED': JSON.stringify('false'),
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type EsbuildOptionsWithDefine = Parameters<
|
|
19
|
+
NonNullable<NonNullable<UnpluginOptions['esbuild']>['config']>
|
|
20
|
+
>[0]
|
|
21
|
+
|
|
22
|
+
function applyWebpackInlineCssDefaultDefinePlugin(compiler: WebpackCompiler) {
|
|
23
|
+
new compiler.webpack.DefinePlugin(INLINE_CSS_DEFAULT_DEFINES).apply(compiler)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function applyRspackInlineCssDefaultDefinePlugin(compiler: RspackCompiler) {
|
|
27
|
+
new compiler.webpack.DefinePlugin(INLINE_CSS_DEFAULT_DEFINES).apply(compiler)
|
|
28
|
+
}
|
|
7
29
|
|
|
8
30
|
export const unpluginRouterComposedFactory: UnpluginFactory<
|
|
9
31
|
Partial<Config | (() => Config)> | undefined
|
|
@@ -27,7 +49,35 @@ export const unpluginRouterComposedFactory: UnpluginFactory<
|
|
|
27
49
|
const routerGenerator = getPlugin(unpluginRouterGeneratorFactory)
|
|
28
50
|
const routerCodeSplitter = getPlugin(unpluginRouterCodeSplitterFactory)
|
|
29
51
|
|
|
30
|
-
const result = [
|
|
52
|
+
const result = [
|
|
53
|
+
{
|
|
54
|
+
name: 'tanstack:router-inline-css-defaults',
|
|
55
|
+
vite: {
|
|
56
|
+
config() {
|
|
57
|
+
return {
|
|
58
|
+
define: {
|
|
59
|
+
...INLINE_CSS_DEFAULT_DEFINES,
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
webpack(compiler: WebpackCompiler) {
|
|
65
|
+
applyWebpackInlineCssDefaultDefinePlugin(compiler)
|
|
66
|
+
},
|
|
67
|
+
rspack(compiler: RspackCompiler) {
|
|
68
|
+
applyRspackInlineCssDefaultDefinePlugin(compiler)
|
|
69
|
+
},
|
|
70
|
+
esbuild: {
|
|
71
|
+
config(options: EsbuildOptionsWithDefine) {
|
|
72
|
+
options.define = {
|
|
73
|
+
...INLINE_CSS_DEFAULT_DEFINES,
|
|
74
|
+
...options.define,
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
...routerGenerator,
|
|
80
|
+
]
|
|
31
81
|
if (userConfig.autoCodeSplitting) {
|
|
32
82
|
result.push(...routerCodeSplitter)
|
|
33
83
|
}
|