@bleedingdev/modern-js-runtime 3.2.0-ultramodern.120 → 3.2.0-ultramodern.122

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.
Files changed (203) hide show
  1. package/dist/cjs/boundary-debugger/index.js +4 -0
  2. package/dist/cjs/cli/index.js +11 -0
  3. package/dist/cjs/{router/runtime/tanstack/rsc/ClientSlot.js → core/context/extensions.js} +33 -21
  4. package/dist/cjs/{router/runtime/tanstack/rsc/SlotContext.js → core/context/helmetContext.js} +16 -20
  5. package/dist/cjs/core/context/index.js +65 -0
  6. package/dist/cjs/core/react/wrapper.js +6 -4
  7. package/dist/cjs/core/server/helmet.js +2 -1
  8. package/dist/cjs/core/server/requestHandler.js +42 -29
  9. package/dist/cjs/core/server/routerCleanup.js +110 -0
  10. package/dist/cjs/core/server/scriptOrder.js +75 -4
  11. package/dist/cjs/core/server/stream/afterTemplate.js +6 -18
  12. package/dist/cjs/core/server/stream/deferredScript.js +4 -1
  13. package/dist/cjs/core/server/string/index.js +1 -7
  14. package/dist/cjs/core/server/string/loadable.js +13 -40
  15. package/dist/cjs/core/server/string/ssrData.js +1 -1
  16. package/dist/cjs/core/server/utils.js +31 -8
  17. package/dist/cjs/exports/head.js +135 -74
  18. package/dist/cjs/exports/tanstack-router.js +36 -305
  19. package/dist/cjs/module-federation/index.js +178 -0
  20. package/dist/cjs/router/cli/code/index.js +1 -47
  21. package/dist/cjs/router/cli/code/templates.js +1 -14
  22. package/dist/cjs/router/cli/handler.js +1 -1
  23. package/dist/cjs/router/cli/index.js +2 -23
  24. package/dist/cjs/router/runtime/DeferredDataScripts.node.js +16 -4
  25. package/dist/cjs/router/runtime/PrefetchLink.js +2 -3
  26. package/dist/cjs/router/runtime/internal.js +20 -13
  27. package/dist/cjs/router/runtime/lifecycle.js +37 -22
  28. package/dist/cjs/router/runtime/plugin.js +2 -9
  29. package/dist/cjs/router/runtime/plugin.node.js +2 -7
  30. package/dist/cjs/router/runtime/provider.js +107 -0
  31. package/dist/cjs/router/runtime/utils.js +35 -9
  32. package/dist/esm/boundary-debugger/index.mjs +4 -0
  33. package/dist/esm/cli/index.mjs +4 -2
  34. package/dist/esm/core/context/extensions.mjs +28 -0
  35. package/dist/esm/core/context/helmetContext.mjs +13 -0
  36. package/dist/esm/core/context/index.mjs +5 -0
  37. package/dist/esm/core/react/wrapper.mjs +6 -4
  38. package/dist/esm/core/server/helmet.mjs +2 -1
  39. package/dist/esm/core/server/requestHandler.mjs +43 -30
  40. package/dist/esm/core/server/routerCleanup.mjs +66 -0
  41. package/dist/esm/core/server/scriptOrder.mjs +60 -1
  42. package/dist/esm/core/server/stream/afterTemplate.mjs +8 -20
  43. package/dist/esm/core/server/stream/deferredScript.mjs +4 -1
  44. package/dist/esm/core/server/string/index.mjs +3 -9
  45. package/dist/esm/core/server/string/loadable.mjs +11 -38
  46. package/dist/esm/core/server/string/ssrData.mjs +2 -2
  47. package/dist/esm/core/server/utils.mjs +31 -8
  48. package/dist/esm/exports/head.mjs +135 -74
  49. package/dist/esm/exports/tanstack-router.mjs +30 -4
  50. package/dist/esm/module-federation/index.mjs +109 -0
  51. package/dist/esm/router/cli/code/index.mjs +1 -47
  52. package/dist/esm/router/cli/code/templates.mjs +1 -14
  53. package/dist/esm/router/cli/handler.mjs +1 -1
  54. package/dist/esm/router/cli/index.mjs +3 -24
  55. package/dist/esm/router/runtime/DeferredDataScripts.node.mjs +16 -4
  56. package/dist/esm/router/runtime/PrefetchLink.mjs +2 -3
  57. package/dist/esm/router/runtime/internal.mjs +16 -15
  58. package/dist/esm/router/runtime/lifecycle.mjs +22 -13
  59. package/dist/esm/router/runtime/plugin.mjs +4 -11
  60. package/dist/esm/router/runtime/plugin.node.mjs +4 -9
  61. package/dist/esm/router/runtime/provider.mjs +57 -0
  62. package/dist/esm/router/runtime/utils.mjs +35 -9
  63. package/dist/esm-node/boundary-debugger/index.mjs +4 -0
  64. package/dist/esm-node/cli/index.mjs +4 -2
  65. package/dist/esm-node/core/context/extensions.mjs +29 -0
  66. package/dist/esm-node/core/context/helmetContext.mjs +14 -0
  67. package/dist/esm-node/core/context/index.mjs +5 -0
  68. package/dist/esm-node/core/react/wrapper.mjs +6 -4
  69. package/dist/esm-node/core/server/helmet.mjs +2 -1
  70. package/dist/esm-node/core/server/requestHandler.mjs +43 -30
  71. package/dist/esm-node/core/server/routerCleanup.mjs +67 -0
  72. package/dist/esm-node/core/server/scriptOrder.mjs +60 -1
  73. package/dist/esm-node/core/server/stream/afterTemplate.mjs +8 -20
  74. package/dist/esm-node/core/server/stream/deferredScript.mjs +4 -1
  75. package/dist/esm-node/core/server/string/index.mjs +3 -9
  76. package/dist/esm-node/core/server/string/loadable.mjs +11 -38
  77. package/dist/esm-node/core/server/string/ssrData.mjs +2 -2
  78. package/dist/esm-node/core/server/utils.mjs +31 -8
  79. package/dist/esm-node/exports/head.mjs +135 -74
  80. package/dist/esm-node/exports/tanstack-router.mjs +30 -4
  81. package/dist/esm-node/module-federation/index.mjs +110 -0
  82. package/dist/esm-node/router/cli/code/index.mjs +1 -47
  83. package/dist/esm-node/router/cli/code/templates.mjs +1 -14
  84. package/dist/esm-node/router/cli/handler.mjs +1 -1
  85. package/dist/esm-node/router/cli/index.mjs +3 -24
  86. package/dist/esm-node/router/runtime/DeferredDataScripts.node.mjs +16 -4
  87. package/dist/esm-node/router/runtime/PrefetchLink.mjs +2 -3
  88. package/dist/esm-node/router/runtime/internal.mjs +16 -15
  89. package/dist/esm-node/router/runtime/lifecycle.mjs +22 -13
  90. package/dist/esm-node/router/runtime/plugin.mjs +4 -11
  91. package/dist/esm-node/router/runtime/plugin.node.mjs +4 -9
  92. package/dist/esm-node/router/runtime/provider.mjs +58 -0
  93. package/dist/esm-node/router/runtime/utils.mjs +35 -9
  94. package/dist/types/cli/index.d.ts +3 -1
  95. package/dist/types/core/context/extensions.d.ts +37 -0
  96. package/dist/types/core/context/helmetContext.d.ts +10 -0
  97. package/dist/types/core/context/index.d.ts +6 -0
  98. package/dist/types/core/context/runtime.d.ts +1 -11
  99. package/dist/types/core/server/routerCleanup.d.ts +28 -0
  100. package/dist/types/core/server/scriptOrder.d.ts +24 -0
  101. package/dist/types/core/server/string/loadable.d.ts +1 -7
  102. package/dist/types/core/server/utils.d.ts +1 -0
  103. package/dist/types/exports/tanstack-router.d.ts +88 -7
  104. package/dist/types/module-federation/index.d.ts +65 -0
  105. package/dist/types/router/cli/code/index.d.ts +1 -3
  106. package/dist/types/router/cli/handler.d.ts +0 -3
  107. package/dist/types/router/runtime/internal.d.ts +1 -0
  108. package/dist/types/router/runtime/lifecycle.d.ts +2 -0
  109. package/dist/types/router/runtime/plugin.d.ts +1 -1
  110. package/dist/types/router/runtime/plugin.node.d.ts +1 -1
  111. package/dist/types/router/runtime/provider.d.ts +61 -0
  112. package/package.json +16 -12
  113. package/rstest.config.mts +2 -4
  114. package/dist/cjs/router/cli/code/tanstackTypes.js +0 -447
  115. package/dist/cjs/router/runtime/tanstack/basepathRewrite.js +0 -66
  116. package/dist/cjs/router/runtime/tanstack/dataMutation.js +0 -349
  117. package/dist/cjs/router/runtime/tanstack/hydrationBoundary.js +0 -48
  118. package/dist/cjs/router/runtime/tanstack/outlet.js +0 -58
  119. package/dist/cjs/router/runtime/tanstack/plugin.js +0 -342
  120. package/dist/cjs/router/runtime/tanstack/plugin.node.js +0 -272
  121. package/dist/cjs/router/runtime/tanstack/prefetchLink.js +0 -59
  122. package/dist/cjs/router/runtime/tanstack/routeTree.js +0 -525
  123. package/dist/cjs/router/runtime/tanstack/rsc/CompositeComponent.js +0 -79
  124. package/dist/cjs/router/runtime/tanstack/rsc/ReplayableStream.js +0 -146
  125. package/dist/cjs/router/runtime/tanstack/rsc/RscNodeRenderer.js +0 -69
  126. package/dist/cjs/router/runtime/tanstack/rsc/client.js +0 -97
  127. package/dist/cjs/router/runtime/tanstack/rsc/createRscProxy.js +0 -145
  128. package/dist/cjs/router/runtime/tanstack/rsc/index.js +0 -46
  129. package/dist/cjs/router/runtime/tanstack/rsc/server.js +0 -250
  130. package/dist/cjs/router/runtime/tanstack/rsc/slotUsageSanitizer.js +0 -69
  131. package/dist/cjs/router/runtime/tanstack/rsc/symbols.js +0 -77
  132. package/dist/cjs/ssr/index.node.js +0 -125
  133. package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.after.js +0 -88
  134. package/dist/cjs/ssr/serverRender/renderToString/entry.js +0 -200
  135. package/dist/cjs/ssr/serverRender/types.js +0 -40
  136. package/dist/esm/router/cli/code/tanstackTypes.mjs +0 -396
  137. package/dist/esm/router/runtime/tanstack/basepathRewrite.mjs +0 -28
  138. package/dist/esm/router/runtime/tanstack/dataMutation.mjs +0 -305
  139. package/dist/esm/router/runtime/tanstack/hydrationBoundary.mjs +0 -10
  140. package/dist/esm/router/runtime/tanstack/outlet.mjs +0 -17
  141. package/dist/esm/router/runtime/tanstack/plugin.mjs +0 -304
  142. package/dist/esm/router/runtime/tanstack/plugin.node.mjs +0 -234
  143. package/dist/esm/router/runtime/tanstack/prefetchLink.mjs +0 -18
  144. package/dist/esm/router/runtime/tanstack/routeTree.mjs +0 -481
  145. package/dist/esm/router/runtime/tanstack/rsc/ClientSlot.mjs +0 -19
  146. package/dist/esm/router/runtime/tanstack/rsc/CompositeComponent.mjs +0 -41
  147. package/dist/esm/router/runtime/tanstack/rsc/ReplayableStream.mjs +0 -104
  148. package/dist/esm/router/runtime/tanstack/rsc/RscNodeRenderer.mjs +0 -31
  149. package/dist/esm/router/runtime/tanstack/rsc/SlotContext.mjs +0 -17
  150. package/dist/esm/router/runtime/tanstack/rsc/client.mjs +0 -53
  151. package/dist/esm/router/runtime/tanstack/rsc/createRscProxy.mjs +0 -107
  152. package/dist/esm/router/runtime/tanstack/rsc/index.mjs +0 -1
  153. package/dist/esm/router/runtime/tanstack/rsc/server.mjs +0 -200
  154. package/dist/esm/router/runtime/tanstack/rsc/slotUsageSanitizer.mjs +0 -31
  155. package/dist/esm/router/runtime/tanstack/rsc/symbols.mjs +0 -17
  156. package/dist/esm/ssr/index.node.mjs +0 -44
  157. package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.after.mjs +0 -50
  158. package/dist/esm/ssr/serverRender/renderToString/entry.mjs +0 -151
  159. package/dist/esm/ssr/serverRender/types.mjs +0 -1
  160. package/dist/esm-node/router/cli/code/tanstackTypes.mjs +0 -397
  161. package/dist/esm-node/router/runtime/tanstack/basepathRewrite.mjs +0 -29
  162. package/dist/esm-node/router/runtime/tanstack/dataMutation.mjs +0 -306
  163. package/dist/esm-node/router/runtime/tanstack/hydrationBoundary.mjs +0 -11
  164. package/dist/esm-node/router/runtime/tanstack/outlet.mjs +0 -18
  165. package/dist/esm-node/router/runtime/tanstack/plugin.mjs +0 -305
  166. package/dist/esm-node/router/runtime/tanstack/plugin.node.mjs +0 -235
  167. package/dist/esm-node/router/runtime/tanstack/prefetchLink.mjs +0 -19
  168. package/dist/esm-node/router/runtime/tanstack/routeTree.mjs +0 -482
  169. package/dist/esm-node/router/runtime/tanstack/rsc/ClientSlot.mjs +0 -20
  170. package/dist/esm-node/router/runtime/tanstack/rsc/CompositeComponent.mjs +0 -42
  171. package/dist/esm-node/router/runtime/tanstack/rsc/ReplayableStream.mjs +0 -105
  172. package/dist/esm-node/router/runtime/tanstack/rsc/RscNodeRenderer.mjs +0 -32
  173. package/dist/esm-node/router/runtime/tanstack/rsc/SlotContext.mjs +0 -18
  174. package/dist/esm-node/router/runtime/tanstack/rsc/client.mjs +0 -54
  175. package/dist/esm-node/router/runtime/tanstack/rsc/createRscProxy.mjs +0 -108
  176. package/dist/esm-node/router/runtime/tanstack/rsc/index.mjs +0 -2
  177. package/dist/esm-node/router/runtime/tanstack/rsc/server.mjs +0 -201
  178. package/dist/esm-node/router/runtime/tanstack/rsc/slotUsageSanitizer.mjs +0 -32
  179. package/dist/esm-node/router/runtime/tanstack/rsc/symbols.mjs +0 -18
  180. package/dist/esm-node/ssr/index.node.mjs +0 -45
  181. package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.after.mjs +0 -51
  182. package/dist/esm-node/ssr/serverRender/renderToString/entry.mjs +0 -152
  183. package/dist/esm-node/ssr/serverRender/types.mjs +0 -2
  184. package/dist/types/router/cli/code/tanstackTypes.d.ts +0 -10
  185. package/dist/types/router/runtime/tanstack/basepathRewrite.d.ts +0 -8
  186. package/dist/types/router/runtime/tanstack/dataMutation.d.ts +0 -29
  187. package/dist/types/router/runtime/tanstack/hydrationBoundary.d.ts +0 -2
  188. package/dist/types/router/runtime/tanstack/outlet.d.ts +0 -2
  189. package/dist/types/router/runtime/tanstack/plugin.d.ts +0 -6
  190. package/dist/types/router/runtime/tanstack/plugin.node.d.ts +0 -6
  191. package/dist/types/router/runtime/tanstack/prefetchLink.d.ts +0 -11
  192. package/dist/types/router/runtime/tanstack/routeTree.d.ts +0 -8
  193. package/dist/types/router/runtime/tanstack/rsc/ClientSlot.d.ts +0 -5
  194. package/dist/types/router/runtime/tanstack/rsc/CompositeComponent.d.ts +0 -3
  195. package/dist/types/router/runtime/tanstack/rsc/ReplayableStream.d.ts +0 -24
  196. package/dist/types/router/runtime/tanstack/rsc/RscNodeRenderer.d.ts +0 -5
  197. package/dist/types/router/runtime/tanstack/rsc/SlotContext.d.ts +0 -11
  198. package/dist/types/router/runtime/tanstack/rsc/client.d.ts +0 -11
  199. package/dist/types/router/runtime/tanstack/rsc/createRscProxy.d.ts +0 -7
  200. package/dist/types/router/runtime/tanstack/rsc/index.d.ts +0 -2
  201. package/dist/types/router/runtime/tanstack/rsc/server.d.ts +0 -14
  202. package/dist/types/router/runtime/tanstack/rsc/slotUsageSanitizer.d.ts +0 -2
  203. package/dist/types/router/runtime/tanstack/rsc/symbols.d.ts +0 -46
