@bleedingdev/modern-js-runtime 3.2.0-ultramodern.2 → 3.2.0-ultramodern.23

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 (177) hide show
  1. package/dist/cjs/cli/ssr/index.js +3 -2
  2. package/dist/cjs/cli/template.server.js +1 -0
  3. package/dist/cjs/core/context/serverPayload/index.js +1 -1
  4. package/dist/cjs/core/plugin/index.js +3 -2
  5. package/dist/cjs/core/server/helmet.js +2 -2
  6. package/dist/cjs/core/server/stream/beforeTemplate.worker.js +105 -0
  7. package/dist/cjs/core/server/stream/createReadableStream.worker.js +2 -1
  8. package/dist/cjs/core/server/stream/shared.js +1 -0
  9. package/dist/cjs/router/cli/code/tanstackTypes.js +20 -6
  10. package/dist/cjs/router/runtime/tanstack/plugin.js +2 -0
  11. package/dist/cjs/router/runtime/tanstack/routeTree.js +38 -2
  12. package/dist/cjs/rsc/server.worker.js +58 -0
  13. package/dist/esm/cli/ssr/index.mjs +3 -2
  14. package/dist/esm/cli/template.server.mjs +1 -0
  15. package/dist/esm/core/context/serverPayload/index.mjs +1 -1
  16. package/dist/esm/core/plugin/index.mjs +3 -2
  17. package/dist/esm/core/server/helmet.mjs +1 -1
  18. package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +61 -0
  19. package/dist/esm/core/server/stream/createReadableStream.worker.mjs +2 -1
  20. package/dist/esm/core/server/stream/shared.mjs +1 -0
  21. package/dist/esm/router/cli/code/tanstackTypes.mjs +20 -6
  22. package/dist/esm/router/runtime/tanstack/plugin.mjs +2 -0
  23. package/dist/esm/router/runtime/tanstack/routeTree.mjs +38 -2
  24. package/dist/esm/rsc/server.worker.mjs +1 -0
  25. package/dist/esm-node/cli/ssr/index.mjs +3 -2
  26. package/dist/esm-node/cli/template.server.mjs +1 -0
  27. package/dist/esm-node/core/context/serverPayload/index.mjs +1 -1
  28. package/dist/esm-node/core/plugin/index.mjs +3 -2
  29. package/dist/esm-node/core/server/helmet.mjs +1 -1
  30. package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +62 -0
  31. package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +2 -1
  32. package/dist/esm-node/core/server/stream/shared.mjs +1 -0
  33. package/dist/esm-node/router/cli/code/tanstackTypes.mjs +20 -6
  34. package/dist/esm-node/router/runtime/tanstack/plugin.mjs +2 -0
  35. package/dist/esm-node/router/runtime/tanstack/routeTree.mjs +38 -2
  36. package/dist/esm-node/rsc/server.worker.mjs +2 -0
  37. package/dist/types/cache/index.d.ts +1 -0
  38. package/dist/types/cli/alias.d.ts +7 -0
  39. package/dist/types/cli/code.d.ts +3 -0
  40. package/dist/types/cli/constants.d.ts +9 -0
  41. package/dist/types/cli/entry.d.ts +2 -0
  42. package/dist/types/cli/index.d.ts +11 -0
  43. package/dist/types/cli/ssr/index.d.ts +6 -0
  44. package/dist/types/cli/ssr/loadable-bundler-plugin.d.ts +31 -0
  45. package/dist/types/cli/ssr/mode.d.ts +15 -0
  46. package/dist/types/cli/template.d.ts +50 -0
  47. package/dist/types/cli/template.server.d.ts +20 -0
  48. package/dist/types/common.d.ts +8 -0
  49. package/dist/types/core/browser/hydrate.d.ts +5 -0
  50. package/dist/types/core/browser/index.d.ts +9 -0
  51. package/dist/types/core/browser/withCallback.d.ts +5 -0
  52. package/dist/types/core/compat/hooks.d.ts +4 -0
  53. package/dist/types/core/compat/index.d.ts +2 -0
  54. package/dist/types/core/compat/requestContext.d.ts +5 -0
  55. package/dist/types/core/config.d.ts +6 -0
  56. package/dist/types/core/constants.d.ts +6 -0
  57. package/dist/types/core/context/index.d.ts +50 -0
  58. package/dist/types/core/context/monitors/default.d.ts +2 -0
  59. package/dist/types/core/context/monitors/index.d.ts +1 -0
  60. package/dist/types/core/context/monitors/index.server.d.ts +2 -0
  61. package/dist/types/core/context/request/index.d.ts +1 -0
  62. package/dist/types/core/context/request/index.server.d.ts +1 -0
  63. package/dist/types/core/context/response/index.d.ts +4 -0
  64. package/dist/types/core/context/response/index.server.d.ts +4 -0
  65. package/dist/types/core/context/runtime.d.ts +42 -0
  66. package/dist/types/core/context/serverPayload/index.d.ts +4 -0
  67. package/dist/types/core/context/serverPayload/index.server.d.ts +31 -0
  68. package/dist/types/core/index.d.ts +5 -0
  69. package/dist/types/core/plugin/index.d.ts +5 -0
  70. package/dist/types/core/plugin/types.d.ts +10 -0
  71. package/dist/types/core/react/index.d.ts +2 -0
  72. package/dist/types/core/react/wrapper.d.ts +3 -0
  73. package/dist/types/core/server/constants.d.ts +4 -0
  74. package/dist/types/core/server/helmet.d.ts +3 -0
  75. package/dist/types/core/server/index.d.ts +4 -0
  76. package/dist/types/core/server/react/index.d.ts +2 -0
  77. package/dist/types/core/server/react/no-ssr-cache/index.d.ts +2 -0
  78. package/dist/types/core/server/react/nossr/index.d.ts +4 -0
  79. package/dist/types/core/server/requestHandler.d.ts +13 -0
  80. package/dist/types/core/server/server.d.ts +4 -0
  81. package/dist/types/core/server/shared.d.ts +8 -0
  82. package/dist/types/core/server/stream/afterTemplate.d.ts +13 -0
  83. package/dist/types/core/server/stream/beforeTemplate.d.ts +9 -0
  84. package/dist/types/core/server/stream/beforeTemplate.worker.d.ts +9 -0
  85. package/dist/types/core/server/stream/createReadableStream.d.ts +2 -0
  86. package/dist/types/core/server/stream/createReadableStream.worker.d.ts +2 -0
  87. package/dist/types/core/server/stream/deferredScript.d.ts +15 -0
  88. package/dist/types/core/server/stream/index.d.ts +1 -0
  89. package/dist/types/core/server/stream/shared.d.ts +40 -0
  90. package/dist/types/core/server/stream/template.d.ts +9 -0
  91. package/dist/types/core/server/string/index.d.ts +2 -0
  92. package/dist/types/core/server/string/loadable.d.ts +36 -0
  93. package/dist/types/core/server/string/ssrData.d.ts +20 -0
  94. package/dist/types/core/server/string/types.d.ts +12 -0
  95. package/dist/types/core/server/tracer.d.ts +17 -0
  96. package/dist/types/core/server/utils.d.ts +19 -0
  97. package/dist/types/core/types.d.ts +49 -0
  98. package/dist/types/document/Body.d.ts +2 -0
  99. package/dist/types/document/Comment.d.ts +5 -0
  100. package/dist/types/document/DocumentContext.d.ts +13 -0
  101. package/dist/types/document/DocumentStructureContext.d.ts +12 -0
  102. package/dist/types/document/Head.d.ts +5 -0
  103. package/dist/types/document/Html.d.ts +4 -0
  104. package/dist/types/document/Links.d.ts +2 -0
  105. package/dist/types/document/Root.d.ts +7 -0
  106. package/dist/types/document/Script.d.ts +4 -0
  107. package/dist/types/document/Scripts.d.ts +2 -0
  108. package/dist/types/document/Style.d.ts +5 -0
  109. package/dist/types/document/Title.d.ts +1 -0
  110. package/dist/types/document/cli/index.d.ts +5 -0
  111. package/dist/types/document/constants.d.ts +25 -0
  112. package/dist/types/document/index.d.ts +12 -0
  113. package/dist/types/exports/config-routes.d.ts +9 -0
  114. package/dist/types/exports/head.d.ts +4 -0
  115. package/dist/types/exports/loadable.d.ts +3 -0
  116. package/dist/types/exports/tanstack-router.d.ts +5 -0
  117. package/dist/types/index.d.ts +10 -0
  118. package/dist/types/internal.d.ts +2 -0
  119. package/dist/types/react-server.d.ts +3 -0
  120. package/dist/types/router/cli/code/getClientRoutes/getRoutes.d.ts +8 -0
  121. package/dist/types/router/cli/code/getClientRoutes/index.d.ts +1 -0
  122. package/dist/types/router/cli/code/getClientRoutes/utils.d.ts +4 -0
  123. package/dist/types/router/cli/code/index.d.ts +12 -0
  124. package/dist/types/router/cli/code/inspect.d.ts +22 -0
  125. package/dist/types/router/cli/code/makeLegalIdentifier.d.ts +1 -0
  126. package/dist/types/router/cli/code/nestedRoutes.d.ts +13 -0
  127. package/dist/types/router/cli/code/tanstackTypes.d.ts +10 -0
  128. package/dist/types/router/cli/code/templates.d.ts +28 -0
  129. package/dist/types/router/cli/code/utils.d.ts +12 -0
  130. package/dist/types/router/cli/config-routes/converter.d.ts +15 -0
  131. package/dist/types/router/cli/config-routes/parseRouteConfig.d.ts +32 -0
  132. package/dist/types/router/cli/constants.d.ts +31 -0
  133. package/dist/types/router/cli/entry.d.ts +18 -0
  134. package/dist/types/router/cli/handler.d.ts +28 -0
  135. package/dist/types/router/cli/index.d.ts +5 -0
  136. package/dist/types/router/index.d.ts +1 -0
  137. package/dist/types/router/internal.d.ts +2 -0
  138. package/dist/types/router/runtime/CSSLinks.d.ts +9 -0
  139. package/dist/types/router/runtime/DefaultNotFound.d.ts +2 -0
  140. package/dist/types/router/runtime/DeferredDataScripts.d.ts +2 -0
  141. package/dist/types/router/runtime/DeferredDataScripts.node.d.ts +11 -0
  142. package/dist/types/router/runtime/PrefetchLink.d.ts +27 -0
  143. package/dist/types/router/runtime/constants.d.ts +146 -0
  144. package/dist/types/router/runtime/hooks.d.ts +18 -0
  145. package/dist/types/router/runtime/index.d.ts +7 -0
  146. package/dist/types/router/runtime/internal.d.ts +11 -0
  147. package/dist/types/router/runtime/lifecycle.d.ts +25 -0
  148. package/dist/types/router/runtime/plugin.d.ts +9 -0
  149. package/dist/types/router/runtime/plugin.node.d.ts +7 -0
  150. package/dist/types/router/runtime/routerHelper.d.ts +5 -0
  151. package/dist/types/router/runtime/rsc-router.d.ts +20 -0
  152. package/dist/types/router/runtime/rsc.d.ts +1 -0
  153. package/dist/types/router/runtime/server.d.ts +1 -0
  154. package/dist/types/router/runtime/tanstack/basepathRewrite.d.ts +8 -0
  155. package/dist/types/router/runtime/tanstack/dataMutation.d.ts +29 -0
  156. package/dist/types/router/runtime/tanstack/plugin.d.ts +6 -0
  157. package/dist/types/router/runtime/tanstack/plugin.node.d.ts +6 -0
  158. package/dist/types/router/runtime/tanstack/prefetchLink.d.ts +11 -0
  159. package/dist/types/router/runtime/tanstack/routeTree.d.ts +8 -0
  160. package/dist/types/router/runtime/tanstack/rsc/ClientSlot.d.ts +5 -0
  161. package/dist/types/router/runtime/tanstack/rsc/CompositeComponent.d.ts +3 -0
  162. package/dist/types/router/runtime/tanstack/rsc/ReplayableStream.d.ts +24 -0
  163. package/dist/types/router/runtime/tanstack/rsc/RscNodeRenderer.d.ts +5 -0
  164. package/dist/types/router/runtime/tanstack/rsc/SlotContext.d.ts +11 -0
  165. package/dist/types/router/runtime/tanstack/rsc/client.d.ts +11 -0
  166. package/dist/types/router/runtime/tanstack/rsc/createRscProxy.d.ts +7 -0
  167. package/dist/types/router/runtime/tanstack/rsc/index.d.ts +2 -0
  168. package/dist/types/router/runtime/tanstack/rsc/server.d.ts +14 -0
  169. package/dist/types/router/runtime/tanstack/rsc/slotUsageSanitizer.d.ts +2 -0
  170. package/dist/types/router/runtime/tanstack/rsc/symbols.d.ts +46 -0
  171. package/dist/types/router/runtime/types.d.ts +119 -0
  172. package/dist/types/router/runtime/utils.d.ts +48 -0
  173. package/dist/types/router/runtime/withRouter.d.ts +10 -0
  174. package/dist/types/rsc/client.d.ts +2 -0
  175. package/dist/types/rsc/server.d.ts +1 -0
  176. package/dist/types/rsc/server.worker.d.ts +1 -0
  177. package/package.json +16 -16
