@modern-js/runtime 2.35.0 → 2.35.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 (91) hide show
  1. package/dist/cjs/core/compatible.js +9 -10
  2. package/dist/cjs/core/loader/useLoader.js +8 -8
  3. package/dist/cjs/core/plugin.js +2 -3
  4. package/dist/cjs/document/Html.js +3 -4
  5. package/dist/cjs/document/cli/index.js +4 -6
  6. package/dist/cjs/router/cli/index.js +1 -2
  7. package/dist/cjs/router/runtime/DeferredDataScripts.node.js +9 -11
  8. package/dist/cjs/router/runtime/PrefetchLink.js +5 -9
  9. package/dist/cjs/router/runtime/index.js +1 -1
  10. package/dist/cjs/router/runtime/plugin.js +5 -7
  11. package/dist/cjs/router/runtime/plugin.node.js +8 -9
  12. package/dist/cjs/router/runtime/server.js +1 -1
  13. package/dist/cjs/router/runtime/utils.js +7 -7
  14. package/dist/cjs/router/runtime/withRouter.js +1 -1
  15. package/dist/cjs/ssr/cli/index.js +9 -11
  16. package/dist/cjs/ssr/index.js +3 -3
  17. package/dist/cjs/ssr/index.node.js +1 -2
  18. package/dist/cjs/ssr/prefetch.js +4 -4
  19. package/dist/cjs/ssr/react/prerender/util.js +2 -4
  20. package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.after.js +2 -2
  21. package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +3 -7
  22. package/dist/cjs/ssr/serverRender/renderToStream/index.js +3 -3
  23. package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.js +5 -6
  24. package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.worker.js +4 -6
  25. package/dist/cjs/ssr/serverRender/renderToString/entry.js +4 -4
  26. package/dist/cjs/ssr/serverRender/renderToString/index.js +3 -3
  27. package/dist/cjs/ssr/serverRender/renderToString/loadable.js +29 -18
  28. package/dist/esm/core/compatible.js +9 -10
  29. package/dist/esm/core/loader/useLoader.js +8 -8
  30. package/dist/esm/core/plugin.js +2 -3
  31. package/dist/esm/document/Html.js +3 -4
  32. package/dist/esm/document/cli/index.js +4 -5
  33. package/dist/esm/router/cli/index.js +1 -2
  34. package/dist/esm/router/runtime/DeferredDataScripts.node.js +4 -6
  35. package/dist/esm/router/runtime/PrefetchLink.js +5 -9
  36. package/dist/esm/router/runtime/index.js +2 -2
  37. package/dist/esm/router/runtime/plugin.js +4 -6
  38. package/dist/esm/router/runtime/plugin.node.js +6 -7
  39. package/dist/esm/router/runtime/server.js +1 -1
  40. package/dist/esm/router/runtime/utils.js +6 -6
  41. package/dist/esm/router/runtime/withRouter.js +1 -1
  42. package/dist/esm/ssr/cli/index.js +9 -11
  43. package/dist/esm/ssr/index.js +1 -1
  44. package/dist/esm/ssr/index.node.js +1 -2
  45. package/dist/esm/ssr/prefetch.js +3 -3
  46. package/dist/esm/ssr/react/prerender/util.js +2 -4
  47. package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.after.js +1 -1
  48. package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +3 -5
  49. package/dist/esm/ssr/serverRender/renderToStream/index.js +2 -2
  50. package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +5 -6
  51. package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.worker.js +5 -5
  52. package/dist/esm/ssr/serverRender/renderToString/entry.js +2 -2
  53. package/dist/esm/ssr/serverRender/renderToString/index.js +2 -2
  54. package/dist/esm/ssr/serverRender/renderToString/loadable.js +32 -18
  55. package/dist/esm-node/core/compatible.js +9 -10
  56. package/dist/esm-node/core/loader/useLoader.js +8 -8
  57. package/dist/esm-node/core/plugin.js +2 -3
  58. package/dist/esm-node/document/Html.js +3 -4
  59. package/dist/esm-node/document/cli/index.js +4 -6
  60. package/dist/esm-node/router/cli/index.js +1 -2
  61. package/dist/esm-node/router/runtime/DeferredDataScripts.node.js +4 -6
  62. package/dist/esm-node/router/runtime/PrefetchLink.js +5 -9
  63. package/dist/esm-node/router/runtime/index.js +2 -2
  64. package/dist/esm-node/router/runtime/plugin.js +4 -6
  65. package/dist/esm-node/router/runtime/plugin.node.js +6 -7
  66. package/dist/esm-node/router/runtime/server.js +1 -1
  67. package/dist/esm-node/router/runtime/utils.js +6 -6
  68. package/dist/esm-node/router/runtime/withRouter.js +1 -1
  69. package/dist/esm-node/ssr/cli/index.js +9 -11
  70. package/dist/esm-node/ssr/index.js +1 -1
  71. package/dist/esm-node/ssr/index.node.js +1 -2
  72. package/dist/esm-node/ssr/prefetch.js +3 -3
  73. package/dist/esm-node/ssr/react/prerender/util.js +2 -4
  74. package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.after.js +1 -1
  75. package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +3 -7
  76. package/dist/esm-node/ssr/serverRender/renderToStream/index.js +2 -2
  77. package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.js +5 -6
  78. package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.worker.js +4 -6
  79. package/dist/esm-node/ssr/serverRender/renderToString/entry.js +2 -2
  80. package/dist/esm-node/ssr/serverRender/renderToString/index.js +2 -2
  81. package/dist/esm-node/ssr/serverRender/renderToString/loadable.js +29 -18
  82. package/dist/types/router/runtime/PrefetchLink.d.ts +1 -1
  83. package/dist/types/router/runtime/hooks.d.ts +1 -1
  84. package/dist/types/router/runtime/index.d.ts +3 -3
  85. package/dist/types/router/runtime/server.d.ts +1 -1
  86. package/dist/types/router/runtime/types.d.ts +2 -2
  87. package/dist/types/router/runtime/utils.d.ts +1 -1
  88. package/dist/types/router/runtime/withRouter.d.ts +1 -1
  89. package/dist/types/runtimeContext.d.ts +1 -1
  90. package/dist/types/ssr/serverRender/renderToString/loadable.d.ts +1 -0
  91. package/package.json +10 -9
