@bleedingdev/modern-js-runtime 3.5.0-ultramodern.98 → 3.8.1-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 (86) hide show
  1. package/dist/cjs/cli/index.js +1 -11
  2. package/dist/cjs/cli/ssr/index.js +1 -0
  3. package/dist/cjs/core/browser/hydrate.js +31 -27
  4. package/dist/cjs/core/browser/index.js +4 -15
  5. package/dist/cjs/core/react/wrapper.js +23 -28
  6. package/dist/cjs/core/server/requestResponse.js +5 -5
  7. package/dist/cjs/core/server/scriptOrder.js +1 -1
  8. package/dist/cjs/core/server/stream/beforeTemplate.worker.js +1 -10
  9. package/dist/cjs/core/server/string/index.js +3 -3
  10. package/dist/cjs/core/server/utils.js +3 -3
  11. package/dist/cjs/document/cli/index.js +5 -2
  12. package/dist/cjs/module-federation/distributed-ssr.js +13 -12
  13. package/dist/cjs/module-federation/last-known-good.js +1 -1
  14. package/dist/cjs/module-federation/manifest-recovery-runtime-plugin.js +27 -38
  15. package/dist/cjs/router/cli/code/index.js +16 -9
  16. package/dist/cjs/router/cli/code/templates.js +36 -27
  17. package/dist/cjs/router/cli/handler.js +7 -1
  18. package/dist/cjs/router/runtime/plugin.js +22 -17
  19. package/dist/cjs/router/runtime/plugin.node.js +11 -3
  20. package/dist/cjs/router/runtime/provider.js +2 -2
  21. package/dist/cjs/router/runtime/redirect.js +51 -0
  22. package/dist/cjs/router/runtime/routerHelper.js +4 -0
  23. package/dist/cjs/router/runtime/rsc-router.js +2 -13
  24. package/dist/cjs/router/runtime/utils.js +3 -2
  25. package/dist/esm/cli/index.mjs +2 -12
  26. package/dist/esm/cli/ssr/index.mjs +1 -0
  27. package/dist/esm/core/browser/hydrate.mjs +30 -22
  28. package/dist/esm/core/browser/index.mjs +5 -13
  29. package/dist/esm/core/react/wrapper.mjs +23 -28
  30. package/dist/esm/core/server/requestResponse.mjs +4 -4
  31. package/dist/esm/core/server/scriptOrder.mjs +1 -1
  32. package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +1 -10
  33. package/dist/esm/core/server/string/index.mjs +3 -3
  34. package/dist/esm/core/server/utils.mjs +1 -1
  35. package/dist/esm/document/cli/index.mjs +1 -1
  36. package/dist/esm/module-federation/distributed-ssr.mjs +13 -12
  37. package/dist/esm/module-federation/last-known-good.mjs +1 -1
  38. package/dist/esm/module-federation/manifest-recovery-runtime-plugin.mjs +22 -33
  39. package/dist/esm/router/cli/code/index.mjs +16 -9
  40. package/dist/esm/router/cli/code/templates.mjs +36 -27
  41. package/dist/esm/router/cli/handler.mjs +7 -1
  42. package/dist/esm/router/runtime/plugin.mjs +24 -19
  43. package/dist/esm/router/runtime/plugin.node.mjs +12 -4
  44. package/dist/esm/router/runtime/provider.mjs +2 -2
  45. package/dist/esm/router/runtime/redirect.mjs +13 -0
  46. package/dist/esm/router/runtime/routerHelper.mjs +2 -1
  47. package/dist/esm/router/runtime/rsc-router.mjs +2 -13
  48. package/dist/esm/router/runtime/utils.mjs +2 -1
  49. package/dist/esm-node/cli/index.mjs +2 -12
  50. package/dist/esm-node/cli/ssr/index.mjs +1 -0
  51. package/dist/esm-node/core/browser/hydrate.mjs +30 -22
  52. package/dist/esm-node/core/browser/index.mjs +5 -13
  53. package/dist/esm-node/core/react/wrapper.mjs +23 -28
  54. package/dist/esm-node/core/server/requestResponse.mjs +4 -4
  55. package/dist/esm-node/core/server/scriptOrder.mjs +1 -1
  56. package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +1 -10
  57. package/dist/esm-node/core/server/string/index.mjs +3 -3
  58. package/dist/esm-node/core/server/utils.mjs +1 -1
  59. package/dist/esm-node/document/cli/index.mjs +1 -1
  60. package/dist/esm-node/module-federation/distributed-ssr.mjs +13 -12
  61. package/dist/esm-node/module-federation/last-known-good.mjs +1 -1
  62. package/dist/esm-node/module-federation/manifest-recovery-runtime-plugin.mjs +22 -33
  63. package/dist/esm-node/router/cli/code/index.mjs +16 -9
  64. package/dist/esm-node/router/cli/code/templates.mjs +36 -27
  65. package/dist/esm-node/router/cli/handler.mjs +7 -1
  66. package/dist/esm-node/router/runtime/plugin.mjs +24 -19
  67. package/dist/esm-node/router/runtime/plugin.node.mjs +12 -4
  68. package/dist/esm-node/router/runtime/provider.mjs +2 -2
  69. package/dist/esm-node/router/runtime/redirect.mjs +14 -0
  70. package/dist/esm-node/router/runtime/routerHelper.mjs +2 -1
  71. package/dist/esm-node/router/runtime/rsc-router.mjs +2 -13
  72. package/dist/esm-node/router/runtime/utils.mjs +2 -1
  73. package/dist/types/core/browser/hydrate.d.ts +0 -1
  74. package/dist/types/core/browser/index.d.ts +0 -1
  75. package/dist/types/core/server/utils.d.ts +1 -1
  76. package/dist/types/document/cli/index.d.ts +1 -0
  77. package/dist/types/module-federation/distributed-ssr.d.ts +3 -3
  78. package/dist/types/module-federation/manifest-recovery-runtime-plugin.d.ts +1 -1
  79. package/dist/types/router/cli/code/index.d.ts +6 -1
  80. package/dist/types/router/cli/code/templates.d.ts +8 -3
  81. package/dist/types/router/cli/handler.d.ts +4 -0
  82. package/dist/types/router/runtime/redirect.d.ts +1 -0
  83. package/dist/types/router/runtime/routerHelper.d.ts +7 -0
  84. package/dist/types/router/runtime/rsc-router.d.ts +1 -2
  85. package/package.json +15 -14
  86. package/rstest.config.mts +2 -0
