@bleedingdev/modern-js-runtime 3.2.0-ultramodern.99 → 3.4.0-ultramodern.1

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 (322) hide show
  1. package/dist/cjs/boundary-debugger/index.js +19 -11
  2. package/dist/cjs/cache/index.js +9 -5
  3. package/dist/cjs/cli/alias.js +9 -5
  4. package/dist/cjs/cli/code.js +9 -5
  5. package/dist/cjs/cli/constants.js +20 -16
  6. package/dist/cjs/cli/entry.js +9 -5
  7. package/dist/cjs/cli/index.js +20 -5
  8. package/dist/cjs/cli/ssr/index.js +9 -5
  9. package/dist/cjs/cli/ssr/loadable-bundler-plugin.js +9 -5
  10. package/dist/cjs/cli/ssr/mode.js +12 -8
  11. package/dist/cjs/cli/template.js +9 -5
  12. package/dist/cjs/cli/template.server.js +9 -5
  13. package/dist/cjs/common.js +14 -10
  14. package/dist/cjs/core/browser/hydrate.js +9 -5
  15. package/dist/cjs/core/browser/index.js +9 -5
  16. package/dist/cjs/core/browser/withCallback.js +9 -5
  17. package/dist/cjs/core/compat/hooks.js +14 -10
  18. package/dist/cjs/core/compat/index.js +9 -5
  19. package/dist/cjs/core/compat/requestContext.js +13 -9
  20. package/dist/cjs/core/config.js +12 -8
  21. package/dist/cjs/core/constants.js +15 -10
  22. package/dist/cjs/core/context/extensions.js +69 -0
  23. package/dist/cjs/core/context/helmetContext.js +54 -0
  24. package/dist/cjs/core/context/index.js +74 -5
  25. package/dist/cjs/core/context/monitors/default.js +12 -8
  26. package/dist/cjs/core/context/monitors/index.js +9 -5
  27. package/dist/cjs/core/context/monitors/index.server.js +9 -5
  28. package/dist/cjs/core/context/request/index.js +12 -8
  29. package/dist/cjs/core/context/request/index.server.js +9 -5
  30. package/dist/cjs/core/context/response/index.js +15 -11
  31. package/dist/cjs/core/context/response/index.server.js +9 -5
  32. package/dist/cjs/core/context/runtime.js +9 -5
  33. package/dist/cjs/core/context/serverPayload/index.js +13 -9
  34. package/dist/cjs/core/context/serverPayload/index.server.js +9 -5
  35. package/dist/cjs/core/index.js +9 -5
  36. package/dist/cjs/core/plugin/index.js +9 -5
  37. package/dist/cjs/core/react/index.js +9 -5
  38. package/dist/cjs/core/react/wrapper.js +15 -9
  39. package/dist/cjs/core/server/constants.js +15 -11
  40. package/dist/cjs/core/server/federatedCss.js +11 -7
  41. package/dist/cjs/core/server/helmet.js +11 -6
  42. package/dist/cjs/core/server/index.js +9 -5
  43. package/dist/cjs/core/server/react/index.js +9 -5
  44. package/dist/cjs/core/server/react/no-ssr-cache/index.js +9 -5
  45. package/dist/cjs/core/server/react/nossr/index.js +9 -5
  46. package/dist/cjs/core/server/requestHandler.js +51 -34
  47. package/dist/cjs/core/server/routerCleanup.js +110 -0
  48. package/dist/cjs/core/server/scriptOrder.js +84 -9
  49. package/dist/cjs/core/server/server.js +9 -5
  50. package/dist/cjs/core/server/shared.js +12 -8
  51. package/dist/cjs/core/server/stream/afterTemplate.js +15 -23
  52. package/dist/cjs/core/server/stream/beforeTemplate.js +11 -7
  53. package/dist/cjs/core/server/stream/beforeTemplate.worker.js +10 -6
  54. package/dist/cjs/core/server/stream/createReadableStream.js +16 -10
  55. package/dist/cjs/core/server/stream/createReadableStream.worker.js +15 -7
  56. package/dist/cjs/core/server/stream/deferredScript.js +13 -6
  57. package/dist/cjs/core/server/stream/index.js +9 -5
  58. package/dist/cjs/core/server/stream/shared.js +9 -5
  59. package/dist/cjs/core/server/stream/template.js +9 -5
  60. package/dist/cjs/core/server/string/index.js +10 -12
  61. package/dist/cjs/core/server/string/loadable.js +24 -54
  62. package/dist/cjs/core/server/string/ssrData.js +10 -6
  63. package/dist/cjs/core/server/tracer.js +13 -9
  64. package/dist/cjs/core/server/utils.js +63 -13
  65. package/dist/cjs/document/Body.js +9 -5
  66. package/dist/cjs/document/Comment.js +9 -5
  67. package/dist/cjs/document/DocumentContext.js +9 -5
  68. package/dist/cjs/document/DocumentStructureContext.js +9 -5
  69. package/dist/cjs/document/Head.js +9 -5
  70. package/dist/cjs/document/Html.js +9 -5
  71. package/dist/cjs/document/Links.js +9 -5
  72. package/dist/cjs/document/Root.js +9 -5
  73. package/dist/cjs/document/Script.js +9 -5
  74. package/dist/cjs/document/Scripts.js +9 -5
  75. package/dist/cjs/document/Style.js +9 -5
  76. package/dist/cjs/document/Title.js +9 -5
  77. package/dist/cjs/document/cli/index.js +14 -11
  78. package/dist/cjs/document/constants.js +9 -5
  79. package/dist/cjs/document/index.js +9 -5
  80. package/dist/cjs/exports/config-routes.js +12 -8
  81. package/dist/cjs/exports/head.js +153 -83
  82. package/dist/cjs/exports/loadable.js +27 -18
  83. package/dist/cjs/exports/tanstack-router.js +50 -58
  84. package/dist/cjs/index.js +9 -5
  85. package/dist/cjs/internal.js +9 -5
  86. package/dist/cjs/module-federation/index.js +178 -0
  87. package/dist/cjs/react-server.js +9 -5
  88. package/dist/cjs/router/cli/code/getClientRoutes/getRoutes.js +9 -5
  89. package/dist/cjs/router/cli/code/getClientRoutes/index.js +9 -5
  90. package/dist/cjs/router/cli/code/getClientRoutes/utils.js +9 -5
  91. package/dist/cjs/router/cli/code/index.js +16 -52
  92. package/dist/cjs/router/cli/code/inspect.js +9 -5
  93. package/dist/cjs/router/cli/code/makeLegalIdentifier.js +12 -8
  94. package/dist/cjs/router/cli/code/nestedRoutes.js +9 -5
  95. package/dist/cjs/router/cli/code/templates.js +10 -19
  96. package/dist/cjs/router/cli/code/utils.js +9 -5
  97. package/dist/cjs/router/cli/config-routes/converter.js +9 -5
  98. package/dist/cjs/router/cli/config-routes/parseRouteConfig.js +9 -5
  99. package/dist/cjs/router/cli/constants.js +23 -19
  100. package/dist/cjs/router/cli/entry.js +9 -5
  101. package/dist/cjs/router/cli/handler.js +10 -6
  102. package/dist/cjs/router/cli/index.js +11 -29
  103. package/dist/cjs/router/index.js +9 -5
  104. package/dist/cjs/router/internal.js +12 -8
  105. package/dist/cjs/router/runtime/CSSLinks.js +9 -5
  106. package/dist/cjs/router/runtime/DefaultNotFound.js +9 -5
  107. package/dist/cjs/router/runtime/DeferredDataScripts.js +12 -8
  108. package/dist/cjs/router/runtime/DeferredDataScripts.node.js +25 -9
  109. package/dist/cjs/router/runtime/PrefetchLink.js +161 -26
  110. package/dist/cjs/router/runtime/constants.js +9 -5
  111. package/dist/cjs/router/runtime/hooks.js +9 -5
  112. package/dist/cjs/router/runtime/index.js +15 -10
  113. package/dist/cjs/router/runtime/internal.js +29 -18
  114. package/dist/cjs/router/runtime/lifecycle.js +38 -19
  115. package/dist/cjs/router/runtime/plugin.js +11 -14
  116. package/dist/cjs/router/runtime/plugin.node.js +11 -12
  117. package/dist/cjs/router/runtime/provider.js +107 -0
  118. package/dist/cjs/router/runtime/routerHelper.js +9 -5
  119. package/dist/cjs/router/runtime/rsc-router.js +19 -9
  120. package/dist/cjs/router/runtime/rsc.js +9 -5
  121. package/dist/cjs/router/runtime/server.js +9 -5
  122. package/dist/cjs/router/runtime/utils.js +44 -15
  123. package/dist/cjs/router/runtime/withRouter.js +9 -5
  124. package/dist/cjs/rsc/client.js +12 -8
  125. package/dist/cjs/rsc/server.js +9 -5
  126. package/dist/cjs/rsc/server.worker.js +9 -5
  127. package/dist/esm/boundary-debugger/index.mjs +10 -6
  128. package/dist/esm/cli/index.mjs +4 -2
  129. package/dist/esm/core/context/extensions.mjs +28 -0
  130. package/dist/esm/core/context/helmetContext.mjs +13 -0
  131. package/dist/esm/core/context/index.mjs +5 -0
  132. package/dist/esm/core/react/wrapper.mjs +6 -4
  133. package/dist/esm/core/server/federatedCss.mjs +2 -2
  134. package/dist/esm/core/server/helmet.mjs +2 -1
  135. package/dist/esm/core/server/requestHandler.mjs +43 -30
  136. package/dist/esm/core/server/routerCleanup.mjs +66 -0
  137. package/dist/esm/core/server/scriptOrder.mjs +62 -3
  138. package/dist/esm/core/server/stream/afterTemplate.mjs +8 -20
  139. package/dist/esm/core/server/stream/beforeTemplate.mjs +3 -3
  140. package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +1 -1
  141. package/dist/esm/core/server/stream/createReadableStream.mjs +7 -5
  142. package/dist/esm/core/server/stream/createReadableStream.worker.mjs +6 -2
  143. package/dist/esm/core/server/stream/deferredScript.mjs +4 -1
  144. package/dist/esm/core/server/string/index.mjs +3 -9
  145. package/dist/esm/core/server/string/loadable.mjs +14 -48
  146. package/dist/esm/core/server/string/ssrData.mjs +2 -2
  147. package/dist/esm/core/server/utils.mjs +52 -9
  148. package/dist/esm/document/cli/index.mjs +5 -6
  149. package/dist/esm/exports/head.mjs +144 -78
  150. package/dist/esm/exports/loadable.mjs +12 -6
  151. package/dist/esm/exports/tanstack-router.mjs +30 -3
  152. package/dist/esm/module-federation/index.mjs +109 -0
  153. package/dist/esm/router/cli/code/index.mjs +8 -48
  154. package/dist/esm/router/cli/code/templates.mjs +1 -14
  155. package/dist/esm/router/cli/handler.mjs +1 -1
  156. package/dist/esm/router/cli/index.mjs +3 -25
  157. package/dist/esm/router/runtime/DeferredDataScripts.node.mjs +16 -4
  158. package/dist/esm/router/runtime/PrefetchLink.mjs +152 -21
  159. package/dist/esm/router/runtime/internal.mjs +16 -15
  160. package/dist/esm/router/runtime/lifecycle.mjs +22 -13
  161. package/dist/esm/router/runtime/plugin.mjs +4 -11
  162. package/dist/esm/router/runtime/plugin.node.mjs +4 -9
  163. package/dist/esm/router/runtime/provider.mjs +57 -0
  164. package/dist/esm/router/runtime/rsc-router.mjs +10 -4
  165. package/dist/esm/router/runtime/utils.mjs +35 -10
  166. package/dist/esm-node/boundary-debugger/index.mjs +10 -6
  167. package/dist/esm-node/cli/index.mjs +4 -2
  168. package/dist/esm-node/core/context/extensions.mjs +29 -0
  169. package/dist/esm-node/core/context/helmetContext.mjs +14 -0
  170. package/dist/esm-node/core/context/index.mjs +5 -0
  171. package/dist/esm-node/core/react/wrapper.mjs +6 -4
  172. package/dist/esm-node/core/server/federatedCss.mjs +2 -2
  173. package/dist/esm-node/core/server/helmet.mjs +2 -1
  174. package/dist/esm-node/core/server/requestHandler.mjs +43 -30
  175. package/dist/esm-node/core/server/routerCleanup.mjs +67 -0
  176. package/dist/esm-node/core/server/scriptOrder.mjs +62 -3
  177. package/dist/esm-node/core/server/stream/afterTemplate.mjs +8 -20
  178. package/dist/esm-node/core/server/stream/beforeTemplate.mjs +3 -3
  179. package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +1 -1
  180. package/dist/esm-node/core/server/stream/createReadableStream.mjs +7 -5
  181. package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +6 -2
  182. package/dist/esm-node/core/server/stream/deferredScript.mjs +4 -1
  183. package/dist/esm-node/core/server/string/index.mjs +3 -9
  184. package/dist/esm-node/core/server/string/loadable.mjs +14 -48
  185. package/dist/esm-node/core/server/string/ssrData.mjs +2 -2
  186. package/dist/esm-node/core/server/utils.mjs +52 -9
  187. package/dist/esm-node/document/cli/index.mjs +5 -6
  188. package/dist/esm-node/exports/head.mjs +144 -78
  189. package/dist/esm-node/exports/loadable.mjs +12 -6
  190. package/dist/esm-node/exports/tanstack-router.mjs +30 -3
  191. package/dist/esm-node/module-federation/index.mjs +110 -0
  192. package/dist/esm-node/router/cli/code/index.mjs +8 -48
  193. package/dist/esm-node/router/cli/code/templates.mjs +1 -14
  194. package/dist/esm-node/router/cli/handler.mjs +1 -1
  195. package/dist/esm-node/router/cli/index.mjs +3 -25
  196. package/dist/esm-node/router/runtime/DeferredDataScripts.node.mjs +16 -4
  197. package/dist/esm-node/router/runtime/PrefetchLink.mjs +152 -21
  198. package/dist/esm-node/router/runtime/internal.mjs +16 -15
  199. package/dist/esm-node/router/runtime/lifecycle.mjs +22 -13
  200. package/dist/esm-node/router/runtime/plugin.mjs +4 -11
  201. package/dist/esm-node/router/runtime/plugin.node.mjs +4 -9
  202. package/dist/esm-node/router/runtime/provider.mjs +58 -0
  203. package/dist/esm-node/router/runtime/rsc-router.mjs +10 -4
  204. package/dist/esm-node/router/runtime/utils.mjs +35 -10
  205. package/dist/types/cli/entry.d.ts +2 -2
  206. package/dist/types/cli/index.d.ts +3 -1
  207. package/dist/types/core/context/extensions.d.ts +37 -0
  208. package/dist/types/core/context/helmetContext.d.ts +10 -0
  209. package/dist/types/core/context/index.d.ts +6 -0
  210. package/dist/types/core/context/response/index.server.d.ts +4 -1
  211. package/dist/types/core/context/runtime.d.ts +1 -11
  212. package/dist/types/core/plugin/index.d.ts +1 -1
  213. package/dist/types/core/server/routerCleanup.d.ts +28 -0
  214. package/dist/types/core/server/scriptOrder.d.ts +24 -0
  215. package/dist/types/core/server/string/loadable.d.ts +1 -7
  216. package/dist/types/core/server/utils.d.ts +19 -1
  217. package/dist/types/document/constants.d.ts +3 -1
  218. package/dist/types/exports/head.d.ts +4 -4
  219. package/dist/types/exports/loadable.d.ts +1 -1
  220. package/dist/types/exports/tanstack-router.d.ts +88 -5
  221. package/dist/types/module-federation/index.d.ts +65 -0
  222. package/dist/types/router/cli/code/index.d.ts +1 -3
  223. package/dist/types/router/cli/code/utils.d.ts +1 -1
  224. package/dist/types/router/cli/entry.d.ts +1 -1
  225. package/dist/types/router/cli/handler.d.ts +0 -3
  226. package/dist/types/router/runtime/DeferredDataScripts.d.ts +1 -1
  227. package/dist/types/router/runtime/PrefetchLink.d.ts +5 -1
  228. package/dist/types/router/runtime/internal.d.ts +1 -0
  229. package/dist/types/router/runtime/lifecycle.d.ts +2 -0
  230. package/dist/types/router/runtime/plugin.d.ts +1 -1
  231. package/dist/types/router/runtime/plugin.node.d.ts +1 -1
  232. package/dist/types/router/runtime/provider.d.ts +61 -0
  233. package/package.json +34 -26
  234. package/rstest.config.mts +2 -4
  235. package/dist/cjs/router/cli/code/tanstackTypes.js +0 -443
  236. package/dist/cjs/router/runtime/tanstack/basepathRewrite.js +0 -62
  237. package/dist/cjs/router/runtime/tanstack/dataMutation.js +0 -345
  238. package/dist/cjs/router/runtime/tanstack/hydrationBoundary.js +0 -43
  239. package/dist/cjs/router/runtime/tanstack/plugin.js +0 -240
  240. package/dist/cjs/router/runtime/tanstack/plugin.node.js +0 -268
  241. package/dist/cjs/router/runtime/tanstack/prefetchLink.js +0 -55
  242. package/dist/cjs/router/runtime/tanstack/routeTree.js +0 -510
  243. package/dist/cjs/router/runtime/tanstack/rsc/ClientSlot.js +0 -53
  244. package/dist/cjs/router/runtime/tanstack/rsc/CompositeComponent.js +0 -75
  245. package/dist/cjs/router/runtime/tanstack/rsc/ReplayableStream.js +0 -141
  246. package/dist/cjs/router/runtime/tanstack/rsc/RscNodeRenderer.js +0 -65
  247. package/dist/cjs/router/runtime/tanstack/rsc/SlotContext.js +0 -54
  248. package/dist/cjs/router/runtime/tanstack/rsc/client.js +0 -93
  249. package/dist/cjs/router/runtime/tanstack/rsc/createRscProxy.js +0 -141
  250. package/dist/cjs/router/runtime/tanstack/rsc/index.js +0 -42
  251. package/dist/cjs/router/runtime/tanstack/rsc/server.js +0 -246
  252. package/dist/cjs/router/runtime/tanstack/rsc/slotUsageSanitizer.js +0 -65
  253. package/dist/cjs/router/runtime/tanstack/rsc/symbols.js +0 -72
  254. package/dist/cjs/ssr/index.node.js +0 -121
  255. package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.after.js +0 -84
  256. package/dist/cjs/ssr/serverRender/renderToString/entry.js +0 -196
  257. package/dist/cjs/ssr/serverRender/types.js +0 -36
  258. package/dist/esm/router/cli/code/tanstackTypes.mjs +0 -396
  259. package/dist/esm/router/runtime/tanstack/basepathRewrite.mjs +0 -28
  260. package/dist/esm/router/runtime/tanstack/dataMutation.mjs +0 -305
  261. package/dist/esm/router/runtime/tanstack/hydrationBoundary.mjs +0 -9
  262. package/dist/esm/router/runtime/tanstack/plugin.mjs +0 -206
  263. package/dist/esm/router/runtime/tanstack/plugin.node.mjs +0 -234
  264. package/dist/esm/router/runtime/tanstack/prefetchLink.mjs +0 -18
  265. package/dist/esm/router/runtime/tanstack/routeTree.mjs +0 -470
  266. package/dist/esm/router/runtime/tanstack/rsc/ClientSlot.mjs +0 -19
  267. package/dist/esm/router/runtime/tanstack/rsc/CompositeComponent.mjs +0 -41
  268. package/dist/esm/router/runtime/tanstack/rsc/ReplayableStream.mjs +0 -104
  269. package/dist/esm/router/runtime/tanstack/rsc/RscNodeRenderer.mjs +0 -31
  270. package/dist/esm/router/runtime/tanstack/rsc/SlotContext.mjs +0 -17
  271. package/dist/esm/router/runtime/tanstack/rsc/client.mjs +0 -53
  272. package/dist/esm/router/runtime/tanstack/rsc/createRscProxy.mjs +0 -107
  273. package/dist/esm/router/runtime/tanstack/rsc/index.mjs +0 -1
  274. package/dist/esm/router/runtime/tanstack/rsc/server.mjs +0 -200
  275. package/dist/esm/router/runtime/tanstack/rsc/slotUsageSanitizer.mjs +0 -31
  276. package/dist/esm/router/runtime/tanstack/rsc/symbols.mjs +0 -17
  277. package/dist/esm/ssr/index.node.mjs +0 -44
  278. package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.after.mjs +0 -50
  279. package/dist/esm/ssr/serverRender/renderToString/entry.mjs +0 -151
  280. package/dist/esm/ssr/serverRender/types.mjs +0 -1
  281. package/dist/esm-node/router/cli/code/tanstackTypes.mjs +0 -397
  282. package/dist/esm-node/router/runtime/tanstack/basepathRewrite.mjs +0 -29
  283. package/dist/esm-node/router/runtime/tanstack/dataMutation.mjs +0 -306
  284. package/dist/esm-node/router/runtime/tanstack/hydrationBoundary.mjs +0 -10
  285. package/dist/esm-node/router/runtime/tanstack/plugin.mjs +0 -207
  286. package/dist/esm-node/router/runtime/tanstack/plugin.node.mjs +0 -235
  287. package/dist/esm-node/router/runtime/tanstack/prefetchLink.mjs +0 -19
  288. package/dist/esm-node/router/runtime/tanstack/routeTree.mjs +0 -471
  289. package/dist/esm-node/router/runtime/tanstack/rsc/ClientSlot.mjs +0 -20
  290. package/dist/esm-node/router/runtime/tanstack/rsc/CompositeComponent.mjs +0 -42
  291. package/dist/esm-node/router/runtime/tanstack/rsc/ReplayableStream.mjs +0 -105
  292. package/dist/esm-node/router/runtime/tanstack/rsc/RscNodeRenderer.mjs +0 -32
  293. package/dist/esm-node/router/runtime/tanstack/rsc/SlotContext.mjs +0 -18
  294. package/dist/esm-node/router/runtime/tanstack/rsc/client.mjs +0 -54
  295. package/dist/esm-node/router/runtime/tanstack/rsc/createRscProxy.mjs +0 -108
  296. package/dist/esm-node/router/runtime/tanstack/rsc/index.mjs +0 -2
  297. package/dist/esm-node/router/runtime/tanstack/rsc/server.mjs +0 -201
  298. package/dist/esm-node/router/runtime/tanstack/rsc/slotUsageSanitizer.mjs +0 -32
  299. package/dist/esm-node/router/runtime/tanstack/rsc/symbols.mjs +0 -18
  300. package/dist/esm-node/ssr/index.node.mjs +0 -45
  301. package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.after.mjs +0 -51
  302. package/dist/esm-node/ssr/serverRender/renderToString/entry.mjs +0 -152
  303. package/dist/esm-node/ssr/serverRender/types.mjs +0 -2
  304. package/dist/types/router/cli/code/tanstackTypes.d.ts +0 -10
  305. package/dist/types/router/runtime/tanstack/basepathRewrite.d.ts +0 -8
  306. package/dist/types/router/runtime/tanstack/dataMutation.d.ts +0 -29
  307. package/dist/types/router/runtime/tanstack/hydrationBoundary.d.ts +0 -2
  308. package/dist/types/router/runtime/tanstack/plugin.d.ts +0 -6
  309. package/dist/types/router/runtime/tanstack/plugin.node.d.ts +0 -6
  310. package/dist/types/router/runtime/tanstack/prefetchLink.d.ts +0 -11
  311. package/dist/types/router/runtime/tanstack/routeTree.d.ts +0 -8
  312. package/dist/types/router/runtime/tanstack/rsc/ClientSlot.d.ts +0 -5
  313. package/dist/types/router/runtime/tanstack/rsc/CompositeComponent.d.ts +0 -3
  314. package/dist/types/router/runtime/tanstack/rsc/ReplayableStream.d.ts +0 -24
  315. package/dist/types/router/runtime/tanstack/rsc/RscNodeRenderer.d.ts +0 -5
  316. package/dist/types/router/runtime/tanstack/rsc/SlotContext.d.ts +0 -11
  317. package/dist/types/router/runtime/tanstack/rsc/client.d.ts +0 -11
  318. package/dist/types/router/runtime/tanstack/rsc/createRscProxy.d.ts +0 -7
  319. package/dist/types/router/runtime/tanstack/rsc/index.d.ts +0 -2
  320. package/dist/types/router/runtime/tanstack/rsc/server.d.ts +0 -14
  321. package/dist/types/router/runtime/tanstack/rsc/slotUsageSanitizer.d.ts +0 -2
  322. 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,11 +19,67 @@ 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