@@ -45,7 +45,6 @@ export const documentPlugin = () => ({
45
45
  return null;
46
46
  }
47
47
  return async ({ htmlWebpackPlugin }) => {
48
- var _tsConfig, _partialsByEntrypoint;
49
48
  const config = api.useResolvedConfigContext();
50
49
  const documentParams = getDocParams({
51
50
  config,
@@ -60,7 +59,7 @@ export const documentPlugin = () => ({
60
59
  } catch (err) {
61
60
  tsConfig = {};
62
61
  }
63
- if ((_tsConfig = tsConfig) === null || _tsConfig === void 0 ? void 0 : _tsConfig.compilerOptions) {
62
+ if (tsConfig === null || tsConfig === void 0 ? void 0 : tsConfig.compilerOptions) {
64
63
  tsConfig.compilerOptions.jsx = "react-jsx";
65
64
  } else {
66
65
  tsConfig.compilerOptions = {
@@ -120,7 +119,7 @@ export const documentPlugin = () => ({
120
119
  partialsHead: "",
121
120
  partialsBody: ""
122
121
  };
123
- if ((_partialsByEntrypoint = partialsByEntrypoint) === null || _partialsByEntrypoint === void 0 ? void 0 : _partialsByEntrypoint[entryName]) {
122
+ if (partialsByEntrypoint === null || partialsByEntrypoint === void 0 ? void 0 : partialsByEntrypoint[entryName]) {
124
123
  partialsContent.partialsTop = partialsByEntrypoint[entryName].top.join("\n");
125
124
  partialsContent.partialsHead = partialsByEntrypoint[entryName].head.join("\n");
126
125
  partialsContent.partialsBody = partialsByEntrypoint[entryName].body.join("\n");
@@ -153,9 +152,8 @@ export const documentPlugin = () => ({
153
152
  return {
154
153
  tools: {
155
154
  htmlPlugin: (options, entry) => {
156
- var _options, _options1, _options2;
157
- const hackParameters = typeof ((_options = options) === null || _options === void 0 ? void 0 : _options.templateParameters) === "function" ? (_options1 = options) === null || _options1 === void 0 ? void 0 : _options1.templateParameters({}, {}, {}, {}) : {
158
- ...(_options2 = options) === null || _options2 === void 0 ? void 0 : _options2.templateParameters
155
+ const hackParameters = typeof (options === null || options === void 0 ? void 0 : options.templateParameters) === "function" ? options === null || options === void 0 ? void 0 : options.templateParameters({}, {}, {}, {}) : {
156
+ ...options === null || options === void 0 ? void 0 : options.templateParameters
159
157
  };
160
158
  const templateContent = documentEntry(
161
159
  entry.entryName,
@@ -43,13 +43,12 @@ export const routerPlugin = () => ({
43
43
  ];
44
44
  },
45
45
  modifyEntryImports({ entrypoint, imports }) {
46
- var _runtimeConfig;
47
46
  const { entryName, isMainEntry, fileSystemRoutes } = entrypoint;
48
47
  const userConfig = api.useResolvedConfigContext();
49
48
  const { packageName } = api.useAppContext();
50
49
  const runtimeConfig = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
51
50
  runtimeConfigMap.set(entryName, runtimeConfig);
52
- if ((_runtimeConfig = runtimeConfig) === null || _runtimeConfig === void 0 ? void 0 : _runtimeConfig.router) {
51
+ if (runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.router) {
53
52
  if (!isV5(userConfig)) {
54
53
  imports.push({
55
54
  value: "@modern-js/runtime/plugins",
@@ -1,14 +1,13 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Suspense, useEffect, useRef, useMemo, useContext } from "react";
3
- import { Await, UNSAFE_DataRouterContext as DataRouterContext, useAsyncError } from "@modern-js/utils/runtime/router";
4
- import { serializeJson } from "@modern-js/utils/runtime-node";
3
+ import { Await, UNSAFE_DataRouterContext as DataRouterContext, useAsyncError } from "@modern-js/runtime-utils/router";
4
+ import { serializeJson } from "@modern-js/runtime-utils/node";
5
5
  import { JSX_SHELL_STREAM_END_MARK } from "../../common";
6
6
  import { serializeErrors } from "./utils";
7
7
  const setupFnStr = `function s(r,e){_ROUTER_DATA.r=_ROUTER_DATA.r||{},_ROUTER_DATA.r[r]=_ROUTER_DATA.r[r]||{};return new Promise((function(A,R){_ROUTER_DATA.r[r][e]={resolve:A,reject:R}}))};`;
8
8
  const resolveFnStr = `function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};`;
9
9
  const preResolvedFnStr = `function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resolve(e)};`;
10
10
  const DeferredDataScripts = (props) => {
11
- var _props;
12
11
  const context = useContext(DataRouterContext);
13
12
  const { staticContext } = context || {};
14
13
  const hydratedRef = useRef(false);
@@ -36,9 +35,8 @@ const DeferredDataScripts = (props) => {
36
35
  const { deferredKeys } = deferredData;
37
36
  const deferredKeyPromiseStr = deferredKeys.map((key) => {
38
37
  if (pendingKeys.has(key)) {
39
- var _props2;
40
38
  deferredDataScripts.push(/* @__PURE__ */ _jsx(DeferredDataScript, {
41
- nonce: (_props2 = props) === null || _props2 === void 0 ? void 0 : _props2.nonce,
39
+ nonce: props === null || props === void 0 ? void 0 : props.nonce,
42
40
  data: deferredData.data[key],
43
41
  dataKey: key,
44
42
  routeId
@@ -74,7 +72,7 @@ const DeferredDataScripts = (props) => {
74
72
  children: [
75
73
  !hydratedRef.current && /* @__PURE__ */ _jsx("script", {
76
74
  async: true,
77
- nonce: (_props = props) === null || _props === void 0 ? void 0 : _props.nonce,
75
+ nonce: props === null || props === void 0 ? void 0 : props.nonce,
78
76
  suppressHydrationWarning: true,
79
77
  dangerouslySetInnerHTML: {
80
78
  __html: deferredScripts[0]
@@ -1,11 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import React, { useContext, useMemo } from "react";
3
- import { Link as RouterLink, matchRoutes, useResolvedPath, useHref, useMatches, NavLink as RouterNavLink } from "@modern-js/utils/runtime/router";
3
+ import { Link as RouterLink, matchRoutes, useResolvedPath, useHref, useMatches, NavLink as RouterNavLink } from "@modern-js/runtime-utils/router";
4
4
  import { RuntimeReactContext } from "../../core";
5
5
  export function composeEventHandlers(theirHandler, ourHandler) {
6
6
  return (event) => {
7
- var _theirHandler;
8
- (_theirHandler = theirHandler) === null || _theirHandler === void 0 ? void 0 : _theirHandler(event);
7
+ theirHandler === null || theirHandler === void 0 ? void 0 : theirHandler(event);
9
8
  if (!event.defaultPrevented) {
10
9
  ourHandler(event);
11
10
  }
@@ -71,8 +70,7 @@ async function loadRouteModule(route, routeAssets) {
71
70
  }
72
71
  try {
73
72
  await Promise.all(chunkIds.map((chunkId) => {
74
- var __webpack_chunk_load__1;
75
- return (__webpack_chunk_load__1 = __webpack_chunk_load__) === null || __webpack_chunk_load__1 === void 0 ? void 0 : __webpack_chunk_load__1(String(chunkId));
73
+ return __webpack_chunk_load__ === null || __webpack_chunk_load__ === void 0 ? void 0 : __webpack_chunk_load__(String(chunkId));
76
74
  }));
77
75
  } catch (error) {
78
76
  console.error(error);
@@ -106,8 +104,7 @@ const PrefetchPageLinks = ({ pathname }) => {
106
104
  const { routeAssets } = routeManifest || {};
107
105
  const matches = Array.isArray(routes) ? matchRoutes(routes, pathname) : [];
108
106
  if (Array.isArray(matches) && routeAssets) {
109
- var _matches;
110
- (_matches = matches) === null || _matches === void 0 ? void 0 : _matches.forEach((match) => loadRouteModule(match.route, routeAssets));
107
+ matches === null || matches === void 0 ? void 0 : matches.forEach((match) => loadRouteModule(match.route, routeAssets));
111
108
  }
112
109
  if (!window._SSR_DATA) {
113
110
  return null;
@@ -122,8 +119,7 @@ const PrefetchDataLinks = ({ matches, pathname, routeManifest }) => {
122
119
  const currentMatches = useMatches();
123
120
  const basename = useHref("/");
124
121
  const dataHrefs = useMemo(() => {
125
- var _matches;
126
- return (_matches = matches) === null || _matches === void 0 ? void 0 : _matches.filter((match, index) => {
122
+ return matches === null || matches === void 0 ? void 0 : matches.filter((match, index) => {
127
123
  if (!match.route.loader || typeof match.route.loader !== "function" || match.route.loader.length === 0) {
128
124
  return false;
129
125
  }
@@ -1,4 +1,4 @@
1
- import { useRouteLoaderData as useRouteData } from "@modern-js/utils/runtime/router";
1
+ import { useRouteLoaderData as useRouteData } from "@modern-js/runtime-utils/router";
2
2
  import { routerPlugin } from "./plugin";
3
3
  export { renderRoutes } from "./utils";
4
4
  export default routerPlugin;
@@ -66,4 +66,4 @@ export {
66
66
  defer,
67
67
  json,
68
68
  redirect
69
- } from "@modern-js/utils/runtime/router";
69
+ } from "@modern-js/runtime-utils/router";
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useContext, useMemo } from "react";
3
- import { createBrowserRouter, createHashRouter, RouterProvider, createRoutesFromElements, useMatches, useLocation } from "@modern-js/utils/runtime/router";
3
+ import { createBrowserRouter, createHashRouter, RouterProvider, createRoutesFromElements, useMatches, useLocation } from "@modern-js/runtime-utils/router";
4
4
  import hoistNonReactStatics from "hoist-non-react-statics";
5
- import { parsedJSONFromElement } from "@modern-js/utils/runtime-browser";
5
+ import { parsedJSONFromElement } from "@modern-js/runtime-utils/browser";
6
6
  import { RuntimeReactContext } from "../../core";
7
7
  import { modifyRoutes as modifyRoutesHook } from "./hooks";
8
8
  import { deserializeErrors, renderRoutes, urlJoin } from "./utils";
@@ -46,7 +46,6 @@ export const routerPlugin = ({ serverBase = [], supportHtml5History = true, base
46
46
  });
47
47
  },
48
48
  hoc: ({ App }, next) => {
49
- var _routesConfig;
50
49
  if (!finalRouteConfig && !createRoutes) {
51
50
  return next({
52
51
  App
@@ -61,8 +60,7 @@ export const routerPlugin = ({ serverBase = [], supportHtml5History = true, base
61
60
  const runtimeContext = useContext(RuntimeReactContext);
62
61
  const { unstable_getBlockNavState: getBlockNavState } = runtimeContext;
63
62
  return useMemo(() => {
64
- var _hydrationData;
65
- if ((_hydrationData = hydrationData) === null || _hydrationData === void 0 ? void 0 : _hydrationData.errors) {
63
+ if (hydrationData === null || hydrationData === void 0 ? void 0 : hydrationData.errors) {
66
64
  hydrationData = {
67
65
  ...hydrationData,
68
66
  errors: deserializeErrors(hydrationData.errors)
@@ -122,7 +120,7 @@ export const routerPlugin = ({ serverBase = [], supportHtml5History = true, base
122
120
  if (App) {
123
121
  RouteApp = hoistNonReactStatics(RouteApp, App);
124
122
  }
125
- if ((_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : _routesConfig.globalApp) {
123
+ if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
126
124
  return next({
127
125
  App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
128
126
  });
@@ -1,11 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useContext } from "react";
3
- import { createStaticHandler } from "@modern-js/utils/runtime/remix-router";
4
- import { createStaticRouter, StaticRouterProvider } from "@modern-js/utils/runtime-node/router";
3
+ import { createStaticHandler } from "@modern-js/runtime-utils/remix-router";
4
+ import { createStaticRouter, StaticRouterProvider } from "@modern-js/runtime-utils/node/router";
5
5
  import hoistNonReactStatics from "hoist-non-react-statics";
6
- import { createRoutesFromElements } from "@modern-js/utils/runtime/router";
7
- import { createRequestContext, reporterCtx } from "@modern-js/utils/runtime-node";
8
- import { time } from "@modern-js/utils/universal/time";
6
+ import { createRoutesFromElements } from "@modern-js/runtime-utils/router";
7
+ import { createRequestContext, reporterCtx } from "@modern-js/runtime-utils/node";
8
+ import { time } from "@modern-js/runtime-utils/time";
9
9
  import { LOADER_REPORTER_NAME } from "@modern-js/utils/universal/constants";
10
10
  import { RuntimeReactContext } from "../../core";
11
11
  import { renderRoutes, urlJoin } from "./utils";
@@ -92,7 +92,6 @@ export const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
92
92
  });
93
93
  },
94
94
  hoc: ({ App }, next) => {
95
- var _routesConfig;
96
95
  if (!routesConfig) {
97
96
  return next({
98
97
  App
@@ -112,7 +111,7 @@ export const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
112
111
  };
113
112
  };
114
113
  const RouteApp = getRouteApp();
115
- if ((_routesConfig = routesConfig) === null || _routesConfig === void 0 ? void 0 : _routesConfig.globalApp) {
114
+ if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
116
115
  return next({
117
116
  App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
118
117
  });
@@ -1 +1 @@
1
- export * from "@modern-js/utils/runtime-node/router";
1
+ export * from "@modern-js/runtime-utils/node/router";
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Route, isRouteErrorResponse } from "@modern-js/utils/runtime/router";
3
- import { ErrorResponse } from "@modern-js/utils/runtime/remix-router";
4
- import { renderNestedRoute } from "@modern-js/utils/runtime/nested-routes";
2
+ import { Route, isRouteErrorResponse } from "@modern-js/runtime-utils/router";
3
+ import { ErrorResponse } from "@modern-js/runtime-utils/remix-router";
4
+ import { renderNestedRoute } from "@modern-js/runtime-utils/browser";
5
5
  import { DefaultNotFound } from "./DefaultNotFound";
6
6
  import DeferredDataScripts from "./DeferredDataScripts";
7
7
  export function getRouteComponents(routes, { globalApp, ssrMode, props, reporter }) {
@@ -59,9 +59,9 @@ export function renderRoutes({ routesConfig, props, ssrMode, reporter }) {
59
59
  return routeElements;
60
60
  }
61
61
  export function getLocation(serverContext) {
62
- var _serverContext, _url_replace, _url;
63
- const { pathname, url } = ((_serverContext = serverContext) === null || _serverContext === void 0 ? void 0 : _serverContext.request) || {};
64
- const cleanUrl = (_url = url) === null || _url === void 0 ? void 0 : (_url_replace = _url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
62
+ var _url_replace;
63
+ const { pathname, url } = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {};
64
+ const cleanUrl = url === null || url === void 0 ? void 0 : (_url_replace = url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
65
65
  const index = (cleanUrl || "").indexOf(pathname);
66
66
  if (index === -1) {
67
67
  return pathname;
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useLocation, useNavigate, useParams } from "@modern-js/utils/runtime/router";
2
+ import { useLocation, useNavigate, useParams } from "@modern-js/runtime-utils/router";
3
3
  export const withRouter = (Component) => {
4
4
  return (props) => {
5
5
  const location = useLocation();
@@ -2,13 +2,12 @@ import path from "path";
2
2
  import { getEntryOptions, SERVER_RENDER_FUNCTION_NAME, LOADABLE_STATS_FILE, isUseSSRBundle, createRuntimeExportsUtils, isSSGEntry } from "@modern-js/utils";
3
3
  const PLUGIN_IDENTIFIER = "ssr";
4
4
  const hasStringSSREntry = (userConfig) => {
5
- var _server, _server1;
6
5
  const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
7
6
  const { server, output } = userConfig;
8
- if ((((_server = server) === null || _server === void 0 ? void 0 : _server.ssr) || output.ssg) && !isStreaming(server.ssr)) {
7
+ if (((server === null || server === void 0 ? void 0 : server.ssr) || output.ssg) && !isStreaming(server.ssr)) {
9
8
  return true;
10
9
  }
11
- if (((_server1 = server) === null || _server1 === void 0 ? void 0 : _server1.ssrByEntries) && typeof server.ssrByEntries === "object") {
10
+ if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
12
11
  for (const name of Object.keys(server.ssrByEntries)) {
13
12
  if (!isStreaming(server.ssrByEntries[name])) {
14
13
  return true;
@@ -18,9 +17,8 @@ const hasStringSSREntry = (userConfig) => {
18
17
  return false;
19
18
  };
20
19
  const checkUseStringSSR = (config) => {
21
- var _output;
22
20
  const { output } = config;
23
- return Boolean((_output = output) === null || _output === void 0 ? void 0 : _output.ssg) || hasStringSSREntry(config);
21
+ return Boolean(output === null || output === void 0 ? void 0 : output.ssg) || hasStringSSREntry(config);
24
22
  };
25
23
  export const ssrPlugin = () => ({
26
24
  name: "@modern-js/plugin-ssr",
@@ -63,8 +61,8 @@ export const ssrPlugin = () => ({
63
61
  return {
64
62
  source: {
65
63
  alias: {
66
- // ensure that all packages use the same storage in @modern-js/utils/runtime-node
67
- "@modern-js/utils/runtime-node$": require.resolve("@modern-js/utils/runtime-node"),
64
+ // ensure that all packages use the same storage in @modern-js/runtime-utils/node
65
+ "@modern-js/runtime-utils/node$": require.resolve("@modern-js/runtime-utils/node"),
68
66
  "@modern-js/runtime/plugins": pluginsExportsUtils.getPath()
69
67
  },
70
68
  globalVars: (values, { target }) => {
@@ -94,9 +92,9 @@ export const ssrPlugin = () => ({
94
92
  pluginsExportsUtils.addExport(`export { default as ssr } from '@modern-js/runtime/ssr'`);
95
93
  const ssrConfig = getEntryOptions(entryName, isMainEntry, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
96
94
  if (typeof ssrConfig === "object" && ssrConfig.mode === "stream") {
97
- var _this, _runtimeConfig;
95
+ var _this;
98
96
  const runtimeConfig = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
99
- if (((_this = (_runtimeConfig = runtimeConfig) === null || _runtimeConfig === void 0 ? void 0 : _runtimeConfig.router) === null || _this === void 0 ? void 0 : _this.mode) === "react-router-5") {
97
+ if (((_this = runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.router) === null || _this === void 0 ? void 0 : _this.mode) === "react-router-5") {
100
98
  throw new Error(`router v5 plugin doesn't support streaming SSR, check your config 'runtime.router'`);
101
99
  }
102
100
  if (fileSystemRoutes && !entrypoint.nestedRoutesEntry) {
@@ -122,8 +120,8 @@ export const ssrPlugin = () => ({
122
120
  },
123
121
  modifyEntryRuntimePlugins({ entrypoint, plugins, bundlerConfigs }) {
124
122
  if (ssrConfigMap.get(entrypoint.entryName)) {
125
- var _bundlerConfigs_find_output, _bundlerConfigs_find, _bundlerConfigs, _config_server;
126
- const chunkLoadingGlobal = (_bundlerConfigs = bundlerConfigs) === null || _bundlerConfigs === void 0 ? void 0 : (_bundlerConfigs_find = _bundlerConfigs.find((config2) => config2.name === "client")) === null || _bundlerConfigs_find === void 0 ? void 0 : (_bundlerConfigs_find_output = _bundlerConfigs_find.output) === null || _bundlerConfigs_find_output === void 0 ? void 0 : _bundlerConfigs_find_output.chunkLoadingGlobal;
123
+ var _bundlerConfigs_find_output, _bundlerConfigs_find, _config_server;
124
+ const chunkLoadingGlobal = bundlerConfigs === null || bundlerConfigs === void 0 ? void 0 : (_bundlerConfigs_find = bundlerConfigs.find((config2) => config2.name === "client")) === null || _bundlerConfigs_find === void 0 ? void 0 : (_bundlerConfigs_find_output = _bundlerConfigs_find.output) === null || _bundlerConfigs_find_output === void 0 ? void 0 : _bundlerConfigs_find_output.chunkLoadingGlobal;
127
125
  const config = api.useResolvedConfigContext();
128
126
  const { crossorigin, scriptLoading } = config.html;
129
127
  const disablePrerender = typeof ((_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.ssr) === "object" ? Boolean(config.server.ssr.disablePrerender) : false;
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { loadableReady } from "@loadable/component";
3
3
  import hoistNonReactStatics from "hoist-non-react-statics";
4
- import { parsedJSONFromElement } from "@modern-js/utils/runtime-browser";
4
+ import { parsedJSONFromElement } from "@modern-js/runtime-utils/browser";
5
5
  import { RenderLevel } from "./serverRender/types";
6
6
  import { WithCallback } from "./react/withCallback";
7
7
  import { formatClient, mockResponse, isReact18 } from "./utils";
@@ -26,8 +26,7 @@ export const ssr = (config = {}) => ({
26
26
  });
27
27
  },
28
28
  pickContext: ({ context, pickedContext }, next) => {
29
- var _context;
30
- const { request, response } = (_context = context) === null || _context === void 0 ? void 0 : _context.ssrContext;
29
+ const { request, response } = context === null || context === void 0 ? void 0 : context.ssrContext;
31
30
  const { initialData } = context;
32
31
  return next({
33
32
  context,
@@ -1,9 +1,9 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { renderToStaticMarkup } from "react-dom/server";
3
- import { run } from "@modern-js/utils/runtime-node";
3
+ import { run } from "@modern-js/runtime-utils/node";
4
4
  import { ChunkExtractor } from "@loadable/server";
5
5
  const prefetch = async (App, context, config) => run(context.ssrContext.request.headers, async () => {
6
- var _context_store, _context;
6
+ var _context_store;
7
7
  const { ssrContext } = context;
8
8
  const { loadableStats } = ssrContext;
9
9
  if (!config.disablePrerender) {
@@ -43,7 +43,7 @@ const prefetch = async (App, context, config) => run(context.ssrContext.request.
43
43
  initialData: context.initialData,
44
44
  i18nData: context.__i18nData__,
45
45
  // todo: move to plugin state
46
- storeState: (_context = context) === null || _context === void 0 ? void 0 : (_context_store = _context.store) === null || _context_store === void 0 ? void 0 : _context_store.getState()
46
+ storeState: context === null || context === void 0 ? void 0 : (_context_store = context.store) === null || _context_store === void 0 ? void 0 : _context_store.getState()
47
47
  };
48
48
  });
49
49
  export default prefetch;
@@ -27,9 +27,8 @@ export const aggKeysFromPropsList = function aggKeysFromPropsList2(propsList, pr
27
27
  }, {});
28
28
  const res = propsList.filter((props) => usefulObject(props[propName])).reduce((result, next) => {
29
29
  REQUEST_META.forEach((key) => {
30
- var _prop;
31
30
  const prop = next[propName];
32
- if (((_prop = prop) === null || _prop === void 0 ? void 0 : _prop.hasOwnProperty(key)) && usefulArray(prop[key])) {
31
+ if ((prop === null || prop === void 0 ? void 0 : prop.hasOwnProperty(key)) && usefulArray(prop[key])) {
33
32
  result[key] = unique(result[key].concat(prop[key]));
34
33
  }
35
34
  });
@@ -52,9 +51,8 @@ export const aggMatchesFromPropsList = function aggMatchesFromPropsList2(propsLi
52
51
  }, {});
53
52
  const res = propsList.filter((props) => usefulObject(props[propName])).reduce((result, next) => {
54
53
  REQUEST_META.forEach((key) => {
55
- var _prop;
56
54
  const prop = next[propName];
57
- if (((_prop = prop) === null || _prop === void 0 ? void 0 : _prop.hasOwnProperty(key)) && usefulObject(prop[key])) {
55
+ if ((prop === null || prop === void 0 ? void 0 : prop.hasOwnProperty(key)) && usefulObject(prop[key])) {
58
56
  result[key] = Object.assign(result[key], prop[key]);
59
57
  }
60
58
  });
@@ -1,4 +1,4 @@
1
- import { serializeJson } from "@modern-js/utils/runtime-node";
1
+ import { serializeJson } from "@modern-js/runtime-utils/node";
2
2
  import { attributesToString } from "../utils";
3
3
  import { buildTemplate } from "./buildTemplate.share";
4
4
  export function buildShellAfterTemplate(afterAppTemplate, options) {
@@ -1,5 +1,5 @@
1
1
  import ReactHelmet from "react-helmet";
2
- import { matchRoutes } from "@modern-js/utils/runtime/router";
2
+ import { matchRoutes } from "@modern-js/runtime-utils/router";
3
3
  import helmetReplace from "../helmet";
4
4
  import { CSS_CHUNKS_PLACEHOLDER } from "../utils";
5
5
  import { HEAD_REG_EXP, buildTemplate } from "./buildTemplate.share";
@@ -20,7 +20,6 @@ function getHeadTemplate(beforeEntryTemplate, context) {
20
20
  function injectCss(headTemplate2) {
21
21
  return headTemplate2.replace(CSS_CHUNKS_PLACEHOLDER, getCssChunks());
22
22
  function getCssChunks() {
23
- var _matches;
24
23
  const { routeManifest, routerContext, routes } = context;
25
24
  if (!routeManifest || !routerContext || !routes) {
26
25
  return "";
@@ -28,7 +27,7 @@ function getHeadTemplate(beforeEntryTemplate, context) {
28
27
  const { routeAssets } = routeManifest;
29
28
  const cssChunks = [];
30
29
  const matches = matchRoutes(routes, routerContext.location, routerContext.basename);
31
- (_matches = matches) === null || _matches === void 0 ? void 0 : _matches.forEach((match, index) => {
30
+ matches === null || matches === void 0 ? void 0 : matches.forEach((match, index) => {
32
31
  if (!index) {
33
32
  return;
34
33
  }
@@ -37,10 +36,7 @@ function getHeadTemplate(beforeEntryTemplate, context) {
37
36
  const routeManifest2 = routeAssets[routeId];
38
37
  if (routeManifest2) {
39
38
  const { referenceCssAssets = [] } = routeManifest2;
40
- const _cssChunks = referenceCssAssets.filter((asset) => {
41
- var _asset;
42
- return ((_asset = asset) === null || _asset === void 0 ? void 0 : _asset.endsWith(".css")) && !headTemplate2.includes(asset);
43
- });
39
+ const _cssChunks = referenceCssAssets.filter((asset) => (asset === null || asset === void 0 ? void 0 : asset.endsWith(".css")) && !headTemplate2.includes(asset));
44
40
  cssChunks.push(..._cssChunks);
45
41
  }
46
42
  }
@@ -1,6 +1,6 @@
1
1
  import { createElement } from "react";
2
- import { run } from "@modern-js/utils/runtime-node";
3
- import { time } from "@modern-js/utils/universal/time";
2
+ import { run } from "@modern-js/runtime-utils/node";
3
+ import { time } from "@modern-js/runtime-utils/time";
4
4
  import { PreRender } from "../../react/prerender";
5
5
  import { SSRErrors, SSRTimings } from "../tracker";
6
6
  import renderToPipe from "./renderToPipe";
@@ -13,7 +13,6 @@ function renderToPipe(rootElement, context, options) {
13
13
  const chunkVec = [];
14
14
  const forUserPipe = (stream) => {
15
15
  return new Promise((resolve) => {
16
- var _ssrContext;
17
16
  let renderToPipeableStream;
18
17
  try {
19
18
  ({ renderToPipeableStream } = require("react-dom/server"));
@@ -21,11 +20,11 @@ function renderToPipe(rootElement, context, options) {
21
20
  }
22
21
  const { pipe } = renderToPipeableStream(rootElement, {
23
22
  ...options,
24
- nonce: (_ssrContext = ssrContext) === null || _ssrContext === void 0 ? void 0 : _ssrContext.nonce,
23
+ nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce,
25
24
  onShellReady() {
26
- var _options_onShellReady, _options;
25
+ var _options_onShellReady;
27
26
  const { shellAfter, shellBefore } = getTemplates(context, RenderLevel.SERVER_RENDER);
28
- (_options = options) === null || _options === void 0 ? void 0 : (_options_onShellReady = _options.onShellReady) === null || _options_onShellReady === void 0 ? void 0 : _options_onShellReady.call(_options);
27
+ options === null || options === void 0 ? void 0 : (_options_onShellReady = options.onShellReady) === null || _options_onShellReady === void 0 ? void 0 : _options_onShellReady.call(options);
29
28
  const injectableTransform = new Transform({
30
29
  transform(chunk, _encoding, callback) {
31
30
  try {
@@ -53,11 +52,11 @@ function renderToPipe(rootElement, context, options) {
53
52
  resolve(pipe(injectableTransform).pipe(stream));
54
53
  },
55
54
  onShellError(error) {
56
- var _options_onShellError, _options;
55
+ var _options_onShellError;
57
56
  const { shellAfter, shellBefore } = getTemplates(context, RenderLevel.CLIENT_RENDER);
58
57
  const fallbackHtml = `${shellBefore}${shellAfter}`;
59
58
  resolve(fallbackHtml);
60
- (_options = options) === null || _options === void 0 ? void 0 : (_options_onShellError = _options.onShellError) === null || _options_onShellError === void 0 ? void 0 : _options_onShellError.call(_options, error);
59
+ options === null || options === void 0 ? void 0 : (_options_onShellError = options.onShellError) === null || _options_onShellError === void 0 ? void 0 : _options_onShellError.call(options, error);
61
60
  }
62
61
  });
63
62
  });
@@ -19,13 +19,12 @@ function renderToPipe(rootElement, context, options) {
19
19
  }
20
20
  const { shellAfter, shellBefore } = getTemplates(context, RenderLevel.SERVER_RENDER);
21
21
  try {
22
- var _ssrContext;
23
22
  const readableOriginal = await renderToReadableStream(rootElement, {
24
23
  ...options,
25
- nonce: (_ssrContext = ssrContext) === null || _ssrContext === void 0 ? void 0 : _ssrContext.nonce,
24
+ nonce: ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.nonce,
26
25
  onError(error) {
27
- var _options_onError, _options;
28
- (_options = options) === null || _options === void 0 ? void 0 : (_options_onError = _options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(_options, error);
26
+ var _options_onError;
27
+ options === null || options === void 0 ? void 0 : (_options_onError = options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(options, error);
29
28
  }
30
29
  });
31
30
  const reader = readableOriginal.getReader();
@@ -56,8 +55,7 @@ function renderToPipe(rootElement, context, options) {
56
55
  });
57
56
  return injectableStream;
58
57
  } catch (err) {
59
- var _ssrContext1;
60
- (_ssrContext1 = ssrContext) === null || _ssrContext1 === void 0 ? void 0 : _ssrContext1.tracker.trackError(SSRErrors.RENDER_SHELL, err);
58
+ ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.tracker.trackError(SSRErrors.RENDER_SHELL, err);
61
59
  const { shellAfter: shellAfter2, shellBefore: shellBefore2 } = getTemplates(context, RenderLevel.CLIENT_RENDER);
62
60
  const fallbackHtml = `${shellBefore2}${shellAfter2}`;
63
61
  return fallbackHtml;
@@ -1,8 +1,8 @@
1
1
  import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
2
  import React from "react";
3
- import { serializeJson } from "@modern-js/utils/runtime-node";
3
+ import { serializeJson } from "@modern-js/runtime-utils/node";
4
4
  import ReactHelmet from "react-helmet";
5
- import { time } from "@modern-js/utils/universal/time";
5
+ import { time } from "@modern-js/runtime-utils/time";
6
6
  import { serializeErrors } from "../../../router/runtime/utils";
7
7
  import helmetReplace from "../helmet";
8
8
  import { RenderLevel } from "../types";
@@ -1,5 +1,5 @@
1
- import { run } from "@modern-js/utils/runtime-node";
2
- import { time } from "@modern-js/utils/universal/time";
1
+ import { run } from "@modern-js/runtime-utils/node";
2
+ import { time } from "@modern-js/runtime-utils/time";
3
3
  import { PreRender } from "../../react/prerender";
4
4
  import { SSRTimings } from "../tracker";
5
5
  import SSREntry from "./entry";
@@ -2,11 +2,10 @@ import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
2
  import { ChunkExtractor } from "@loadable/server";
3
3
  import { attributesToString, getLoadableScripts } from "../utils";
4
4
  const extname = (uri) => {
5
- var _uri;
6
5
  if (typeof uri !== "string" || !uri.includes(".")) {
7
6
  return "";
8
7
  }
9
- return `.${(_uri = uri) === null || _uri === void 0 ? void 0 : _uri.split(".").pop()}` || "";
8
+ return `.${uri === null || uri === void 0 ? void 0 : uri.split(".").pop()}` || "";
10
9
  };
11
10
  class LoadableCollector {
12
11
  collect(comopnent) {
@@ -30,35 +29,47 @@ class LoadableCollector {
30
29
  const { extractor } = this;
31
30
  const chunks = extractor.getChunkAssets(extractor.chunks);
32
31
  chunksMap.js = (chunksMap.js || "") + getLoadableScripts(extractor);
32
+ const attributes = this.generateAttributes();
33
33
  for (const v of chunks) {
34
- const fileType = extname(v.url).slice(1);
35
- const attributes = {};
36
- const { crossorigin, scriptLoading = "defer" } = config;
37
- if (crossorigin) {
38
- attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
39
- }
40
- switch (scriptLoading) {
41
- case "defer":
42
- attributes.defer = true;
43
- break;
44
- case "module":
45
- attributes.type = "module";
46
- break;
47
- default:
34
+ if (!v.url) {
35
+ continue;
48
36
  }
37
+ const fileType = extname(v.url).slice(1);
49
38
  if (fileType === "js") {
50
39
  const jsChunkReg = new RegExp(`<script .*src="${v.url}".*>`);
51
40
  if (!jsChunkReg.test(template)) {
41
+ const { scriptLoading = "defer" } = config;
42
+ switch (scriptLoading) {
43
+ case "defer":
44
+ attributes.defer = true;
45
+ break;
46
+ case "module":
47
+ attributes.type = "module";
48
+ break;
49
+ default:
50
+ }
52
51
  attributes.nonce = nonce;
53
52
  const attrsStr = attributesToString(attributes);
54
53
  chunksMap[fileType] += `<script${attrsStr} src="${v.url}"></script>`;
55
54
  }
56
55
  } else if (fileType === "css") {
57
- const attrsStr = attributesToString(attributes);
58
- chunksMap[fileType] += `<link${attrsStr} href="${v.url}" rel="stylesheet" />`;
56
+ const cssChunkReg = new RegExp(`<link .*href="${v.url}".*>`);
57
+ if (!cssChunkReg.test(template)) {
58
+ const attrsStr = attributesToString(attributes);
59
+ chunksMap[fileType] += `<link${attrsStr} href="${v.url}" rel="stylesheet" />`;
60
+ }
59
61
  }
60
62
  }
61
63
  }
64
+ generateAttributes() {
65
+ const { config } = this.options;
66
+ const { crossorigin } = config;
67
+ const attributes = {};
68
+ if (crossorigin) {
69
+ attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
70
+ }
71
+ return attributes;
72
+ }
62
73
  constructor(options) {
63
74
  _define_property(this, "options", void 0);
64
75
  _define_property(this, "extractor", void 0);
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { LinkProps as RouterLinkProps, NavLinkProps as RouterNavLinkProps } from '@modern-js/utils/runtime/router';
2
+ import { LinkProps as RouterLinkProps, NavLinkProps as RouterNavLinkProps } from '@modern-js/runtime-utils/router';
3
3
  export declare function composeEventHandlers<EventType extends React.SyntheticEvent | Event>(theirHandler: ((event: EventType) => any) | undefined, ourHandler: (event: EventType) => any): (event: EventType) => any;
4
4
  /**
5
5
  * Modified from https://github.com/remix-run/remix/blob/9a0601bd704d2f3ee622e0ddacab9b611eb0c5bc/packages/remix-react/components.tsx#L218
@@ -1,3 +1,3 @@
1
- import { RouteObject } from '@modern-js/utils/runtime/router';
1
+ import { RouteObject } from '@modern-js/runtime-utils/router';
2
2
  declare const modifyRoutes: import("@modern-js/plugin").Waterfall<RouteObject[]>;
3
3
  export { modifyRoutes };