@@ -8,6 +8,7 @@ import { onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBefo
8
8
  import { applyRouterRuntimeState } from "../lifecycle.mjs";
9
9
  import { createRouteObjectsFromConfig, urlJoin } from "../utils.mjs";
10
10
  import { createModernBasepathRewrite } from "./basepathRewrite.mjs";
11
+ import { Link } from "./prefetchLink.mjs";
11
12
  import { createRouteTreeFromRouteObjects } from "./routeTree.mjs";
12
13
  import { getTanstackRscSerializationAdapters } from "./rsc/client.mjs";
13
14
  import * as __rspack_external_react from "react";
@@ -70,6 +71,7 @@ const tanstackRouterPlugin = (userConfig = {})=>({
70
71
  }
71
72
  }
72
73
  context.router = {
74
+ Link: Link,
73
75
  useMatches: useMatches,
74
76
  useLocation: useLocation,
75
77
  useNavigate: useNavigate,
@@ -1,4 +1,5 @@
1
1
  import { createRootRoute, createRoute, notFound, redirect } from "@tanstack/react-router";
2
+ import { createElement } from "react";
2
3
  import { DefaultNotFound } from "../DefaultNotFound.mjs";
3
4
  function createTanstackRoute(options) {
4
5
  return createRoute(options);
@@ -43,6 +44,33 @@ function isModernDeferredData(value) {
43
44
  function normalizeModernLoaderResult(result) {
44
45
  return isModernDeferredData(result) ? result.data : result;
45
46
  }
47
+ function pickRouteModuleComponent(routeModule) {
48
+ if ('function' == typeof routeModule || routeModule && 'object' == typeof routeModule && '$$typeof' in routeModule) return routeModule;
49
+ if (!routeModule || 'object' != typeof routeModule) return;
50
+ const module = routeModule;
51
+ const component = module.default || module.Component;
52
+ if ('function' == typeof component || component && 'object' == typeof component && '$$typeof' in component) return component;
53
+ }
54
+ function createServerLazyImportComponent(lazyImport, fallbackComponent) {
55
+ if ("u" > typeof document) return fallbackComponent;
56
+ let resolvedComponent;
57
+ let pendingLoad;
58
+ const load = async ()=>{
59
+ if (resolvedComponent) return resolvedComponent;
60
+ const routeModule = await lazyImport();
61
+ const component = pickRouteModuleComponent(routeModule);
62
+ if (component) resolvedComponent = component;
63
+ return resolvedComponent;
64
+ };
65
+ const Component = (props)=>{
66
+ if (resolvedComponent) return createElement(resolvedComponent, props);
67
+ pendingLoad ||= load();
68
+ throw pendingLoad;
69
+ };
70
+ Component.load = load;
71
+ Component.preload = load;
72
+ return Component;
73
+ }
46
74
  function throwTanstackRedirect(location) {
47
75
  const target = location || '/';
48
76
  try {
@@ -209,10 +237,18 @@ function wrapRouteObjectLoader(route, revalidationState) {
209
237
  }
210
238
  function toRouteComponent(routeObject) {
211
239
  const route = routeObject;
240
+ const lazyImport = 'function' == typeof route.lazyImport ? route.lazyImport : void 0;
241
+ const fallbackComponent = route.Component ? route.Component : route.element ? ()=>route.element : void 0;
242
+ if (lazyImport && fallbackComponent) return createServerLazyImportComponent(lazyImport, fallbackComponent);
212
243
  if (route.Component) return route.Component;
213
244
  const element = route.element;
214
245
  if (element) return ()=>element;
215
246
  }
247
+ function toModernRouteComponent(route) {
248
+ const component = route.component || void 0;
249
+ if ('function' == typeof route.lazyImport && component) return createServerLazyImportComponent(route.lazyImport, component);
250
+ return component;
251
+ }
216
252
  function toErrorComponent(routeObject) {
217
253
  const route = routeObject;
218
254
  if (route.ErrorBoundary) return route.ErrorBoundary;
@@ -292,7 +328,7 @@ function createRouteFromModernRoute(opts) {
292
328
  const stableFallbackId = modernId || route._component || route.filename || route.data || ('function' == typeof route.loader ? route.id : void 0);
293
329
  const pendingComponent = route.loading || route.pendingComponent;
294
330
  const errorComponent = route.error || route.errorComponent;
295
- const component = route.component;
331
+ const component = toModernRouteComponent(route);
296
332
  const modernLoader = route.loader;
297
333
  const modernAction = route.action;
298
334
  const modernShouldRevalidate = route.shouldRevalidate;
@@ -338,7 +374,7 @@ function createRouteFromModernRoute(opts) {
338
374
  }
339
375
  function createRouteTreeFromModernRoutes(routes) {
340
376
  const rootModern = routes.find((r)=>r && 'nested' === r.type && r.isRoot);
341
- const rootComponent = rootModern?.component;
377
+ const rootComponent = rootModern ? toModernRouteComponent(rootModern) : void 0;
342
378
  const pendingComponent = rootModern?.loading;
343
379
  const errorComponent = rootModern?.error;
344
380
  const rootLoader = rootModern?.loader;
@@ -0,0 +1 @@
1
+ export * from "@modern-js/render/rsc-worker";
@@ -86,13 +86,14 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
86
86
  const hasServerRendering = hasServerRenderingConfig(userConfig);
87
87
  const hasModuleFederationRuntimeMarker = hasServerRendering && shouldUseModuleFederationNodeOutput(config);
88
88
  const hasExplicitMfSsrFlag = isModuleFederationAppSSREnabled(userConfig);
89
+ const isCloudflareWorkerSSR = 'workerSSR' === name && userConfig.deploy?.target === 'cloudflare';
89
90
  const requireExplicitMfSsrFlag = 'true' === process.env.MODERN_MF_APP_SSR_REQUIRE_EXPLICIT;
90
91
  if (hasServerRendering && hasModuleFederationRuntimeMarker && !hasExplicitMfSsrFlag) {
91
92
  const warningMessage = '[modernjs][mf-ssr] Module Federation SSR was auto-detected from runtime markers. Set server.ssr.moduleFederationAppSSR=true explicitly in host and remotes to avoid heuristic drift.';
92
93
  if (requireExplicitMfSsrFlag) throw new Error(`${warningMessage} (enforced by MODERN_MF_APP_SSR_REQUIRE_EXPLICIT=true)`);
93
94
  console.warn(warningMessage);
94
95
  }
95
- const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag;
96
+ const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag && !isCloudflareWorkerSSR;
96
97
  const useModuleFederationNodeOutput = hasServerRendering && isModuleFederationAppSSR && isNodeEnvironmentTarget(config.output.target);
97
98
  const ssrEnv = userConfig.deploy?.worker?.ssr || userConfig.server?.rsc ? 'edge' : 'node';
98
99
  const appContext = modernAPI.getAppContext();
@@ -109,7 +110,7 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
109
110
  } : void 0;
110
111
  const useLoadablePlugin = isUseSSRBundle(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig, appDirectory, entrypoints);
111
112
  const outputConfig = {
112
- module: isServerEnvironment && !useModuleFederationNodeOutput && outputModule
113
+ module: isServerEnvironment && !useModuleFederationNodeOutput && (outputModule || 'workerSSR' === name && userConfig.deploy?.target === 'cloudflare')
113
114
  };
114
115
  const useLoadableComponents = isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig, appDirectory, entrypoints);
115
116
  return mergeEnvironmentConfig(config, {
@@ -36,6 +36,7 @@ const handleRequest = async (request, ServerRoot, options) => {
36
36
  </ServerRoot>,
37
37
  {
38
38
  ...options,
39
+ rscManifest: __rspack_rsc_manifest__,
39
40
  rscRoot: options.rscRoot,
40
41
  },
41
42
  );
@@ -1,4 +1,4 @@
1
1
  import "node:module";
2
- const getServerPayload = ()=>{};
2
+ const getServerPayload = ()=>void 0;
3
3
  const setServerPayload = (payload)=>{};
4
4
  export { getServerPayload, setServerPayload };
@@ -17,8 +17,9 @@ function registerPlugin(internalPlugins, runtimeConfig) {
17
17
  config: runtimeConfig || {},
18
18
  handleSetupResult: handleSetupResult
19
19
  });
20
- setGlobalInternalRuntimeContext(runtimeContext);
21
- return runtimeContext;
20
+ const internalRuntimeContext = runtimeContext;
21
+ setGlobalInternalRuntimeContext(internalRuntimeContext);
22
+ return internalRuntimeContext;
22
23
  }
23
24
  function mergeConfig(config, ...otherConfig) {
24
25
  return merge({}, config, ...otherConfig);
@@ -1,6 +1,6 @@
1
1
  import "node:module";
2
- import { EOL } from "os";
3
2
  import { safeReplace } from "./utils.mjs";
3
+ const EOL = '\n';
4
4
  const RE_HTML_ATTR = /<html[^>]*>/;
5
5
  const RE_BODY_ATTR = /<body[^>]*>/;
6
6
  const RE_LAST_IN_HEAD = /<\/head>/;
@@ -0,0 +1,62 @@
1
+ import "node:module";
2
+ import { matchRoutes } from "@modern-js/runtime-utils/router";
3
+ import react_helmet from "react-helmet";
4
+ import { getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
5
+ import { CHUNK_CSS_PLACEHOLDER } from "../constants.mjs";
6
+ import { createReplaceHelemt } from "../helmet.mjs";
7
+ import { buildHtml } from "../shared.mjs";
8
+ import { safeReplace } from "../utils.mjs";
9
+ const checkIsInline = (chunk, enableInline)=>{
10
+ if ('production' !== process.env.NODE_ENV) return false;
11
+ if (enableInline instanceof RegExp) return enableInline.test(chunk);
12
+ return Boolean(enableInline);
13
+ };
14
+ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
15
+ const { config, runtimeContext, styledComponentsStyleTags, entryName } = options;
16
+ const helmetData = react_helmet.renderStatic();
17
+ const callbacks = [
18
+ createReplaceHelemt(helmetData),
19
+ (template)=>injectCss(template, entryName, styledComponentsStyleTags)
20
+ ];
21
+ return buildHtml(beforeAppTemplate, callbacks);
22
+ async function injectCss(template, entryName, styledComponentsStyleTags) {
23
+ let css = await getCssChunks();
24
+ if (styledComponentsStyleTags) css += styledComponentsStyleTags;
25
+ return safeReplace(template, CHUNK_CSS_PLACEHOLDER, css);
26
+ async function getCssChunks() {
27
+ const { routeManifest, routerContext, routes } = runtimeContext;
28
+ if (!routeManifest) return '';
29
+ const { routeAssets } = routeManifest;
30
+ let matchedRouteManifests;
31
+ const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext);
32
+ if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
33
+ else {
34
+ if (!routerContext || !routes) return '';
35
+ const matches = matchRoutes(routes, routerContext.location, routerContext.basename);
36
+ matchedRouteManifests = matches?.map((match, index)=>{
37
+ if (!index) return;
38
+ const routeId = match.route.id;
39
+ if (routeId) return routeAssets[routeId];
40
+ }).filter(Boolean);
41
+ }
42
+ const asyncEntry = routeAssets[`async-${entryName}`];
43
+ if (asyncEntry) matchedRouteManifests?.push(asyncEntry);
44
+ const cssChunks = matchedRouteManifests ? matchedRouteManifests.reduce((chunks, routeManifest)=>{
45
+ const { referenceCssAssets = [] } = routeManifest;
46
+ const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
47
+ return [
48
+ ...chunks,
49
+ ..._cssChunks
50
+ ];
51
+ }, []) : [];
52
+ const { inlineStyles } = config;
53
+ const styles = cssChunks.map((chunk)=>{
54
+ const link = `<link href="${chunk}" rel="stylesheet" />`;
55
+ checkIsInline(chunk, inlineStyles);
56
+ return link;
57
+ });
58
+ return `${styles.join('')}`;
59
+ }
60
+ }
61
+ }
62
+ export { buildShellBeforeTemplate };
@@ -9,7 +9,7 @@ import { getTemplates } from "./template.mjs";
9
9
  const createReadableStreamFromElement = async (request, rootElement, options)=>{
10
10
  let shellChunkStatus = ShellChunkStatus.START;
11
11
  const chunkVec = [];
12
- const { htmlTemplate, runtimeContext, config, ssrConfig, entryName, rscRoot } = options;
12
+ const { htmlTemplate, runtimeContext, config, ssrConfig, entryName, rscManifest, rscRoot } = options;
13
13
  const { shellBefore, shellAfter } = await getTemplates(htmlTemplate, {
14
14
  renderLevel: RenderLevel.SERVER_RENDER,
15
15
  runtimeContext,
@@ -22,6 +22,7 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
22
22
  const readableOriginal = await renderSSRStream(rootElement, {
23
23
  request,
24
24
  nonce: config.nonce,
25
+ rscManifest,
25
26
  rscRoot: rscRoot,
26
27
  routes: runtimeContext.routes,
27
28
  onError (error) {
@@ -87,6 +87,7 @@ function createRenderStreaming(createReadableStreamPromise) {
87
87
  rscClientManifest: options.rscClientManifest,
88
88
  rscSSRManifest: options.rscSSRManifest,
89
89
  rscServerManifest: options.rscServerManifest,
90
+ rscManifest: options.rscManifest,
90
91
  rscRoot: options.rscRoot,
91
92
  onShellReady () {
92
93
  const cost = end();
@@ -79,6 +79,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
79
79
  const imports = [];
80
80
  const statements = [];
81
81
  const loaderImportMap = new Map();
82
+ const usedRouteVarNames = new Set();
82
83
  let loaderIndex = 0;
83
84
  let routeIndex = 0;
84
85
  const getImportNamesForLoader = async (aliasedNoExtPath, inline, hasAction)=>{
@@ -112,10 +113,17 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
112
113
  actionName
113
114
  };
114
115
  };
116
+ const reserveRouteVarName = (preferred)=>{
117
+ let candidate = preferred;
118
+ let suffix = 1;
119
+ while(usedRouteVarNames.has(candidate))candidate = `${preferred}_${suffix++}`;
120
+ usedRouteVarNames.add(candidate);
121
+ return candidate;
122
+ };
115
123
  const createRouteVarName = (route)=>{
116
124
  const id = route.id;
117
125
  const base = id ? makeLegalIdentifier(id) : `r_${routeIndex++}`;
118
- return `route_${base}`;
126
+ return reserveRouteVarName(`route_${base}`);
119
127
  };
120
128
  const buildRoute = async (opts)=>{
121
129
  const { parentVar, route } = opts;
@@ -144,14 +152,16 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
144
152
  actionName
145
153
  });
146
154
  if (staticDataSnippet) routeOpts.push(staticDataSnippet);
147
- statements.push(`const ${varName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
148
155
  const children = route.children;
156
+ const hasChildren = Boolean(children && children.length > 0);
157
+ const routeCtorVarName = hasChildren ? reserveRouteVarName(`${varName}__base`) : varName;
158
+ statements.push(`const ${routeCtorVarName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
149
159
  if (children && children.length > 0) {
150
160
  const childVars = await Promise.all(children.map((child)=>buildRoute({
151
- parentVar: varName,
161
+ parentVar: routeCtorVarName,
152
162
  route: child
153
163
  })));
154
- statements.push(`${varName}.addChildren([${childVars.join(', ')}]);`);
164
+ statements.push(`const ${varName} = ${routeCtorVarName}.addChildren([${childVars.join(', ')}]);`);
155
165
  }
156
166
  return varName;
157
167
  };
@@ -224,7 +234,11 @@ function createRouteStaticData(opts: {
224
234
  modernRouteAction?: unknown;
225
235
  modernRouteLoader?: unknown;
226
236
  }) {
227
- const staticData: Record<string, unknown> = {};
237
+ const staticData: {
238
+ modernRouteId?: string;
239
+ modernRouteAction?: unknown;
240
+ modernRouteLoader?: unknown;
241
+ } = {};
228
242
 
229
243
  if (opts.modernRouteId) {
230
244
  staticData.modernRouteId = opts.modernRouteId;
@@ -238,7 +252,7 @@ function createRouteStaticData(opts: {
238
252
  staticData.modernRouteAction = opts.modernRouteAction;
239
253
  }
240
254
 
241
- return Object.keys(staticData).length > 0 ? staticData : undefined;
255
+ return staticData;
242
256
  }
243
257
 
244
258
  function modernLoaderToTanstack<TLoader extends (args: any) => any>(
@@ -9,6 +9,7 @@ import { onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBefo
9
9
  import { applyRouterRuntimeState } from "../lifecycle.mjs";
10
10
  import { createRouteObjectsFromConfig, urlJoin } from "../utils.mjs";
11
11
  import { createModernBasepathRewrite } from "./basepathRewrite.mjs";
12
+ import { Link } from "./prefetchLink.mjs";
12
13
  import { createRouteTreeFromRouteObjects } from "./routeTree.mjs";
13
14
  import { getTanstackRscSerializationAdapters } from "./rsc/client.mjs";
14
15
  import * as __rspack_external_react from "react";
@@ -71,6 +72,7 @@ const tanstackRouterPlugin = (userConfig = {})=>({
71
72
  }
72
73
  }
73
74
  context.router = {
75
+ Link: Link,
74
76
  useMatches: useMatches,
75
77
  useLocation: useLocation,
76
78
  useNavigate: useNavigate,
@@ -1,5 +1,6 @@
1
1
  import "node:module";
2
2
  import { createRootRoute, createRoute, notFound, redirect } from "@tanstack/react-router";
3
+ import { createElement } from "react";
3
4
  import { DefaultNotFound } from "../DefaultNotFound.mjs";
4
5
  function createTanstackRoute(options) {
5
6
  return createRoute(options);
@@ -44,6 +45,33 @@ function isModernDeferredData(value) {
44
45
  function normalizeModernLoaderResult(result) {
45
46
  return isModernDeferredData(result) ? result.data : result;
46
47
  }
48
+ function pickRouteModuleComponent(routeModule) {
49
+ if ('function' == typeof routeModule || routeModule && 'object' == typeof routeModule && '$$typeof' in routeModule) return routeModule;
50
+ if (!routeModule || 'object' != typeof routeModule) return;
51
+ const module = routeModule;
52
+ const component = module.default || module.Component;
53
+ if ('function' == typeof component || component && 'object' == typeof component && '$$typeof' in component) return component;
54
+ }
55
+ function createServerLazyImportComponent(lazyImport, fallbackComponent) {
56
+ if ("u" > typeof document) return fallbackComponent;
57
+ let resolvedComponent;
58
+ let pendingLoad;
59
+ const load = async ()=>{
60
+ if (resolvedComponent) return resolvedComponent;
61
+ const routeModule = await lazyImport();
62
+ const component = pickRouteModuleComponent(routeModule);
63
+ if (component) resolvedComponent = component;
64
+ return resolvedComponent;
65
+ };
66
+ const Component = (props)=>{
67
+ if (resolvedComponent) return createElement(resolvedComponent, props);
68
+ pendingLoad ||= load();
69
+ throw pendingLoad;
70
+ };
71
+ Component.load = load;
72
+ Component.preload = load;
73
+ return Component;
74
+ }
47
75
  function throwTanstackRedirect(location) {
48
76
  const target = location || '/';
49
77
  try {
@@ -210,10 +238,18 @@ function wrapRouteObjectLoader(route, revalidationState) {
210
238
  }
211
239
  function toRouteComponent(routeObject) {
212
240
  const route = routeObject;
241
+ const lazyImport = 'function' == typeof route.lazyImport ? route.lazyImport : void 0;
242
+ const fallbackComponent = route.Component ? route.Component : route.element ? ()=>route.element : void 0;
243
+ if (lazyImport && fallbackComponent) return createServerLazyImportComponent(lazyImport, fallbackComponent);
213
244
  if (route.Component) return route.Component;
214
245
  const element = route.element;
215
246
  if (element) return ()=>element;
216
247
  }
248
+ function toModernRouteComponent(route) {
249
+ const component = route.component || void 0;
250
+ if ('function' == typeof route.lazyImport && component) return createServerLazyImportComponent(route.lazyImport, component);
251
+ return component;
252
+ }
217
253
  function toErrorComponent(routeObject) {
218
254
  const route = routeObject;
219
255
  if (route.ErrorBoundary) return route.ErrorBoundary;
@@ -293,7 +329,7 @@ function createRouteFromModernRoute(opts) {
293
329
  const stableFallbackId = modernId || route._component || route.filename || route.data || ('function' == typeof route.loader ? route.id : void 0);
294
330
  const pendingComponent = route.loading || route.pendingComponent;
295
331
  const errorComponent = route.error || route.errorComponent;
296
- const component = route.component;
332
+ const component = toModernRouteComponent(route);
297
333
  const modernLoader = route.loader;
298
334
  const modernAction = route.action;
299
335
  const modernShouldRevalidate = route.shouldRevalidate;
@@ -339,7 +375,7 @@ function createRouteFromModernRoute(opts) {
339
375
  }
340
376
  function createRouteTreeFromModernRoutes(routes) {
341
377
  const rootModern = routes.find((r)=>r && 'nested' === r.type && r.isRoot);
342
- const rootComponent = rootModern?.component;
378
+ const rootComponent = rootModern ? toModernRouteComponent(rootModern) : void 0;
343
379
  const pendingComponent = rootModern?.loading;
344
380
  const errorComponent = rootModern?.error;
345
381
  const rootLoader = rootModern?.loader;
@@ -0,0 +1,2 @@
1
+ import "node:module";
2
+ export * from "@modern-js/render/rsc-worker";
@@ -0,0 +1 @@
1
+ export * from '@modern-js/runtime-utils/cache';
@@ -0,0 +1,7 @@
1
+ import type { Entrypoint } from '@modern-js/types';
2
+ import type { RsbuildPlugin } from '@rsbuild/core';
3
+ export declare const builderPluginAlias: ({ entrypoints, internalDirectory, metaName, }: {
4
+ entrypoints: Entrypoint[];
5
+ internalDirectory: string;
6
+ metaName: string;
7
+ }) => RsbuildPlugin;
@@ -0,0 +1,3 @@
1
+ import type { AppToolsContext, AppToolsFeatureHooks, AppToolsNormalizedConfig } from '@modern-js/app-tools';
2
+ import type { Entrypoint } from '@modern-js/types';
3
+ export declare const generateCode: (entrypoints: Entrypoint[], appContext: AppToolsContext, config: AppToolsNormalizedConfig, hooks: AppToolsFeatureHooks) => Promise<void>;
@@ -0,0 +1,9 @@
1
+ export declare const APP_FILE_NAME = "App";
2
+ export declare const ENTRY_POINT_FILE_NAME = "index.jsx";
3
+ export declare const SERVER_ENTRY_POINT_FILE_NAME = "index.server.jsx";
4
+ export declare const INDEX_FILE_NAME = "index";
5
+ export declare const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
6
+ export declare const ENTRY_SERVER_BOOTSTRAP_FILE_NAME = "bootstrap.server.jsx";
7
+ export declare const ENTRY_POINT_RUNTIME_REGISTER_FILE_NAME = "runtime-register.js";
8
+ export declare const ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME = "runtime-global-context";
9
+ export declare const ENTRY_POINT_REGISTER_FILE_NAME = "register.js";
@@ -0,0 +1,2 @@
1
+ export declare const hasApp: (dir: string) => any;
2
+ export declare const isRuntimeEntry: (dir: string) => any;
@@ -0,0 +1,11 @@
1
+ import type { AppTools, CliPlugin } from '@modern-js/app-tools';
2
+ import { documentPlugin } from '../document/cli';
3
+ import { routerPlugin } from '../router/cli';
4
+ import { ssrPlugin } from './ssr';
5
+ export { getEntrypointRoutesDir, handleFileChange, handleGeneratorEntryCode, handleModifyEntrypoints, isRouteEntry, } from '../router/cli';
6
+ export { isRuntimeEntry } from './entry';
7
+ export { documentPlugin, routerPlugin, ssrPlugin };
8
+ export declare const runtimePlugin: (params?: {
9
+ plugins?: CliPlugin<AppTools>[];
10
+ }) => CliPlugin<AppTools>;
11
+ export default runtimePlugin;
@@ -0,0 +1,6 @@
1
+ import type { AppTools, CliPlugin } from '@modern-js/app-tools';
2
+ import type { MergedEnvironmentConfig } from '@rsbuild/core';
3
+ type EnvironmentConfigLike = Partial<Pick<MergedEnvironmentConfig, 'output' | 'source' | 'tools'>>;
4
+ export declare const shouldUseModuleFederationNodeOutput: (config: EnvironmentConfigLike) => boolean;
5
+ export declare const ssrPlugin: () => CliPlugin<AppTools>;
6
+ export default ssrPlugin;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The following code is modified based on
3
+ * https://github.com/gregberge/loadable-components
4
+ *
5
+ * MIT Licensed
6
+ * Author Greg Bergé
7
+ * Copyright 2019 Greg Bergé
8
+ * https://github.com/gregberge/loadable-components/blob/main/LICENSE
9
+ */
10
+ import type { Rspack } from '@modern-js/app-tools';
11
+ interface LoadablePluginOptions {
12
+ filename: string;
13
+ path?: string;
14
+ writeToDisk?: any;
15
+ outputAsset?: boolean;
16
+ chunkLoadingGlobal?: string;
17
+ }
18
+ type Compiler = Rspack.Compiler;
19
+ type Compilation = Rspack.Compilation;
20
+ declare class LoadablePlugin {
21
+ opts: LoadablePluginOptions;
22
+ compiler: Compiler | null;
23
+ constructor({ filename, path, writeToDisk, outputAsset, chunkLoadingGlobal, }?: LoadablePluginOptions);
24
+ apply(compiler: Compiler): void;
25
+ handleEmit(compilation: Compilation): {
26
+ source(): string;
27
+ size(): number;
28
+ } | null;
29
+ writeAssetsFile(manifest: string): void;
30
+ }
31
+ export default LoadablePlugin;
@@ -0,0 +1,15 @@
1
+ import type { AppToolsNormalizedConfig } from '@modern-js/app-tools';
2
+ export type SSRMode = 'string' | 'stream' | false;
3
+ /**
4
+ * Unified SSR mode resolution function.
5
+ * Priority:
6
+ * 1. If SSG is enabled, use SSG configuration (SSG takes precedence over SSR when both are configured)
7
+ * 2. User's explicit server.ssr/server.ssrByEntries config
8
+ * 3. Otherwise return false (no SSR)
9
+ */
10
+ export declare function resolveSSRMode(params: {
11
+ entry?: string;
12
+ config: AppToolsNormalizedConfig;
13
+ appDirectory?: string;
14
+ nestedRoutesEntry?: string;
15
+ }): SSRMode;
@@ -0,0 +1,50 @@
1
+ import type { RuntimePluginConfig } from '@modern-js/app-tools';
2
+ export declare const entryForCSRWithRSC: ({ metaName, entryName, urlPath, mountId, isNestedRouter, }: {
3
+ metaName: string;
4
+ entryName: string;
5
+ urlPath?: string;
6
+ mountId?: string;
7
+ isNestedRouter?: string;
8
+ }) => string;
9
+ export declare const index: ({ srcDirectory, internalSrcAlias, metaName, entry, entryName, customEntry, mountId, enableRsc, isNestedRouter, }: {
10
+ srcDirectory: string;
11
+ internalSrcAlias: string;
12
+ metaName: string;
13
+ entry: string;
14
+ entryName: string;
15
+ customEntry?: boolean;
16
+ mountId?: string;
17
+ enableRsc?: boolean;
18
+ isNestedRouter?: boolean;
19
+ }) => string;
20
+ export declare const register: () => string;
21
+ export declare const runtimeRegister: ({ entryName, srcDirectory, internalSrcAlias, metaName, runtimeConfigFile, runtimePlugins, }: {
22
+ entryName: string;
23
+ srcDirectory: string;
24
+ internalSrcAlias: string;
25
+ metaName: string;
26
+ runtimeConfigFile: string | false;
27
+ runtimePlugins: RuntimePluginConfig[];
28
+ }) => string;
29
+ export declare const runtimeGlobalContext: ({ entryName, srcDirectory, internalSrcAlias, metaName, entry, customEntry, basename, }: {
30
+ entryName: string;
31
+ srcDirectory: string;
32
+ internalSrcAlias: string;
33
+ metaName: string;
34
+ entry: string;
35
+ customEntry?: boolean;
36
+ basename?: string;
37
+ }) => string;
38
+ export declare const runtimeGlobalContextForRSCServer: ({ metaName, }: {
39
+ metaName: string;
40
+ }) => string;
41
+ export declare const runtimeGlobalContextForRSCClient: ({ metaName, customEntry, }: {
42
+ metaName: string;
43
+ customEntry?: boolean;
44
+ }) => string;
45
+ export declare const AppProxyForRSC: ({ srcDirectory, internalSrcAlias, entry, customEntry, }: {
46
+ srcDirectory: string;
47
+ internalSrcAlias: string;
48
+ entry: string;
49
+ customEntry?: boolean;
50
+ }) => string;
@@ -0,0 +1,20 @@
1
+ type ServerIndexOptinos = GenHandlerCodeOptions & {
2
+ entryName: string;
3
+ };
4
+ export declare const serverIndex: (options: ServerIndexOptinos) => string;
5
+ export declare const entryForCSRWithRSC: ({ metaName, entryName, }: {
6
+ metaName: string;
7
+ entryName: string;
8
+ }) => string;
9
+ type GenHandlerCodeOptions = {
10
+ customServerEntry?: string | false;
11
+ srcDirectory: string;
12
+ internalSrcAlias: string;
13
+ entry: string;
14
+ enableRsc?: boolean;
15
+ } & TransformServerEntryOptions;
16
+ type TransformServerEntryOptions = {
17
+ metaName?: string;
18
+ mode: 'string' | 'stream';
19
+ };
20
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { RuntimePlugin } from './core/plugin';
2
+ export declare const isBrowser: () => boolean;
3
+ export interface RuntimeConfig {
4
+ plugins?: RuntimePlugin[];
5
+ [key: string]: any;
6
+ }
7
+ export declare const JSX_SHELL_STREAM_END_MARK = "<!--<?- SHELL_STREAM_END ?>-->";
8
+ export declare const ESCAPED_SHELL_STREAM_END_MARK = "&lt;!--&lt;?- SHELL_STREAM_END ?&gt;--&gt;";
@@ -0,0 +1,5 @@
1
+ import type React from 'react';
2
+ import type { Root } from 'react-dom/client';
3
+ import type { TRuntimeContext } from '../context/runtime';
4
+ export declare const isReact18: () => boolean;
5
+ export declare function hydrateRoot(App: React.ReactElement, context: TRuntimeContext, ModernRender: (App: React.ReactElement) => Promise<HTMLElement | Root>, ModernHydrate: (App: React.ReactElement, callback?: () => void) => Promise<HTMLElement | Root>): Promise<HTMLElement | Root>;
@@ -0,0 +1,9 @@
1
+ import type React from 'react';
2
+ export type RenderFunc = typeof render;
3
+ export declare function render(App: React.ReactElement<{
4
+ basename: string;
5
+ }>, id?: HTMLElement | string): Promise<HTMLElement | import("react-dom/client").Root>;
6
+ export declare function renderWithReact18(App: React.ReactElement, rootElement: HTMLElement): Promise<import("react-dom/client").Root>;
7
+ export declare function renderWithReact17(App: React.ReactElement, rootElement: HTMLElement): Promise<HTMLElement>;
8
+ export declare function hydrateWithReact18(App: React.ReactElement, rootElement: HTMLElement): Promise<import("react-dom/client").Root>;
9
+ export declare function hydrateWithReact17(App: React.ReactElement, rootElement: HTMLElement, callback?: () => void): Promise<any>;
@@ -0,0 +1,5 @@
1
+ import type React from 'react';
2
+ export declare const WithCallback: React.FC<{
3
+ callback: () => void;
4
+ children: React.ReactElement;
5
+ }>;
@@ -0,0 +1,4 @@
1
+ import type { TInternalRuntimeContext } from '../context';
2
+ export declare function transformHookRunner(hookRunnerName: string): string;
3
+ export declare function handleSetupResult(setupResult: Record<string, (...args: any) => any>, api: Record<string, any>): void;
4
+ export declare function getHookRunners(runtimeContext: TInternalRuntimeContext): Record<string, any>;
@@ -0,0 +1,2 @@
1
+ import type { RuntimePlugin } from '../plugin/types';
2
+ export declare const compatPlugin: () => RuntimePlugin;
@@ -0,0 +1,5 @@
1
+ import type { TInternalRuntimeContext } from '../context';
2
+ import type { RuntimePlugin } from '../plugin/types';
3
+ import type { RequestContext } from '../types';
4
+ export declare const makeRequestContext: (context: TInternalRuntimeContext) => RequestContext;
5
+ export declare const requestContextPlugin: () => RuntimePlugin;