- if (!scripts) return template;
59
+ if ('' === scripts) return template;
21
60
  const scriptTags = getScriptTags(template);
22
61
  const target = scriptTags.find((match)=>isEntryScript(match.src, entryName, false)) ?? scriptTags.find((match)=>isEntryScript(match.src, entryName, true));
23
- if (!target) return template;
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
  }
@@ -5,7 +5,7 @@ import { CHUNK_CSS_PLACEHOLDER } from "../constants.mjs";
5
5
  import { createFederatedCssLinks } from "../federatedCss.mjs";
6
6
  import { createReplaceHelemt, getHelmetData } from "../helmet.mjs";
7
7
  import { buildHtml } from "../shared.mjs";
8
- import { checkIsNode, safeReplace } from "../utils.mjs";
8
+ import { checkIsNode, hasStylesheetLink, safeReplace } from "../utils.mjs";
9
9
  import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
10
10
  import { dirname as __rspack_dirname } from "node:path";
11
11
  var beforeTemplate_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
@@ -49,13 +49,13 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
49
49
  if (!index) return;
50
50
  const routeId = match.route.id;
51
51
  if (routeId) return routeAssets[routeId];
52
- }).filter(Boolean) ?? [];
52
+ }).filter((routeManifest)=>void 0 !== routeManifest) ?? [];
53
53
  }