@@ -112,12 +112,10 @@ const runtimePlugin = (params)=>({
112
112
  });
113
113
  api.config(()=>{
114
114
  const { appDirectory, metaName } = api.getAppContext();
115
- const isReact18 = (0, utils_namespaceObject.isReact18)(appDirectory);
116
- process.env.IS_REACT18 = isReact18.toString();
117
115
  return {
118
116
  source: {
119
117
  globalVars: {
120
- 'process.env.IS_REACT18': process.env.IS_REACT18
118
+ 'process.env.IS_REACT18': 'true'
121
119
  },
122
120
  include: [
123
121
  new RegExp(`[\\\\/]node_modules[\\\\/]@${metaName}[\\\\/]runtime[\\\\/].*[\\\\/]head\\.`)
@@ -126,14 +124,6 @@ const runtimePlugin = (params)=>({
126
124
  tools: {
127
125
  bundlerChain: (chain)=>{
128
126
  chain.module.rule('modern-entry').test(/\.jsx?$/).include.add(external_path_default().resolve(appDirectory, 'node_modules', `.${metaName}`)).end().sideEffects(true);
129
- },
130
- rspack: (_config, { appendPlugins, rspack })=>{
131
- if (!isReact18) appendPlugins([
132
- new rspack.IgnorePlugin({
133
- resourceRegExp: /^react-dom\/client$/,
134
- contextRegExp: /@modern-js\/runtime/
135
- })
136
- ]);
137
127
  }
138
128
  }
139
129
  };
@@ -151,6 +151,7 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
151
151
  'process.env.MODERN_SSR_ENV': JSON.stringify(ssrEnv),
152
152
  'process.env.MODERN_ENABLE_HYDRATION': JSON.stringify((0, utils_namespaceObject.isUseSSRBundle)(userConfig)),
153
153
  'process.env.MODERN_ENABLE_RSC': JSON.stringify(Boolean(userConfig.server?.rsc)),
154
+ __MODERN_ENABLE_RSC__: JSON.stringify(Boolean(userConfig.server?.rsc)),
154
155
  'process.env.MODERN_MF_APP_SSR': JSON.stringify(isModuleFederationAppSSR)
155
156
  }
156
157
  },
@@ -29,8 +29,7 @@ var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
31
  hydrateRoot: ()=>hydrateRoot,
32
- hydrateWithReact: ()=>hydrateWithReact,
33
- isReact18: ()=>isReact18
32
+ hydrateWithReact: ()=>hydrateWithReact
34
33
  });
35
34
  const jsx_runtime_namespaceObject = require("react/jsx-runtime");
36
35
  const component_namespaceObject = require("@loadable/component");
@@ -39,15 +38,23 @@ const client_namespaceObject = require("react-dom/client");
39
38
  const external_constants_js_namespaceObject = require("../constants.js");
40
39
  const wrapper_js_namespaceObject = require("../react/wrapper.js");
41
40
  const external_withCallback_js_namespaceObject = require("./withCallback.js");
42
- const isReact18 = ()=>'true' === process.env.IS_REACT18;
43
41
  const runtimeProcess = Reflect.get(globalThis, 'process');
42
+ const runtimeEnvironment = null !== runtimeProcess && 'object' == typeof runtimeProcess ? Reflect.get(runtimeProcess, 'env') : void 0;
43
+ const readRuntimeEnvironment = (name)=>{
44
+ if (null === runtimeEnvironment || 'object' != typeof runtimeEnvironment) return;
45
+ const value = Reflect.get(runtimeEnvironment, name);
46
+ return 'string' == typeof value ? value : void 0;
47
+ };
44
48
  const loadableReadyOptions = {
45
- chunkLoadingGlobal: runtimeProcess?.env?.MODERN_CHUNK_LOADING_GLOBAL || '__LOADABLE_LOADED_CHUNKS__'
49
+ chunkLoadingGlobal: (()=>{
50
+ const configured = readRuntimeEnvironment('MODERN_CHUNK_LOADING_GLOBAL');
51
+ return void 0 === configured || '' === configured ? '__LOADABLE_LOADED_CHUNKS__' : configured;
52
+ })()
46
53
  };
47
- async function hydrateWithReact(App, rootElement) {
48
- return (0, client_namespaceObject.hydrateRoot)(rootElement, App, {
54
+ function hydrateWithReact(App, rootElement) {
55
+ return Promise.resolve((0, client_namespaceObject.hydrateRoot)(rootElement, App, {
49
56
  identifierPrefix: constants_namespaceObject.SSR_HYDRATION_ID_PREFIX
50
- });
57
+ }));
51
58
  }
52
59
  function hydrateRoot(App, context, ModernRender, ModernHydrate) {
53
60
  const hydrateContext = {
@@ -60,9 +67,9 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
60
67
  const callback = ()=>{
61
68
  delete hydrateContext._hydration;
62
69
  };
63
- const renderLevel = window?._SSR_DATA?.renderLevel || external_constants_js_namespaceObject.RenderLevel.CLIENT_RENDER;
64
- const renderMode = window?._SSR_DATA?.mode || 'string';
65
- if (isReact18() && 'stream' === renderMode) return streamSSRHydrate();
70
+ const renderLevel = window?._SSR_DATA?.renderLevel ?? external_constants_js_namespaceObject.RenderLevel.CLIENT_RENDER;
71
+ const renderMode = window?._SSR_DATA?.mode ?? 'string';
72
+ if ('stream' === renderMode) return streamSSRHydrate();
66
73
  function streamSSRHydrate() {
67
74
  if (renderLevel !== external_constants_js_namespaceObject.RenderLevel.SERVER_RENDER) return ModernRender((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, context));
68
75
  {
@@ -76,33 +83,30 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
76
83
  return stringSSRHydrate();
77
84
  function stringSSRHydrate() {
78
85
  if (renderLevel === external_constants_js_namespaceObject.RenderLevel.CLIENT_RENDER) return ModernRender((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, context));
79
- if (renderLevel === external_constants_js_namespaceObject.RenderLevel.SERVER_RENDER) return new Promise((resolve)=>{
80
- if (isReact18()) (0, component_namespaceObject.loadableReady)(()=>{
86
+ {
87
+ if (renderLevel === external_constants_js_namespaceObject.RenderLevel.SERVER_RENDER) return (0, component_namespaceObject.loadableReady)(()=>void 0, loadableReadyOptions).then(()=>{
81
88
  const SSRApp = ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_withCallback_js_namespaceObject.WithCallback, {
82
89
  callback: callback,
83
90
  children: App
84
91
  });
85
- ModernHydrate((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SSRApp, {}), hydrateContext)).then((root)=>{
86
- resolve(root);
87
- });
88
- }, loadableReadyOptions);
89
- else (0, component_namespaceObject.loadableReady)(()=>{
90
- ModernHydrate((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, hydrateContext), callback).then((root)=>{
91
- resolve(root);
92
- });
93
- }, loadableReadyOptions);
94
- });
95
- console.warn(`unknow render level: ${renderLevel}, execute render()`);
96
- return ModernRender((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, context));
92
+ return ModernHydrate((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SSRApp, {}), hydrateContext));
93
+ });
94
+ const runtimeConsole = Reflect.get(globalThis, 'console');
95
+ if (null !== runtimeConsole && 'object' == typeof runtimeConsole) {
96
+ const warn = Reflect.get(runtimeConsole, 'warn');
97
+ if ('function' == typeof warn) Reflect.apply(warn, runtimeConsole, [
98
+ `unknow render level: ${renderLevel}, execute render()`
99
+ ]);
100
+ }
101
+ return ModernRender((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, context));
102
+ }
97
103
  }
98
104
  }
99
105
  exports.hydrateRoot = __webpack_exports__.hydrateRoot;
100
106
  exports.hydrateWithReact = __webpack_exports__.hydrateWithReact;
101
- exports.isReact18 = __webpack_exports__.isReact18;
102
107
  for(var __rspack_i in __webpack_exports__)if (-1 === [
103
108
  "hydrateRoot",
104
- "hydrateWithReact",
105
- "isReact18"
109
+ "hydrateWithReact"
106
110
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
107
111
  Object.defineProperty(exports, '__esModule', {
108
112
  value: true
@@ -31,13 +31,12 @@ __webpack_require__.d(__webpack_exports__, {
31
31
  createNestedAppRenderer: ()=>createNestedAppRenderer,
32
32
  hydrateWithReact: ()=>external_hydrate_js_namespaceObject.hydrateWithReact,
33
33
  hydrateWithReact17: ()=>hydrateWithReact17,
34
- hydrateWithReact18: ()=>hydrateWithReact18,
35
34
  render: ()=>render,
36
35
  renderWithReact17: ()=>renderWithReact17,
37
36
  renderWithReact18: ()=>renderWithReact18
38
37
  });
39
- const constants_namespaceObject = require("@modern-js/utils/universal/constants");
40
38
  const external_cookie_namespaceObject = require("cookie");
39
+ const client_namespaceObject = require("react-dom/client");
41
40
  const index_js_namespaceObject = require("../context/index.js");
42
41
  const runtime_js_namespaceObject = require("../context/runtime.js");
43
42
  const wrapper_js_namespaceObject = require("../react/wrapper.js");
@@ -107,8 +106,8 @@ async function renderApp(App, id, hydrateFromSsrData, internalRuntimeContext) {
107
106
  return renderFunc(App, rootElement);
108
107
  }
109
108
  async function ModernHydrate(App, callback) {
110
- const hydrateFunc = IS_REACT18 ? hydrateWithReact18 : hydrateWithReact17;
111
- return hydrateFunc(App, rootElement, callback);
109
+ if (IS_REACT18) return (0, external_hydrate_js_namespaceObject.hydrateWithReact)(App, rootElement);
110
+ return hydrateWithReact17(App, rootElement, callback);
112
111
  }
113
112
  if (hydrateFromSsrData && process.env.MODERN_ENABLE_HYDRATION && window._SSR_DATA) return (0, external_hydrate_js_namespaceObject.hydrateRoot)(App, context, ModernRender, ModernHydrate);
114
113
  return ModernRender((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, context));
@@ -123,8 +122,7 @@ function createNestedAppRenderer() {
123
122
  return (App, id)=>renderApp(App, id, false, internalRuntimeContext);
124
123
  }
125
124
  async function renderWithReact18(App, rootElement) {
126
- const ReactDOM = await import("react-dom/client");
127
- const root = ReactDOM.createRoot(rootElement);
125
+ const root = (0, client_namespaceObject.createRoot)(rootElement);
128
126
  root.render(App);
129
127
  return root;
130
128
  }
@@ -133,13 +131,6 @@ async function renderWithReact17(App, rootElement) {
133
131
  ReactDOM.render(App, rootElement);
134
132
  return rootElement;
135
133
  }
136
- async function hydrateWithReact18(App, rootElement) {
137
- const ReactDOM = await import("react-dom/client");
138
- const root = ReactDOM.hydrateRoot(rootElement, App, {
139
- identifierPrefix: constants_namespaceObject.SSR_HYDRATION_ID_PREFIX
140
- });
141
- return root;
142
- }
143
134
  async function hydrateWithReact17(App, rootElement, callback) {
144
135
  const ReactDOM = await import("react-dom");
145
136
  const root = ReactDOM.hydrate(App, rootElement, callback);
@@ -148,7 +139,6 @@ async function hydrateWithReact17(App, rootElement, callback) {
148
139
  exports.createNestedAppRenderer = __webpack_exports__.createNestedAppRenderer;
149
140
  exports.hydrateWithReact = __webpack_exports__.hydrateWithReact;
150
141
  exports.hydrateWithReact17 = __webpack_exports__.hydrateWithReact17;
151
- exports.hydrateWithReact18 = __webpack_exports__.hydrateWithReact18;
152
142
  exports.render = __webpack_exports__.render;
153
143
  exports.renderWithReact17 = __webpack_exports__.renderWithReact17;
154
144
  exports.renderWithReact18 = __webpack_exports__.renderWithReact18;
@@ -156,7 +146,6 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
156
146
  "createNestedAppRenderer",
157
147
  "hydrateWithReact",
158
148
  "hydrateWithReact17",
159
- "hydrateWithReact18",
160
149
  "render",
161
150
  "renderWithReact17",
162
151
  "renderWithReact18"
@@ -35,39 +35,34 @@ const external_react_helmet_async_namespaceObject = require("react-helmet-async"
35
35
  const index_js_namespaceObject = require("../context/index.js");
36
36
  const extensions_js_namespaceObject = require("../context/extensions.js");
37
37
  const helmetContext_js_namespaceObject = require("../context/helmetContext.js");
38
- function toRscSafeRecord(value) {
39
- if (!value || 'object' != typeof value) return value;
40
- return Object.fromEntries(Object.entries(value));
41
- }
42
- function createRscSafeSsrContext(ssrContext) {
43
- if (!ssrContext) return ssrContext;
44
- const { request } = ssrContext;
38
+ function createRscSafeRequestContext(ssrContext) {
39
+ if (void 0 === ssrContext) return {
40
+ request: {},
41
+ response: {
42
+ locals: {}
43
+ }
44
+ };
45
+ const { request, response } = ssrContext;
45
46
  return {
46
- nonce: ssrContext.nonce,
47
- useJsonScript: ssrContext.useJsonScript,
48
- htmlModifiers: [],
49
- baseUrl: ssrContext.baseUrl,
50
- request: request ? {
47
+ request: {
51
48
  url: request.url,
52
49
  userAgent: request.userAgent,
53
50
  cookie: request.cookie,
54
51
  pathname: request.pathname,
55
- query: toRscSafeRecord(request.query),
56
- params: toRscSafeRecord(request.params),
57
- headers: toRscSafeRecord(request.headers),
52
+ query: {
53
+ ...request.query
54
+ },
55
+ params: {
56
+ ...request.params
57
+ },
58
+ headers: {
59
+ ...request.headers
60
+ },
58
61
  host: request.host,
59
62
  referer: request.referer
60
- } : request,
61
- mode: ssrContext.mode,
62
- loaderFailureMode: ssrContext.loaderFailureMode
63
- };
64
- }
65
- function createRscSafeRequestContext(ssrContext) {
66
- const safeSsrContext = createRscSafeSsrContext(ssrContext);
67
- return {
68
- request: safeSsrContext?.request || {},
63
+ },
69
64
  response: {
70
- locals: ssrContext?.response?.locals || {}
65
+ locals: response.locals ?? {}
71
66
  }
72
67
  };
73
68
  }
@@ -83,14 +78,14 @@ function wrapRuntimeContextProvider(App, contextValue) {
83
78
  ...rest
84
79
  };
85
80
  (0, extensions_js_namespaceObject.stripRuntimeContextExtensions)(runtimeContextValue);
86
- if ((0, index_js_namespaceObject.getGlobalEnableRsc)() && !isBrowser) {
81
+ if (true === (0, index_js_namespaceObject.getGlobalEnableRsc)() && false === isBrowser) {
87
82
  const rscSafeRequestContext = createRscSafeRequestContext(ssrContext);
88
83
  const rscInternalContextValue = {
89
84
  ...internalContextValue,
90
85
  context: rscSafeRequestContext,
91
- requestContext: rscSafeRequestContext,
92
- ssrContext: createRscSafeSsrContext(ssrContext)
86
+ requestContext: rscSafeRequestContext
93
87
  };
88
+ delete rscInternalContextValue.ssrContext;
94
89
  const rscRuntimeContextValue = {
95
90
  ...runtimeContextValue,
96
91
  context: rscSafeRequestContext,
@@ -33,12 +33,12 @@ __webpack_require__.d(__webpack_exports__, {
33
33
  finalizeRenderResponse: ()=>finalizeRenderResponse
34
34
  });
35
35
  const lifecycle_js_namespaceObject = require("../../router/runtime/lifecycle.js");
36
- const rsc_router_js_namespaceObject = require("../../router/runtime/rsc-router.js");
36
+ const redirect_js_namespaceObject = require("../../router/runtime/redirect.js");
37
37
  const external_tracer_js_namespaceObject = require("./tracer.js");
38
38
  const isRedirectStatus = (status)=>status >= 300 && status <= 399;
39
39
  const isNullBodyStatus = (status)=>204 === status || 205 === status || 304 === status;
40
40
  const processRedirect = (headers, status, ctx)=>{
41
- if (ctx.enableRsc && ctx.isRSCNavigation) return (0, rsc_router_js_namespaceObject.handleRSCRedirect)(headers, ctx.basename, status);
41
+ if (ctx.enableRsc && ctx.isRSCNavigation) return (0, redirect_js_namespaceObject.handleRSCRedirect)(headers, ctx.basename, status);
42
42
  return new Response(null, {
43
43
  status,
44
44
  headers
@@ -47,12 +47,12 @@ const processRedirect = (headers, status, ctx)=>{
47
47
  const applyRouterSnapshotResult = (context, onError)=>{
48
48
  const routerServerSnapshot = (0, lifecycle_js_namespaceObject.getRouterServerSnapshot)(context);
49
49
  const routerStatusCode = routerServerSnapshot?.statusCode ?? context.routerContext?.statusCode;
50
- if (routerStatusCode && 200 !== routerStatusCode) context.ssrContext?.response.status(routerStatusCode);
50
+ if (void 0 !== routerStatusCode && 0 !== routerStatusCode && !Number.isNaN(routerStatusCode) && 200 !== routerStatusCode) context.ssrContext?.response.status(routerStatusCode);
51
51
  const errors = Object.values(routerServerSnapshot?.errors || context.routerContext?.errors || {});
52
52
  if (errors.length > 0) onError(errors[0], external_tracer_js_namespaceObject.SSRErrors.LOADER_ERROR);
53
53
  };
54
54
  const createLoaderRedirectResponse = (beforeRenderResult, redirectCtx)=>{
55
- if (!beforeRenderResult || !isRedirectStatus(beforeRenderResult.status)) return;
55
+ if (void 0 === beforeRenderResult || !isRedirectStatus(beforeRenderResult.status)) return;
56
56
  if (beforeRenderResult.headers.has('X-Modernjs-Redirect')) return beforeRenderResult;
57
57
  const redirectUrl = beforeRenderResult.headers.get('Location') || '/';
58
58
  return processRedirect(new Headers({
@@ -60,7 +60,7 @@ const createLoaderRedirectResponse = (beforeRenderResult, redirectCtx)=>{
60
60
  }), beforeRenderResult.status, redirectCtx);
61
61
  };
62
62
  const finalizeRenderResponse = (response, responseProxy, redirectCtx, routerCleanup)=>{
63
- if (-1 !== responseProxy.status && isRedirectStatus(responseProxy.status) && responseProxy.headers.Location) return processRedirect(new Headers(responseProxy.headers), responseProxy.status, redirectCtx);
63
+ if (-1 !== responseProxy.status && isRedirectStatus(responseProxy.status) && void 0 !== responseProxy.headers.Location && '' !== responseProxy.headers.Location) return processRedirect(new Headers(responseProxy.headers), responseProxy.status, redirectCtx);
64
64
  Object.entries(responseProxy.headers).forEach(([key, value])=>{
65
65
  response.headers.set(key, value);
66
66
  });
@@ -79,7 +79,7 @@ function getMatchedRouteAssets(runtimeContext, routeManifest) {
79
79
  return matchedRouteIds.flatMap((routeId)=>routeAssets[routeId]?.assets ?? []);
80
80
  }
81
81
  function getMatchedRouteChunks(runtimeContext, routeManifest, routeAssetToChunk) {
82
- if (!routeManifest) return [];
82
+ if (void 0 === routeManifest) return [];
83
83
  return getMatchedRouteAssets(runtimeContext, routeManifest).map(routeAssetToChunk);
84
84
  }
85
85
  const orderHydrationScriptChunks = ({ asyncEntryChunks, collectedChunks, matchedRouteChunks, entryName })=>{
@@ -30,7 +30,6 @@ __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
31
  buildShellBeforeTemplate: ()=>buildShellBeforeTemplate
32
32
  });
33
- const router_namespaceObject = require("@modern-js/runtime-utils/router");
34
33
  const lifecycle_js_namespaceObject = require("../../../router/runtime/lifecycle.js");
35
34
  const external_constants_js_namespaceObject = require("../constants.js");
36
35
  const external_federatedCss_js_namespaceObject = require("../federatedCss.js");
@@ -59,20 +58,12 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
59
58
  });
60
59
  return (0, external_utils_js_namespaceObject.safeReplace)(template, external_constants_js_namespaceObject.CHUNK_CSS_PLACEHOLDER, css);
61
60
  async function getCssChunks() {
62
- const { routeManifest, routerContext, routes } = runtimeContext;
61
+ const { routeManifest } = runtimeContext;
63
62
  const routeAssets = routeManifest?.routeAssets;
64
63
  if (!routeAssets) return '';
65
64
  let matchedRouteManifests = [];
66
65
  const matchedRouteIds = (0, lifecycle_js_namespaceObject.getRouterMatchedRouteIds)(runtimeContext);
67
66
  if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
68
- else if (routerContext && routes) {
69
- const matches = (0, router_namespaceObject.matchRoutes)(routes, routerContext.location, routerContext.basename);
70
- matchedRouteManifests = matches?.map((match, index)=>{
71
- if (!index) return;
72
- const routeId = match.route.id;
73
- if (routeId) return routeAssets[routeId];
74
- }).filter((routeManifest)=>void 0 !== routeManifest) ?? [];
75
- }
76
67
  const asyncEntry = routeAssets[`async-${entryName}`];
77
68
  if (asyncEntry) matchedRouteManifests.push(asyncEntry);
78
69
  const cssChunks = matchedRouteManifests.reduce((chunks, routeManifest)=>{
@@ -127,7 +127,7 @@ async function generateHtml(App, htmlTemplate, chunkSet, collectors, htmlModifie
127
127
  createReplaceHtml(html),
128
128
  createReplaceChunkJs(jsChunk, entryName),
129
129
  createReplaceChunkCss(cssChunk),
130
- createReplaceSSRDataScript(ssrScripts),
130
+ createReplaceSSRDataScript(ssrScripts, entryName),
131
131
  (0, external_helmet_js_namespaceObject.createReplaceHelemt)(helmetData),
132
132
  ...htmlModifiers
133
133
  ]);
@@ -136,8 +136,8 @@ async function generateHtml(App, htmlTemplate, chunkSet, collectors, htmlModifie
136
136
  function createReplaceHtml(html) {
137
137
  return (template)=>(0, external_utils_js_namespaceObject.safeReplace)(template, external_constants_js_namespaceObject_1.HTML_PLACEHOLDER, html);
138
138
  }
139
- function createReplaceSSRDataScript(data) {
140
- return (template)=>(0, external_utils_js_namespaceObject.safeReplace)(template, external_constants_js_namespaceObject_1.SSR_DATA_PLACEHOLDER, data);
139
+ function createReplaceSSRDataScript(data, entryName) {
140
+ return (template)=>(0, external_scriptOrder_js_namespaceObject.replaceChunkJsPlaceholder)(template, data, entryName, external_constants_js_namespaceObject_1.SSR_DATA_PLACEHOLDER);
141
141
  }
142
142
  function createReplaceChunkJs(js, entryName) {
143
143
  return (template)=>(0, external_scriptOrder_js_namespaceObject.replaceChunkJsPlaceholder)(template, js, entryName);
@@ -36,7 +36,7 @@ __webpack_require__.d(__webpack_exports__, {
36
36
  safeReplace: ()=>safeReplace,
37
37
  serializeErrors: ()=>serializeErrors
38
38
  });
39
- const router_namespaceObject = require("@modern-js/runtime-utils/router");
39
+ const routerHelper_js_namespaceObject = require("../../router/runtime/routerHelper.js");
40
40
  function attributesToString(attributes) {
41
41
  return Object.entries(attributes).reduce((str, [key, value])=>void 0 === value ? str : `${str} ${key}="${value}"`, '');
42
42
  }
@@ -50,7 +50,7 @@ function serializeErrors(errors) {
50
50
  if (!errors) return null;
51
51
  const entries = Object.entries(errors);
52
52
  const serialized = {};
53
- for (const [key, val] of entries)if ((0, router_namespaceObject.isRouteErrorResponse)(val)) serialized[key] = serializeRouteErrorResponse(val);
53
+ for (const [key, val] of entries)if ((0, routerHelper_js_namespaceObject.isRouteErrorResponse)(val)) serialized[key] = serializeRouteErrorResponse(val);
54
54
  else if (val instanceof Error) serialized[key] = serializeError(val);
55
55
  else serialized[key] = val;
56
56
  return serialized;
@@ -71,7 +71,7 @@ function serializeError(error) {
71
71
  };
72
72
  }
73
73
  function serializeRouteErrorResponse(error) {
74
- if (!(0, router_namespaceObject.isRouteErrorResponse)(error)) return error;
74
+ if (!(0, routerHelper_js_namespaceObject.isRouteErrorResponse)(error)) return error;
75
75
  if (error.status >= 500 && shouldRedactServerError()) return {
76
76
  status: error.status,
77
77
  statusText: 'Internal Server Error',
@@ -39,7 +39,8 @@ __webpack_require__.r(__webpack_exports__);
39
39
  __webpack_require__.d(__webpack_exports__, {
40
40
  default: ()=>cli,
41
41
  documentPlugin: ()=>documentPlugin,
42
- getDocumentByEntryName: ()=>getDocumentByEntryName
42
+ getDocumentByEntryName: ()=>getDocumentByEntryName,
43
+ processScriptPlaceholders: ()=>processScriptPlaceholders
43
44
  });
44
45
  const utils_namespaceObject = require("@modern-js/utils");
45
46
  const external_entities_namespaceObject = require("entities");
@@ -394,10 +395,12 @@ const cli = documentPlugin;
394
395
  exports["default"] = __webpack_exports__["default"];
395
396
  exports.documentPlugin = __webpack_exports__.documentPlugin;
396
397
  exports.getDocumentByEntryName = __webpack_exports__.getDocumentByEntryName;
398
+ exports.processScriptPlaceholders = __webpack_exports__.processScriptPlaceholders;
397
399
  for(var __rspack_i in __webpack_exports__)if (-1 === [
398
400
  "default",
399
401
  "documentPlugin",
400
- "getDocumentByEntryName"
402
+ "getDocumentByEntryName",
403
+ "processScriptPlaceholders"
401
404
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
402
405
  Object.defineProperty(exports, '__esModule', {
403
406
  value: true
@@ -44,24 +44,24 @@ function distributedSsrFragmentKey(remote, expose) {
44
44
  }
45
45
  function getDistributedSsrFragmentContext(response) {
46
46
  const locals = response?.locals;
47
- if (!locals || 'object' != typeof locals) return;
48
- const context = locals[DISTRIBUTED_SSR_FRAGMENTS_LOCALS_KEY];
49
- if (!context || 'object' != typeof context) return;
47
+ if ('object' != typeof locals || null === locals) return;
48
+ const context = DISTRIBUTED_SSR_FRAGMENTS_LOCALS_KEY in locals ? locals[DISTRIBUTED_SSR_FRAGMENTS_LOCALS_KEY] : void 0;
49
+ if ('object' != typeof context || null === context) return;
50
50
  return context;
51
51
  }
52
52
  function useDistributedSsrFragmentProps({ boundaryId, expose }) {
53
53
  const runtimeContext = (0, runtime_js_namespaceObject.useRuntimeContext)();
54
54
  const locals = runtimeContext.requestContext?.response?.locals;
55
- const request = locals && 'object' == typeof locals ? locals[DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY] : void 0;
56
- if (!request || 'object' != typeof request || request.boundaryId !== boundaryId || request.expose !== expose) throw new Error(`Distributed SSR fragment request contract mismatch for ${boundaryId} ${expose}.`);
57
- const props = request.props;
58
- if (!props || 'object' != typeof props || Array.isArray(props)) throw new Error(`Distributed SSR fragment request props must be an object for ${boundaryId} ${expose}.`);
55
+ const request = 'object' == typeof locals && null !== locals && DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY in locals ? locals[DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY] : void 0;
56
+ if ('object' != typeof request || null === request || !('boundaryId' in request) || request.boundaryId !== boundaryId || !('expose' in request) || request.expose !== expose) throw new Error(`Distributed SSR fragment request contract mismatch for ${boundaryId} ${expose}.`);
57
+ const props = 'props' in request ? request.props : void 0;
58
+ if ('object' != typeof props || null === props || Array.isArray(props)) throw new Error(`Distributed SSR fragment request props must be an object for ${boundaryId} ${expose}.`);
59
59
  return props;
60
60
  }
61
61
  function isThenable(value) {
62
- return 'function' == typeof value.then;
62
+ return void 0 !== value && 'then' in value && 'function' == typeof value.then;
63
63
  }
64
- function DistributedSsrBoundary({ children, expose, fallback, fragmentProps = {}, remote }) {
64
+ function DistributedSsrBoundary({ children, expose, fallback, fragmentProps, remote }) {
65
65
  const runtimeContext = (0, runtime_js_namespaceObject.useRuntimeContext)();
66
66
  const key = distributedSsrFragmentKey(remote, expose);
67
67
  const attributes = {
@@ -72,12 +72,13 @@ function DistributedSsrBoundary({ children, expose, fallback, fragmentProps = {}
72
72
  children: children
73
73
  });
74
74
  const fragmentContext = getDistributedSsrFragmentContext(runtimeContext.requestContext?.response);
75
- if (!fragmentContext) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
75
+ if (void 0 === fragmentContext) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
76
76
  ...attributes,
77
77
  children: children
78
78
  });
79
- const fragmentOrPromise = fragmentContext.resolve?.(remote, expose, fragmentProps) ?? fragmentContext.fragments?.[key];
80
- if (fragmentOrPromise && isThenable(fragmentOrPromise)) throw fragmentOrPromise;
79
+ const resolverFragmentProps = void 0 === fragmentProps ? {} : Object.fromEntries(Object.entries(fragmentProps));
80
+ const fragmentOrPromise = fragmentContext.resolve?.(remote, expose, resolverFragmentProps) ?? fragmentContext.fragments?.[key];
81
+ if (isThenable(fragmentOrPromise)) throw fragmentOrPromise;
81
82
  const fragment = fragmentOrPromise;
82
83
  if (fragment?.status === 'ready') return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
83
84
  ...attributes,
@@ -67,7 +67,7 @@ function staleRecordResult(ref, env, ageMs, maxStaleMs) {
67
67
  }
68
68
  function createLastKnownGoodProvider(options) {
69
69
  const storage = options.storage ?? createInMemoryLkgStorage();
70
- const now = options.now ?? (()=>Date.now());
70
+ const now = options.now ?? (()=>Math.floor(performance.timeOrigin + performance.now()));
71
71
  const maxStaleMs = options.freshness?.maxStaleMs;
72
72
  async function serveFromCache(ref, env, fallback) {
73
73
  const key = (0, external_surface_resolution_types_js_namespaceObject.deliveryUnitResolutionKey)(ref.unitId, env);
@@ -27,6 +27,11 @@ var __webpack_require__ = {};
27
27
  })();
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ createModuleFederationManifestRecoveryPlugin: ()=>createModuleFederationManifestRecoveryPlugin,
32
+ default: ()=>manifest_recovery_runtime_plugin
33
+ });
34
+ const universal_namespaceObject = require("@modern-js/utils/universal");
30
35
  const DEFAULT_ATTEMPTS = 3;
31
36
  const DEFAULT_RETRY_DELAY_MS = 100;
32
37
  const DEFAULT_TIMEOUT_MS = 1000;
@@ -72,7 +77,7 @@ const isRetryableError = (error)=>{
72
77
  return error instanceof TypeError || /(?:fetch failed|network|ECONNREFUSED|ECONNRESET|ETIMEDOUT|EAI_AGAIN)/i.test(message);
73
78
  };
74
79
  const isHttpManifestUrl = (id)=>{
75
- if (!id) return false;
80
+ if (void 0 === id || 0 === id.length) return false;
76
81
  try {
77
82
  const url = new URL(id);
78
83
  return ('http:' === url.protocol || 'https:' === url.protocol) && url.pathname.endsWith('.json');
@@ -80,55 +85,39 @@ const isHttpManifestUrl = (id)=>{
80
85
  return false;
81
86
  }
82
87
  };
83
- const defaultWait = (milliseconds)=>new Promise((resolve)=>{
84
- setTimeout(resolve, milliseconds);
88
+ const defaultWait = (milliseconds)=>(0, universal_namespaceObject.wait)(milliseconds).then(()=>void 0);
89
+ const fetchWithTimeout = (fetchImpl, url, timeoutMs)=>fetchImpl(url, {
90
+ signal: AbortSignal.timeout(timeoutMs)
85
91
  });
86
- const fetchWithTimeout = async (fetchImpl, url, timeoutMs)=>{
87
- const controller = new AbortController();
88
- const timeout = setTimeout(()=>controller.abort(), timeoutMs);
89
- try {
90
- return await fetchImpl(url, {
91
- signal: controller.signal
92
- });
93
- } finally{
94
- clearTimeout(timeout);
95
- }
96
- };
97
92
  const createModuleFederationManifestRecoveryPlugin = (options = {})=>{
98
93
  const attempts = clampInteger(options.attempts, DEFAULT_ATTEMPTS, 1, MAX_ATTEMPTS);
99
94
  const retryDelayMs = clampInteger(options.retryDelayMs, DEFAULT_RETRY_DELAY_MS, 0, MAX_RETRY_DELAY_MS);
100
95
  const timeoutMs = clampInteger(options.timeoutMs, DEFAULT_TIMEOUT_MS, 1, MAX_TIMEOUT_MS);
101
96
  const fetchImpl = options.fetchImpl ?? globalThis.fetch;
102
97
  const waitImpl = options.waitImpl ?? defaultWait;
98
+ const recoverManifest = (url, attempt)=>{
99
+ const fetchManifest = ()=>Promise.resolve().then(()=>fetchWithTimeout(fetchImpl, url, timeoutMs)).then((response)=>{
100
+ if (!response.ok) {
101
+ if (!RETRYABLE_HTTP_STATUSES.has(response.status) || attempt === attempts - 1) return;
102
+ return recoverManifest(url, attempt + 1);
103
+ }
104
+ return Promise.resolve().then(()=>response.json()).then((manifest)=>manifest, ()=>void 0);
105
+ }, (error)=>{
106
+ if (!isRetryableError(error) || attempt === attempts - 1) return;
107
+ return recoverManifest(url, attempt + 1);
108
+ });
109
+ if (attempt > 0 && retryDelayMs > 0) return waitImpl(retryDelayMs).then(fetchManifest);
110
+ return fetchManifest();
111
+ };
103
112
  return {
104
113
  name: 'modern-js-manifest-recovery-plugin',
105
- async errorLoadRemote (args) {
106
- if ('afterResolve' !== args.lifecycle || !isHttpManifestUrl(args.id) || !isRetryableError(args.error) || 'function' != typeof fetchImpl) return;
107
- for(let attempt = 0; attempt < attempts; attempt++){
108
- if (attempt > 0 && retryDelayMs > 0) await waitImpl(retryDelayMs);
109
- try {
110
- const response = await fetchWithTimeout(fetchImpl, args.id, timeoutMs);
111
- if (!response.ok) {
112
- if (!RETRYABLE_HTTP_STATUSES.has(response.status) || attempt === attempts - 1) return;
113
- continue;
114
- }
115
- try {
116
- return await response.json();
117
- } catch {
118
- break;
119
- }
120
- } catch (error) {
121
- if (!isRetryableError(error) || attempt === attempts - 1) break;
122
- }
123
- }
114
+ errorLoadRemote (args) {
115
+ if ('afterResolve' !== args.lifecycle || !isHttpManifestUrl(args.id) || !isRetryableError(args.error) || 'function' != typeof fetchImpl) return Promise.resolve(void 0);
116
+ return recoverManifest(args.id, 0);
124
117
  }
125
118
  };
126
119
  };
127
- const __rspack_default_export = createModuleFederationManifestRecoveryPlugin;
128
- __webpack_require__.d(__webpack_exports__, {}, {
129
- createModuleFederationManifestRecoveryPlugin: createModuleFederationManifestRecoveryPlugin,
130
- default: __rspack_default_export
131
- });
120
+ const manifest_recovery_runtime_plugin = createModuleFederationManifestRecoveryPlugin;
132
121
  exports.createModuleFederationManifestRecoveryPlugin = __webpack_exports__.createModuleFederationManifestRecoveryPlugin;
133
122
  exports["default"] = __webpack_exports__["default"];
134
123
  for(var __rspack_i in __webpack_exports__)if (-1 === [