@@ -1,4 +1,7 @@
1
1
  import "node:module";
2
+ import { getRouterMatchedRouteIds } from "../../router/runtime/lifecycle.mjs";
3
+ import { CHUNK_JS_PLACEHOLDER } from "./constants.mjs";
4
+ import { safeReplace } from "./utils.mjs";
2
5
  function getScriptTags(template) {
3
6
  const scriptRegExp = /<script\b[^>]*\bsrc=(["'])(.*?)\1[^>]*><\/script>/g;
4
7
  return Array.from(template.matchAll(scriptRegExp)).map((match)=>({
@@ -16,6 +19,42 @@ function isEntryScript(src, entryName, asyncEntry) {
16
19
  const prefix = asyncEntry ? `async-${entryName}` : entryName;
17
20
  return basename === `${prefix}.js` || basename.startsWith(`${prefix}.`) || basename.startsWith(`${prefix}-`);
18
21
  }
22
+ const dedupeByUrl = (chunks)=>{
23
+ const seen = new Set();
24
+ return chunks.filter((chunk)=>{
25
+ if (void 0 === chunk.url || '' === chunk.url || seen.has(chunk.url)) return false;
26
+ seen.add(chunk.url);
27
+ return true;
28
+ });
29
+ };
30
+ const isAsyncEntryScriptChunk = (chunk, entryName)=>{
31
+ if (void 0 === chunk.url || !chunk.url.endsWith('.js')) return false;
32
+ const asyncEntryName = `async-${entryName}`;
33
+ const filename = chunk.filename ?? chunk.url;
34
+ const basename = filename.split('/').pop() ?? filename;
35
+ return basename === `${asyncEntryName}.js` || basename.startsWith(`${asyncEntryName}.`) || basename.startsWith(`${asyncEntryName}-`);
36
+ };
37
+ function getRouteAssets(runtimeContext, routeManifest = runtimeContext.routeManifest) {
38
+ return routeManifest?.routeAssets;
39
+ }
40
+ function getMatchedRouteAssets(runtimeContext, routeManifest) {
41
+ const routeAssets = getRouteAssets(runtimeContext, routeManifest);
42
+ if (void 0 === routeAssets) return [];
43
+ const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext) ?? [];
44
+ return matchedRouteIds.flatMap((routeId)=>routeAssets[routeId]?.assets ?? []);
45
+ }
46
+ const orderHydrationScriptChunks = ({ asyncEntryChunks, collectedChunks, matchedRouteChunks, entryName })=>{
47
+ const asyncEntryScriptChunks = [];
48
+ const asyncEntryDependencyChunks = [];
49
+ for (const chunk of asyncEntryChunks)if (isAsyncEntryScriptChunk(chunk, entryName)) asyncEntryScriptChunks.push(chunk);
50
+ else asyncEntryDependencyChunks.push(chunk);
51
+ return dedupeByUrl([
52
+ ...asyncEntryDependencyChunks,
53
+ ...collectedChunks,
54
+ ...matchedRouteChunks,
55
+ ...asyncEntryScriptChunks
56
+ ]);
57
+ };
19
58
  function injectBeforeHydrationEntryScript(template, scripts, entryName = 'index') {
20
59
  if ('' === scripts) return template;
21
60
  const scriptTags = getScriptTags(template);
@@ -23,4 +62,24 @@ function injectBeforeHydrationEntryScript(template, scripts, entryName = 'index'
23
62
  if (void 0 === target) return template;
24
63
  return `${template.slice(0, target.index)}${scripts}${template.slice(target.index)}`;
25
64
  }
26
- export { injectBeforeHydrationEntryScript };
65
+ function replaceChunkJsPlaceholder(template, scripts, entryName, placeholder = CHUNK_JS_PLACEHOLDER) {
66
+ if ('' === scripts) return safeReplace(template, placeholder, '');
67
+ const withoutPlaceholder = safeReplace(template, placeholder, '');
68
+ const withEarlyScripts = injectBeforeHydrationEntryScript(withoutPlaceholder, scripts, entryName);
69
+ if (withEarlyScripts !== withoutPlaceholder) return withEarlyScripts;
70
+ return safeReplace(template, placeholder, scripts);
71
+ }
72
+ function createRouteHydrationScriptTags(runtimeContext, entryName, options = {}) {
73
+ const { nonce, template } = options;
74
+ const routeAssets = getRouteAssets(runtimeContext);
75
+ if (void 0 === routeAssets) return '';
76
+ const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext) ?? [];
77
+ const assetEntries = [
78
+ ...matchedRouteIds.map((routeId)=>routeAssets[routeId]),
79
+ routeAssets[`async-${entryName}`]
80
+ ].filter((entry)=>void 0 !== entry);
81
+ const jsAssets = Array.from(new Set(assetEntries.flatMap((entry)=>(entry.assets ?? []).filter((asset)=>asset.endsWith('.js')))));
82
+ const nonceAttr = void 0 === nonce || '' === nonce ? '' : ` nonce="${nonce}"`;
83
+ return jsAssets.filter((asset)=>template?.includes(asset) !== true).map((asset)=>`<script src=${asset}${nonceAttr}></script>`).join(' ');
84
+ }
85
+ export { createRouteHydrationScriptTags, getMatchedRouteAssets, injectBeforeHydrationEntryScript, orderHydrationScriptChunks, replaceChunkJsPlaceholder };
@@ -1,9 +1,9 @@
1
1
  import "node:module";
2
2
  import { serializeJson } from "@modern-js/runtime-utils/node";
3
- import { getRouterHydrationScripts, getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
3
+ import { getRouterHydrationScripts } from "../../../router/runtime/lifecycle.mjs";
4
4
  import { SSR_DATA_JSON_ID } from "../../constants.mjs";
5
5
  import { SSR_DATA_PLACEHOLDER } from "../constants.mjs";
6
- import { injectBeforeHydrationEntryScript } from "../scriptOrder.mjs";
6
+ import { createRouteHydrationScriptTags, replaceChunkJsPlaceholder } from "../scriptOrder.mjs";
7
7
  import { buildHtml } from "../shared.mjs";
8
8
  import { attributesToString, safeReplace } from "../utils.mjs";
9
9
  function buildShellAfterTemplate(afterAppTemplate, options) {
@@ -20,24 +20,12 @@ function buildShellAfterTemplate(afterAppTemplate, options) {
20
20
  (template)=>injectJs(template, entryName, config.nonce)
21
21
  ];
22
22
  async function injectJs(template, entryName, nonce) {
23
- const { routeManifest } = runtimeContext;
24
- if (!routeManifest) return template;
25
- const { routeAssets } = routeManifest;
26
- if (!routeAssets) return template;
27
- const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext) ?? [];
28
- const assetEntries = [
29
- ...matchedRouteIds.map((routeId)=>routeAssets[routeId]),
30
- routeAssets[`async-${entryName}`]
31
- ].filter(Boolean);
32
- const jsAssets = Array.from(new Set(assetEntries.flatMap((entry)=>(entry.assets ?? []).filter((asset)=>asset.endsWith('.js')))));
33
- const nonceAttr = nonce ? ` nonce="${nonce}"` : '';
34
- const jsChunkStr = jsAssets.filter((asset)=>!template.includes(asset)).map((asset)=>`<script src=${asset}${nonceAttr}></script>`).join(' ');
35
- if (jsChunkStr) {
36
- const withoutPlaceholder = safeReplace(template, '<!--<?- chunksMap.js ?>-->', '');
37
- const withEarlyScripts = injectBeforeHydrationEntryScript(withoutPlaceholder, jsChunkStr, entryName);
38
- return withEarlyScripts !== withoutPlaceholder ? withEarlyScripts : safeReplace(template, '<!--<?- chunksMap.js ?>-->', jsChunkStr);
39
- }
40
- return template;
23
+ const jsChunkStr = createRouteHydrationScriptTags(runtimeContext, entryName, {
24
+ nonce,
25
+ template
26
+ });
27
+ if (!jsChunkStr) return template;
28
+ return replaceChunkJsPlaceholder(template, jsChunkStr, entryName);
41
29
  }
42
30
  return buildHtml(afterAppTemplate, callbacks);
43
31
  }
@@ -23,12 +23,15 @@ function isPromiseLike(value) {
23
23
  return !!value && 'function' == typeof value.then;
24
24
  }
25
25
  function toErrorInfo(error) {
26
+ if ('production' === process.env.NODE_ENV) return {
27
+ message: 'Unexpected Server Error'
28
+ };
26
29
  if (error && 'object' == typeof error) {
27
30
  const maybeMsg = error.message;
28
31
  const maybeStack = error.stack;
29
32
  return {
30
33
  message: 'string' == typeof maybeMsg ? maybeMsg : String(maybeMsg ?? error),
31
- stack: 'production' !== process.env.NODE_ENV ? maybeStack : void 0
34
+ stack: maybeStack
32
35
  };
33
36
  }
34
37
  return {
@@ -5,9 +5,9 @@ import server from "react-dom/server";
5
5
  import { RenderLevel } from "../../constants.mjs";
6
6
  import { getGlobalInternalRuntimeContext } from "../../context/index.mjs";
7
7
  import { wrapRuntimeContextProvider } from "../../react/wrapper.mjs";
8
- import { CHUNK_CSS_PLACEHOLDER, CHUNK_JS_PLACEHOLDER, HTML_PLACEHOLDER, SSR_DATA_PLACEHOLDER } from "../constants.mjs";
8
+ import { CHUNK_CSS_PLACEHOLDER, HTML_PLACEHOLDER, SSR_DATA_PLACEHOLDER } from "../constants.mjs";
9
9
  import { createReplaceHelemt, getHelmetData } from "../helmet.mjs";
10
- import { injectBeforeHydrationEntryScript } from "../scriptOrder.mjs";
10
+ import { replaceChunkJsPlaceholder } from "../scriptOrder.mjs";
11
11
  import { buildHtml } from "../shared.mjs";
12
12
  import { SSRErrors, SSRTimings } from "../tracer.mjs";
13
13
  import { getSSRConfigByEntry, safeReplace } from "../utils.mjs";
@@ -99,13 +99,7 @@ function createReplaceSSRDataScript(data) {
99
99
  return (template)=>safeReplace(template, SSR_DATA_PLACEHOLDER, data);
100
100
  }
101
101
  function createReplaceChunkJs(js, entryName) {
102
- return (template)=>{
103
- if (!js) return safeReplace(template, CHUNK_JS_PLACEHOLDER, '');
104
- const withoutPlaceholder = safeReplace(template, CHUNK_JS_PLACEHOLDER, '');
105
- const withEarlyScripts = injectBeforeHydrationEntryScript(withoutPlaceholder, js, entryName);
106
- if (withEarlyScripts !== withoutPlaceholder) return withEarlyScripts;
107
- return safeReplace(template, CHUNK_JS_PLACEHOLDER, js);
108
- };
102
+ return (template)=>replaceChunkJsPlaceholder(template, js, entryName);
109
103
  }
110
104
  function createReplaceChunkCss(css) {
111
105
  return (template)=>safeReplace(template, CHUNK_CSS_PLACEHOLDER, css);
@@ -1,7 +1,7 @@
1
1
  import "node:module";
2
2
  import { ChunkExtractor } from "@loadable/server";
3
- import { getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
4
3
  import { createFederatedCssLinks } from "../federatedCss.mjs";
4
+ import { getMatchedRouteAssets, orderHydrationScriptChunks } from "../scriptOrder.mjs";
5
5
  import { attributesToString, checkIsNode } from "../utils.mjs";
6
6
  import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
7
7
  import { dirname as __rspack_dirname } from "node:path";
@@ -11,33 +11,15 @@ const extname = (uri)=>{
11
11
  return `.${uri?.split('.').pop()}` || '';
12
12
  };
13
13
  const generateChunks = (chunks, ext)=>chunks.filter((chunk)=>Boolean(chunk.url)).filter((chunk)=>extname(chunk.url).slice(1) === ext);
14
- const dedupeChunksByUrl = (chunks)=>{
15
- const seen = new Set();
16
- return chunks.filter((chunk)=>{
17
- if (!chunk.url || seen.has(chunk.url)) return false;
18
- seen.add(chunk.url);
19
- return true;
14
+ const routeAssetToChunk = (asset)=>({
15
+ chunk: asset,
16
+ filename: asset.replace(/^\//, ''),
17
+ linkType: 'preload',
18
+ path: asset,
19
+ scriptType: asset.endsWith('.css') ? 'style' : "script",
20
+ type: 'routeAsset',
21
+ url: asset
20
22
  });
21
- };
22
- const isAsyncEntryScriptChunk = (chunk, entryName)=>{
23
- if (!chunk.url?.endsWith('.js')) return false;
24
- const asyncEntryName = `async-${entryName}`;
25
- const filename = chunk.filename || chunk.url;
26
- const basename = filename.split('/').pop() || filename;
27
- return basename === `${asyncEntryName}.js` || basename.startsWith(`${asyncEntryName}.`) || basename.startsWith(`${asyncEntryName}-`);
28
- };
29
- const orderHydrationScriptChunks = ({ asyncEntryChunks, collectedChunks, matchedRouteChunks, entryName })=>{
30
- const asyncEntryScriptChunks = [];
31
- const asyncEntryDependencyChunks = [];
32
- for (const chunk of asyncEntryChunks)if (isAsyncEntryScriptChunk(chunk, entryName)) asyncEntryScriptChunks.push(chunk);
33
- else asyncEntryDependencyChunks.push(chunk);
34
- return dedupeChunksByUrl([
35
- ...asyncEntryDependencyChunks,
36
- ...collectedChunks,
37
- ...matchedRouteChunks,
38
- ...asyncEntryScriptChunks
39
- ]);
40
- };
41
23
  const checkIsInline = (chunk, enableInline)=>{
42
24
  if ('production' !== process.env.NODE_ENV) return false;
43
25
  if (enableInline instanceof RegExp) return enableInline.test(chunk.url);
@@ -56,17 +38,8 @@ class LoadableCollector {
56
38
  }
57
39
  getMatchedRouteChunks() {
58
40
  const { routeManifest, runtimeContext } = this.options;
59
- const routeAssets = routeManifest?.routeAssets;
60
- if (!routeAssets) return [];
61
- const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext) ?? [];
62
- return matchedRouteIds.flatMap((routeId)=>{
63
- const routeAsset = routeAssets[routeId];
64
- return (routeAsset?.assets ?? []).map((asset)=>({
65
- filename: asset.replace(/^\//, ''),
66
- path: asset,
67
- url: asset
68
- }));
69
- });
41
+ if (!routeManifest) return [];
42
+ return getMatchedRouteAssets(runtimeContext, routeManifest).map(routeAssetToChunk);
70
43
  }
71
44
  collect(comopnent) {
72
45
  const { stats, entryName } = this.options;
@@ -1,6 +1,6 @@
1
1
  import "node:module";
2
2
  import { serializeJson } from "@modern-js/runtime-utils/node";
3
- import { getRouterHydrationScripts } from "../../../router/runtime/lifecycle.mjs";
3
+ import { getRouterHydrationScripts, getRouterServerSnapshot } from "../../../router/runtime/lifecycle.mjs";
4
4
  import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../../constants.mjs";
5
5
  import { attributesToString, serializeErrors } from "../utils.mjs";
6
6
  function _check_private_redeclaration(obj, privateCollection) {
@@ -90,7 +90,7 @@ function getSSRData() {
90
90
  }
91
91
  function getRouterData() {
92
92
  const { routerContext, runtimeContext } = _class_private_field_get(this, _options);
93
- const snapshotRouterData = runtimeContext.routerServerSnapshot?.routerData;
93
+ const snapshotRouterData = getRouterServerSnapshot(runtimeContext)?.routerData;
94
94
  if (snapshotRouterData) return {
95
95
  loaderData: snapshotRouterData.loaderData,
96
96
  errors: serializeErrors(snapshotRouterData.errors || null)
@@ -13,17 +13,40 @@ function serializeErrors(errors) {
13
13
  if (!errors) return null;
14
14
  const entries = Object.entries(errors);
15
15
  const serialized = {};
16
- for (const [key, val] of entries)if (isRouteErrorResponse(val)) serialized[key] = {
17
- ...val,
18
- __type: 'RouteErrorResponse'
16
+ for (const [key, val] of entries)if (isRouteErrorResponse(val)) serialized[key] = serializeRouteErrorResponse(val);
17
+ else if (val instanceof Error) serialized[key] = serializeError(val);
18
+ else serialized[key] = val;
19
+ return serialized;
20
+ }
21
+ function shouldRedactServerError() {
22
+ return 'development' !== process.env.NODE_ENV && 'test' !== process.env.NODE_ENV;
23
+ }
24
+ function serializeError(error) {
25
+ if (shouldRedactServerError()) return {
26
+ message: 'Unexpected Server Error',
27
+ stack: void 0,
28
+ __type: 'Error'
19
29
  };
20
- else if (val instanceof Error) serialized[key] = {
21
- message: val.message,
22
- stack: val.stack,
30
+ return {
31
+ message: error.message,
32
+ stack: error.stack,
23
33
  __type: 'Error'
24
34
  };
25
- else serialized[key] = val;
26
- return serialized;
35
+ }
36
+ function serializeRouteErrorResponse(error) {
37
+ if (!isRouteErrorResponse(error)) return error;
38
+ if (error.status >= 500 && shouldRedactServerError()) return {
39
+ status: error.status,
40
+ statusText: 'Internal Server Error',
41
+ data: 'Unexpected Server Error',
42
+ __type: 'RouteErrorResponse'
43
+ };
44
+ return {
45
+ status: error.status,
46
+ statusText: error.statusText,
47
+ data: error.data,
48
+ __type: 'RouteErrorResponse'
49
+ };
27
50
  }
28
51
  function getSSRConfigByEntry(entryName, ssr, ssrByEntries) {
29
52
  if (ssrByEntries?.[entryName]) return ssrByEntries[entryName];
@@ -3,6 +3,7 @@ import "node:module";
3
3
  import react from "react";
4
4
  import { Helmet, HelmetData, HelmetProvider } from "react-helmet-async";
5
5
  import { InternalRuntimeContext } from "../core/context/index.mjs";
6
+ import { ensureHelmetContext } from "../core/context/helmetContext.mjs";
6
7
  const ATTRIBUTE_NAME_MAP = {
7
8
  charSet: 'charset',
8
9
  className: 'class',
@@ -12,6 +13,10 @@ const ATTRIBUTE_NAME_MAP = {
12
13
  itemProp: 'itemprop',
13
14
  tabIndex: 'tabindex'
14
15
  };
16
+ const CONTENT_PROPERTIES = new Set([
17
+ 'innerHTML',
18
+ 'cssText'
19
+ ]);
15
20
  const escapeHtml = (value)=>String(value).replaceAll('&', '&amp;').replaceAll('"', '&quot;').replaceAll('<', '&lt;').replaceAll('>', '&gt;');
16
21
  const toHtmlAttributeName = (name)=>ATTRIBUTE_NAME_MAP[name] ?? name;
17
22
  const attributesToString = (attributes, includeHelmetAttribute = false)=>{
@@ -19,6 +24,7 @@ const attributesToString = (attributes, includeHelmetAttribute = false)=>{
19
24
  if (includeHelmetAttribute) pairs.push('data-rh="true"');
20
25
  for (const [name, value] of Object.entries(attributes ?? {})){
21
26
  if (false === value || null == value) continue;
27
+ if (CONTENT_PROPERTIES.has(name)) continue;
22
28
  const htmlName = toHtmlAttributeName(name);
23
29
  if (true === value) pairs.push(htmlName);
24
30
  else pairs.push(`${htmlName}="${escapeHtml(value)}"`);
@@ -47,18 +53,6 @@ const createTitleDatum = (title, attributes)=>({
47
53
  return `<title ${attrs}>${escapeHtml(title)}</title>`;
48
54
  }
49
55
  });
50
- const createEmptyHelmetState = ()=>({
51
- base: createDatum('base', []),
52
- bodyAttributes: createAttributeDatum({}),
53
- htmlAttributes: createAttributeDatum({}),
54
- link: createDatum('link', []),
55
- meta: createDatum('meta', []),
56
- noscript: createDatum("noscript", []),
57
- priority: createDatum('meta', []),
58
- script: createDatum("script", []),
59
- style: createDatum('style', []),
60
- title: createTitleDatum(void 0, {})
61
- });
62
56
  const normalizeHelmetTitle = (title)=>{
63
57
  if ('string' == typeof title) return title;
64
58
  if (Array.isArray(title)) return title.map((part)=>String(part)).join('');
@@ -78,7 +72,14 @@ const collectChildren = (children, draft)=>{
78
72
  draft.titleAttributes = mergeAttributes(draft.titleAttributes, props);
79
73
  return;
80
74
  }
81
- if ('html' === child.type || 'body' === child.type) return;
75
+ if ('html' === child.type) {
76
+ draft.htmlAttributes = mergeAttributes(draft.htmlAttributes ?? {}, props);
77
+ return;
78
+ }
79
+ if ('body' === child.type) {
80
+ draft.bodyAttributes = mergeAttributes(draft.bodyAttributes ?? {}, props);
81
+ return;
82
+ }
82
83
  if ('base' === child.type || 'link' === child.type || 'meta' === child.type || "noscript" === child.type || "script" === child.type || 'style' === child.type) {
83
84
  const tag = {
84
85
  ...props
@@ -88,8 +89,7 @@ const collectChildren = (children, draft)=>{
88
89
  }
89
90
  });
90
91
  };
91
- const collectHelmetProps = (current, props)=>{
92
- const baseState = current ?? createEmptyHelmetState();
92
+ const createHelmetRecord = (props)=>{
93
93
  const draft = {
94
94
  base: [
95
95
  ...void 0 !== props.base ? [
@@ -117,71 +117,132 @@ const collectHelmetProps = (current, props)=>{
117
117
  titleAttributes: props.titleAttributes ?? {}
118
118
  };
119
119
  collectChildren(props.children, draft);
120
- const title = void 0 !== draft.title && '' !== draft.title && void 0 !== props.titleTemplate ? props.titleTemplate.replaceAll('%s', draft.title) : draft.title ?? props.defaultTitle;
121
120
  return {
122
- base: createDatum('base', [
123
- ...baseState.__baseTags ?? [],
124
- ...draft.base
125
- ]),
126
- bodyAttributes: createAttributeDatum(mergeAttributes(baseState.__bodyAttributes ?? {}, draft.bodyAttributes)),
127
- htmlAttributes: createAttributeDatum(mergeAttributes(baseState.__htmlAttributes ?? {}, draft.htmlAttributes)),
128
- link: createDatum('link', [
129
- ...baseState.__linkTags ?? [],
130
- ...draft.link
131
- ]),
132
- meta: createDatum('meta', [
133
- ...baseState.__metaTags ?? [],
134
- ...draft.meta
135
- ]),
136
- noscript: createDatum("noscript", [
137
- ...baseState.__noscriptTags ?? [],
138
- ...draft.noscript
139
- ]),
140
- priority: createDatum('meta', []),
141
- script: createDatum("script", [
142
- ...baseState.__scriptTags ?? [],
143
- ...draft.script
144
- ]),
145
- style: createDatum('style', [
146
- ...baseState.__styleTags ?? [],
147
- ...draft.style
148
- ]),
149
- title: createTitleDatum(title ?? baseState.__title, mergeAttributes(baseState.__titleAttributes ?? {}, draft.titleAttributes)),
150
- __baseTags: [
151
- ...baseState.__baseTags ?? [],
152
- ...draft.base
153
- ],
154
- __bodyAttributes: mergeAttributes(baseState.__bodyAttributes ?? {}, draft.bodyAttributes),
155
- __htmlAttributes: mergeAttributes(baseState.__htmlAttributes ?? {}, draft.htmlAttributes),
156
- __linkTags: [
157
- ...baseState.__linkTags ?? [],
158
- ...draft.link
159
- ],
160
- __metaTags: [
161
- ...baseState.__metaTags ?? [],
162
- ...draft.meta
163
- ],
164
- __noscriptTags: [
165
- ...baseState.__noscriptTags ?? [],
166
- ...draft.noscript
167
- ],
168
- __scriptTags: [
169
- ...baseState.__scriptTags ?? [],
170
- ...draft.script
171
- ],
172
- __styleTags: [
173
- ...baseState.__styleTags ?? [],
174
- ...draft.style
175
- ],
176
- __title: title ?? baseState.__title,
177
- __titleAttributes: mergeAttributes(baseState.__titleAttributes ?? {}, draft.titleAttributes)
121
+ ...draft,
122
+ titleTemplate: props.titleTemplate,
123
+ defaultTitle: props.defaultTitle
124
+ };
125
+ };
126
+ const getInnermostDefined = (records, pick)=>{
127
+ for(let i = records.length - 1; i >= 0; i -= 1){
128
+ const value = pick(records[i]);
129
+ if (void 0 !== value) return value;
130
+ }
131
+ };
132
+ const deriveTitle = (records)=>{
133
+ const innermostTitle = getInnermostDefined(records, (record)=>record.title);
134
+ const innermostTemplate = getInnermostDefined(records, (record)=>record.titleTemplate);
135
+ if (innermostTemplate && innermostTitle) return innermostTemplate.replaceAll('%s', innermostTitle);
136
+ return innermostTitle || getInnermostDefined(records, (record)=>record.defaultTitle);
137
+ };
138
+ const mergeRecordAttributes = (records, pick)=>records.reduce((merged, record)=>mergeAttributes(merged, pick(record)), {});
139
+ const deriveBaseTags = (records)=>{
140
+ for(let i = records.length - 1; i >= 0; i -= 1){
141
+ const tags = records[i].base;
142
+ for(let j = tags.length - 1; j >= 0; j -= 1)if (tags[j].href) return [
143
+ tags[j]
144
+ ];
145
+ }
146
+ return [];
147
+ };
148
+ const TAG_PRIMARY_ATTRIBUTES = {
149
+ link: [
150
+ 'rel',
151
+ 'href'
152
+ ],
153
+ meta: [
154
+ 'name',
155
+ 'charset',
156
+ 'http-equiv',
157
+ 'property',
158
+ 'itemprop'
159
+ ],
160
+ noscript: [
161
+ 'innerHTML'
162
+ ],
163
+ script: [
164
+ 'src',
165
+ 'innerHTML'
166
+ ],
167
+ style: [
168
+ 'cssText'
169
+ ]
170
+ };
171
+ const getPrimaryAttribute = (tagName, tag)=>{
172
+ const candidates = TAG_PRIMARY_ATTRIBUTES[tagName];
173
+ let selectedKey;
174
+ let selectedValue;
175
+ for (const [key, value] of Object.entries(tag)){
176
+ const normalizedKey = CONTENT_PROPERTIES.has(key) ? key : toHtmlAttributeName(key).toLowerCase();
177
+ if (candidates.includes(normalizedKey)) {
178
+ if ('rel' !== selectedKey || 'canonical' !== String(selectedValue).toLowerCase()) {
179
+ if ('rel' !== normalizedKey || 'stylesheet' !== String(value).toLowerCase()) {
180
+ selectedKey = normalizedKey;
181
+ selectedValue = value;
182
+ }
183
+ }
184
+ }
185
+ }
186
+ if (void 0 === selectedKey || !selectedValue) return;
187
+ return {
188
+ key: selectedKey,
189
+ value: String(selectedValue).toLowerCase()
178
190
  };
179
191
  };
192
+ const dedupeTags = (tagName, records)=>{
193
+ const approvedValues = new Map();
194
+ const approved = [];
195
+ for(let i = records.length - 1; i >= 0; i -= 1){
196
+ const instanceValues = new Map();
197
+ const kept = [];
198
+ for (const tag of records[i][tagName]){
199
+ const primary = getPrimaryAttribute(tagName, tag);
200
+ if (void 0 === primary) continue;
201
+ if (approvedValues.get(primary.key)?.has(primary.value)) continue;
202
+ let seen = instanceValues.get(primary.key);
203
+ if (void 0 === seen) {
204
+ seen = new Set();
205
+ instanceValues.set(primary.key, seen);
206
+ }
207
+ seen.add(primary.value);
208
+ kept.push(tag);
209
+ }
210
+ approved.unshift(...kept);
211
+ for (const [key, values] of instanceValues){
212
+ const target = approvedValues.get(key);
213
+ if (void 0 === target) approvedValues.set(key, values);
214
+ else for (const value of values)target.add(value);
215
+ }
216
+ }
217
+ return approved;
218
+ };
219
+ const deriveHelmetServerState = (records)=>({
220
+ base: createDatum('base', deriveBaseTags(records)),
221
+ bodyAttributes: createAttributeDatum(mergeRecordAttributes(records, (record)=>record.bodyAttributes)),
222
+ htmlAttributes: createAttributeDatum(mergeRecordAttributes(records, (record)=>record.htmlAttributes)),
223
+ link: createDatum('link', dedupeTags('link', records)),
224
+ meta: createDatum('meta', dedupeTags('meta', records)),
225
+ noscript: createDatum("noscript", dedupeTags("noscript", records)),
226
+ priority: createDatum('meta', []),
227
+ script: createDatum("script", dedupeTags("script", records)),
228
+ style: createDatum('style', dedupeTags('style', records)),
229
+ title: createTitleDatum(deriveTitle(records), mergeRecordAttributes(records, (record)=>record.titleAttributes))
230
+ });
231
+ const serverHelmetRecords = new WeakMap();
232
+ const collectServerHelmet = (runtimeContext, props)=>{
233
+ const helmetContext = ensureHelmetContext(runtimeContext);
234
+ let records = serverHelmetRecords.get(helmetContext);
235
+ if (void 0 === records) {
236
+ records = [];
237
+ serverHelmetRecords.set(helmetContext, records);
238
+ }
239
+ records.push(createHelmetRecord(props));
240
+ helmetContext.helmet = deriveHelmetServerState(records);
241
+ };
180
242
  const head_Helmet = (props)=>{
181
243
  const runtimeContext = react.useContext(InternalRuntimeContext);
182
244
  if (null !== runtimeContext && false === runtimeContext.isBrowser) {
183
- runtimeContext._helmetContext ??= {};
184
- runtimeContext._helmetContext.helmet = collectHelmetProps(runtimeContext._helmetContext.helmet ?? void 0, props);
245
+ collectServerHelmet(runtimeContext, props);
185
246
  return null;
186
247
  }
187
248
  return react.createElement(Helmet, props);
@@ -1,5 +1,31 @@
1
1
  import "node:module";
2
- export { Asset, Await, Block, CatchBoundary, CatchNotFound, ClientOnly, DEFAULT_PROTOCOL_ALLOWLIST, DefaultGlobalNotFound, ErrorComponent, FileRoute, FileRouteLoader, HeadContent, LazyRoute, Match, MatchRoute, Matches, Navigate, NotFoundRoute, RootRoute, Route, RouteApi, Router, RouterContextProvider, RouterProvider, ScriptOnce, Scripts, ScrollRestoration, SearchParamError, cleanPath, composeRewrites, createBrowserHistory, createControlledPromise, createFileRoute, createHashHistory, createHistory, createLazyFileRoute, createLazyRoute, createLink, createMemoryHistory, createRootRoute, createRootRouteWithContext, createRoute, createRouteMask, createRouter, createRouterConfig, createSerializationAdapter, deepEqual, defaultParseSearch, defaultStringifySearch, defer, functionalUpdate, getRouteApi, interpolatePath, isMatch, isNotFound, isPlainArray, isPlainObject, isRedirect, joinPaths, lazyFn, lazyRouteComponent, linkOptions, notFound, parseSearchWith, reactUse, redirect, replaceEqualDeep, resolvePath, retainSearchParams, rootRouteId, rootRouteWithContext, stringifySearchWith, stripSearchParams, trimPath, trimPathLeft, trimPathRight, useAwaited, useBlocker, useCanGoBack, useChildMatches, useElementScrollRestoration, useHydrated, useLayoutEffect, useLinkProps, useLoaderData, useLoaderDeps, useLocation, useMatch, useMatchRoute, useMatches, useNavigate, useParams, useParentMatches, useRouteContext, useRouter, useRouterState, useSearch, useTags } from "@tanstack/react-router";
3
- export { Form, RouteActionResponseError, useFetcher } from "../router/runtime/tanstack/dataMutation.mjs";
4
- export { Outlet } from "../router/runtime/tanstack/outlet.mjs";
5
- export { Link, NavLink } from "../router/runtime/tanstack/prefetchLink.mjs";
2
+ import { createElement } from "react";
3
+ const COMPAT_BINDINGS_SLOT = Symbol.for('@modern-js/plugin-tanstack:runtime-compat-bindings');
4
+ function readCompatBindings() {
5
+ return globalThis[COMPAT_BINDINGS_SLOT];
6
+ }
7
+ function resolveCompatBindings(exportName) {
8
+ const bindings = readCompatBindings();
9
+ if (void 0 === bindings) throw new Error(`[@modern-js/runtime] '${exportName}' from the deprecated '@modern-js/runtime/tanstack-router' alias is provided by @modern-js/plugin-tanstack. Install @modern-js/plugin-tanstack, add \`tanstackRouterPlugin()\` to the \`plugins\` array in modern.config.ts, and make sure '@modern-js/plugin-tanstack/runtime' is imported (e.g. in modern.runtime.ts) before '${exportName}' is used. Prefer importing '${exportName}' from '@modern-js/plugin-tanstack/runtime' directly.`);
10
+ return bindings;
11
+ }
12
+ const Link = (props)=>createElement(resolveCompatBindings('Link').Link, props);
13
+ const NavLink = (props)=>createElement(resolveCompatBindings('NavLink').NavLink, props);
14
+ const Outlet = ()=>createElement(resolveCompatBindings('Outlet').Outlet);
15
+ const Form = (props)=>createElement(resolveCompatBindings('Form').Form, props);
16
+ function useFetcher() {
17
+ return resolveCompatBindings('useFetcher').useFetcher();
18
+ }
19
+ function RouteActionResponseErrorPlaceholder() {}
20
+ const RouteActionResponseError = new Proxy(RouteActionResponseErrorPlaceholder, {
21
+ construct (_target, args) {
22
+ const RealError = resolveCompatBindings('RouteActionResponseError').RouteActionResponseError;
23
+ return new RealError(...args);
24
+ },
25
+ get (target, property, receiver) {
26
+ const RealError = readCompatBindings()?.RouteActionResponseError;
27
+ if (void 0 !== RealError) return Reflect.get(RealError, property);
28
+ return Reflect.get(target, property, receiver);
29
+ }
30
+ });
31
+ export { Form, Link, NavLink, Outlet, RouteActionResponseError, useFetcher };