54
54
  const asyncEntry = routeAssets[`async-${entryName}`];
55
55
  if (asyncEntry) matchedRouteManifests.push(asyncEntry);
56
56
  const cssChunks = matchedRouteManifests.reduce((chunks, routeManifest)=>{
57
57
  const { referenceCssAssets = [] } = routeManifest;
58
- const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
58
+ const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !hasStylesheetLink(template, asset));
59
59
  return [
60
60
  ...chunks,
61
61
  ..._cssChunks
@@ -40,7 +40,7 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
40
40
  if (!index) return;
41
41
  const routeId = match.route.id;
42
42
  if (routeId) return routeAssets[routeId];
43
- }).filter(Boolean) ?? [];
43
+ }).filter((routeManifest)=>void 0 !== routeManifest) ?? [];
44
44
  }
45
45
  const asyncEntry = routeAssets[`async-${entryName}`];
46
46
  if (asyncEntry) matchedRouteManifests.push(asyncEntry);
@@ -65,12 +65,14 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
65
65
  try {
66
66
  if (shellChunkStatus !== ShellChunkStatus.FINISH) {
67
67
  chunkVec.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
68
- const chunkStr = chunk.toString('utf-8');
69
- if (chunkStr.includes(ESCAPED_SHELL_STREAM_END_MARK)) {
70
- let concatedChunk = Buffer.concat(chunkVec).toString('utf-8');
71
- concatedChunk = concatedChunk.replace(ESCAPED_SHELL_STREAM_END_MARK, '');
68
+ const concatedChunk = Buffer.concat(chunkVec).toString('utf-8');
69
+ const markerIndex = concatedChunk.indexOf(ESCAPED_SHELL_STREAM_END_MARK);
70
+ if (-1 !== markerIndex) {
71
+ const beforeMark = concatedChunk.slice(0, markerIndex);
72
+ const afterMark = concatedChunk.slice(markerIndex + ESCAPED_SHELL_STREAM_END_MARK.length);
72
73
  shellChunkStatus = ShellChunkStatus.FINISH;
73
- this.push(`${shellBefore}${concatedChunk}${shellAfter}`);
74
+ this.push(`${shellBefore}${beforeMark}${shellAfter}`);
75
+ if (afterMark) this.push(afterMark);
74
76
  if (pendingScripts.length > 0) for (const s of pendingScripts)this.push(s);
75
77
  }
76
78
  } else this.push(chunk);
@@ -78,9 +78,13 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
78
78
  if (shellChunkStatus !== ShellChunkStatus.FINISH) {
79
79
  chunkVec.push(new TextDecoder().decode(value));
80
80
  const concatedChunk = chunkVec.join('');
81
- if (concatedChunk.includes(ESCAPED_SHELL_STREAM_END_MARK)) {
81
+ const markerIndex = concatedChunk.indexOf(ESCAPED_SHELL_STREAM_END_MARK);
82
+ if (-1 !== markerIndex) {
83
+ const beforeMark = concatedChunk.slice(0, markerIndex);
84
+ const afterMark = concatedChunk.slice(markerIndex + ESCAPED_SHELL_STREAM_END_MARK.length);
82
85
  shellChunkStatus = ShellChunkStatus.FINISH;
83
- safeEnqueue(encodeForWebStream(`${shellBefore}${concatedChunk.replace(ESCAPED_SHELL_STREAM_END_MARK, '')}${shellAfter}`));
86
+ safeEnqueue(encodeForWebStream(`${shellBefore}${beforeMark}${shellAfter}`));
87
+ if (afterMark.length > 0) safeEnqueue(encodeForWebStream(afterMark));
84
88
  flushPendingScripts();
85
89
  }
86
90
  } else safeEnqueue(value);
@@ -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,8 +1,8 @@
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";
5
- import { attributesToString, checkIsNode } from "../utils.mjs";
4
+ import { getMatchedRouteAssets, orderHydrationScriptChunks } from "../scriptOrder.mjs";
5
+ import { attributesToString, checkIsNode, hasStylesheetLink } from "../utils.mjs";
6
6
  import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
7
7
  import { dirname as __rspack_dirname } from "node:path";
8
8
  var loadable_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
@@ -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;
@@ -140,11 +113,7 @@ class LoadableCollector {
140
113
  const { template, chunkSet, config, moduleFederationCssAssets } = this.options;
141
114
  const { inlineStyles } = config;
142
115
  const atrributes = attributesToString(this.generateAttributes());
143
- const linkRegExp = /<link .*?href="([^"]+)".*?>/g;
144
- const matchs = template.matchAll(linkRegExp);
145
- const existedLinks = [];
146
- for (const match of matchs)existedLinks.push(match[1]);
147
- const emittedChunks = chunks.filter((chunk)=>!existedLinks.includes(chunk.url) && !this.existsAssets?.includes(chunk.path));
116
+ const emittedChunks = chunks.filter((chunk)=>!hasStylesheetLink(template, chunk.url) && !this.existsAssets?.includes(chunk.path));
148
117
  const css = await Promise.all(emittedChunks.map(async (chunk)=>{
149
118
  const link = `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
150
119
  if (checkIsNode() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<style>${content}</style>`).catch((_)=>link);
@@ -154,10 +123,7 @@ class LoadableCollector {
154
123
  chunkSet.cssChunk += createFederatedCssLinks(moduleFederationCssAssets, {
155
124
  template,
156
125
  attributes: this.generateAttributes(),
157
- existingAssets: [
158
- ...existedLinks,
159
- ...emittedChunks.map((chunk)=>chunk.url)
160
- ]
126
+ existingAssets: emittedChunks.map((chunk)=>chunk.url)
161
127
  });
162
128
  }
163
129
  generateAttributes(extraAtr = {}) {
@@ -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];
@@ -37,4 +60,24 @@ function getSSRMode(ssrConfig) {
37
60
  const result = ssrConfig?.mode === 'string' ? 'string' : 'stream';
38
61
  return result;
39
62
  }
40
- export { attributesToString, checkIsNode, getSSRConfigByEntry, getSSRMode, safeReplace, serializeErrors };
63
+ const getLinkAttributes = (linkTag)=>{
64
+ const attributes = new Map();
65
+ const attributeRegExp = /([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
66
+ let match;
67
+ while(match = attributeRegExp.exec(linkTag)){
68
+ const [, name, doubleQuotedValue, singleQuotedValue, unquotedValue] = match;
69
+ if ('link' === name.toLowerCase()) continue;
70
+ attributes.set(name.toLowerCase(), doubleQuotedValue ?? singleQuotedValue ?? unquotedValue ?? '');
71
+ }
72
+ return attributes;
73
+ };
74
+ const hasStylesheetLink = (template, href)=>{
75
+ const linkTags = template.match(/<link\b[^>]*>/gi) ?? [];
76
+ return linkTags.some((linkTag)=>{
77
+ const attributes = getLinkAttributes(linkTag);
78
+ const linkHref = attributes.get('href');
79
+ const rel = attributes.get('rel');
80
+ return linkHref === href && rel?.split(/\s+/).some((relToken)=>'stylesheet' === relToken.toLowerCase());
81
+ });
82
+ };
83
+ export { attributesToString, checkIsNode, getSSRConfigByEntry, getSSRMode, hasStylesheetLink, safeReplace, serializeErrors };
@@ -297,12 +297,13 @@ const documentPlugin = ()=>({
297
297
  processedHtml = processCommentPlaceholders(processedHtml);
298
298
  return `<!DOCTYPE html>${processedHtml}`.replace(DOCUMENT_META_PLACEHOLDER, ()=>metas).replace(DOCUMENT_SSR_PLACEHOLDER, ()=>HTML_SEPARATOR).replace(DOCUMENT_SCRIPTS_PLACEHOLDER, ()=>scripts).replace(DOCUMENT_LINKS_PLACEHOLDER, ()=>links).replace(DOCUMENT_CHUNKSMAP_PLACEHOLDER, ()=>PLACEHOLDER_REPLACER_MAP[DOCUMENT_CHUNKSMAP_PLACEHOLDER]).replace(DOCUMENT_SSRDATASCRIPT_PLACEHOLDER, ()=>PLACEHOLDER_REPLACER_MAP[DOCUMENT_SSRDATASCRIPT_PLACEHOLDER]).replace(DOCUMENT_TITLE_PLACEHOLDER, ()=>titles);
299
299
  };
300
- const documentEntry = (entryName, templateParameters)=>{
300
+ const documentEntry = (entryName)=>{
301
301
  const { entrypoints, internalDirectory, appDirectory } = api.getAppContext();
302
302
  const documentFilePath = getDocumentByEntryName(entrypoints, entryName, appDirectory);
303
303
  if (!documentFilePath) return null;
304
- return async ({ htmlPlugin })=>{
304
+ return async (templateData)=>{
305
305
  const config = api.getNormalizedConfig();
306
+ const { compilation: _compilation, htmlPlugin, rspackConfig: _rspackConfig, ...templateParameters } = templateData;
306
307
  const documentParams = getDocParams({
307
308
  config: config,
308
309
  entryName,
@@ -320,6 +321,7 @@ const documentPlugin = ()=>({
320
321
  debug("entry %s's document jsx rendered html: %o", entryName, html);
321
322
  const { partialsByEntrypoint } = api.getAppContext();
322
323
  html = processPartials(html, entryName, partialsByEntrypoint || {});
324
+ if (!htmlPlugin) throw new Error('Failed to get HTML plugin tags from template parameters.');
323
325
  const { scripts, links, metas, titles } = extractHtmlTags(htmlPlugin, templateParameters);
324
326
  return processPlaceholders(html, config, scripts, links, metas, titles);
325
327
  };
@@ -330,10 +332,7 @@ const documentPlugin = ()=>({
330
332
  return {
331
333
  tools: {
332
334
  htmlPlugin: (options, entry)=>{
333
- const hackParameters = 'function' == typeof options?.templateParameters ? options?.templateParameters({}, {}, {}, {}) : {
334
- ...options?.templateParameters
335
- };
336
- const templateContent = documentEntry(entry.entryName, hackParameters);
335
+ const templateContent = documentEntry(entry.entryName);
337
336
  const documentHtmlOptions = templateContent ? {
338
337
  templateContent,
339
338
  inject: false