@modern-js/runtime 2.4.0 → 2.4.1-beta.0

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/CHANGELOG.md +17 -0
  2. package/dist/js/modern/core/compatible.js +1 -0
  3. package/dist/js/modern/router/runtime/fetch.js +5 -0
  4. package/dist/js/modern/router/runtime/fetch.node.js +4 -0
  5. package/dist/js/modern/router/runtime/fetch.worker.js +5 -0
  6. package/dist/js/modern/router/runtime/plugin.node.js +2 -2
  7. package/dist/js/modern/ssr/cli/index.js +2 -2
  8. package/dist/js/modern/ssr/prefetch.worker.js +66 -0
  9. package/dist/js/modern/ssr/react/nossr/index.js +6 -2
  10. package/dist/js/modern/ssr/serverRender/renderToStream/index.js +1 -1
  11. package/dist/js/modern/ssr/serverRender/renderToStream/index.worker.js +35 -0
  12. package/dist/js/modern/ssr/serverRender/renderToStream/renderToPipe.worker.js +110 -0
  13. package/dist/js/modern/ssr/serverRender/renderToString/entry.js +5 -4
  14. package/dist/js/modern/ssr/serverRender/renderToString/index.js +1 -1
  15. package/dist/js/modern/ssr/serverRender/renderToString/index.worker.js +49 -0
  16. package/dist/js/modern/ssr/serverRender/time.js +13 -0
  17. package/dist/js/modern/ssr/serverRender/time.worker.js +28 -0
  18. package/dist/js/modern/ssr/serverRender/utils.js +1 -12
  19. package/dist/js/node/core/compatible.js +1 -0
  20. package/dist/js/node/router/runtime/fetch.js +28 -0
  21. package/dist/js/node/router/runtime/fetch.node.js +27 -0
  22. package/dist/js/node/router/runtime/fetch.worker.js +28 -0
  23. package/dist/js/node/router/runtime/plugin.node.js +3 -3
  24. package/dist/js/node/ssr/cli/index.js +2 -2
  25. package/dist/js/node/ssr/prefetch.worker.js +87 -0
  26. package/dist/js/node/ssr/react/nossr/index.js +6 -2
  27. package/dist/js/node/ssr/serverRender/renderToStream/index.js +2 -2
  28. package/dist/js/node/ssr/serverRender/renderToStream/index.worker.js +64 -0
  29. package/dist/js/node/ssr/serverRender/renderToStream/renderToPipe.worker.js +129 -0
  30. package/dist/js/node/ssr/serverRender/renderToString/entry.js +7 -6
  31. package/dist/js/node/ssr/serverRender/renderToString/index.js +2 -2
  32. package/dist/js/node/ssr/serverRender/renderToString/index.worker.js +78 -0
  33. package/dist/js/node/ssr/serverRender/time.js +36 -0
  34. package/dist/js/node/ssr/serverRender/time.worker.js +51 -0
  35. package/dist/js/node/ssr/serverRender/utils.js +2 -14
  36. package/dist/js/treeshaking/core/compatible.js +8 -7
  37. package/dist/js/treeshaking/core/loader/loaderManager.js +3 -3
  38. package/dist/js/treeshaking/core/loader/useLoader.js +15 -15
  39. package/dist/js/treeshaking/document/Head.js +1 -1
  40. package/dist/js/treeshaking/document/Html.js +2 -2
  41. package/dist/js/treeshaking/document/Root.js +2 -2
  42. package/dist/js/treeshaking/document/cli/index.js +4 -4
  43. package/dist/js/treeshaking/router/cli/index.js +2 -2
  44. package/dist/js/treeshaking/router/runtime/fetch.js +2 -0
  45. package/dist/js/treeshaking/router/runtime/fetch.node.js +2 -0
  46. package/dist/js/treeshaking/router/runtime/fetch.worker.js +2 -0
  47. package/dist/js/treeshaking/router/runtime/plugin.js +3 -3
  48. package/dist/js/treeshaking/router/runtime/plugin.node.js +5 -5
  49. package/dist/js/treeshaking/router/runtime/utils.js +3 -3
  50. package/dist/js/treeshaking/ssr/cli/index.js +5 -5
  51. package/dist/js/treeshaking/ssr/index.js +6 -6
  52. package/dist/js/treeshaking/ssr/index.node.js +1 -1
  53. package/dist/js/treeshaking/ssr/prefetch.js +2 -2
  54. package/dist/js/treeshaking/ssr/prefetch.worker.js +191 -0
  55. package/dist/js/treeshaking/ssr/react/nossr/index.js +3 -3
  56. package/dist/js/treeshaking/ssr/react/prerender/index.js +2 -2
  57. package/dist/js/treeshaking/ssr/react/prerender/util.js +2 -2
  58. package/dist/js/treeshaking/ssr/serverRender/renderToStream/bulidTemplate.before.js +2 -2
  59. package/dist/js/treeshaking/ssr/serverRender/renderToStream/index.js +1 -1
  60. package/dist/js/treeshaking/ssr/serverRender/renderToStream/index.worker.js +32 -0
  61. package/dist/js/treeshaking/ssr/serverRender/renderToStream/loadable.js +1 -1
  62. package/dist/js/treeshaking/ssr/serverRender/renderToStream/renderToPipe.js +8 -8
  63. package/dist/js/treeshaking/ssr/serverRender/renderToStream/renderToPipe.worker.js +280 -0
  64. package/dist/js/treeshaking/ssr/serverRender/renderToStream/template.js +1 -1
  65. package/dist/js/treeshaking/ssr/serverRender/renderToString/entry.js +5 -5
  66. package/dist/js/treeshaking/ssr/serverRender/renderToString/index.js +1 -1
  67. package/dist/js/treeshaking/ssr/serverRender/renderToString/index.worker.js +167 -0
  68. package/dist/js/treeshaking/ssr/serverRender/renderToString/loadable.js +1 -1
  69. package/dist/js/treeshaking/ssr/serverRender/time.js +57 -0
  70. package/dist/js/treeshaking/ssr/serverRender/time.worker.js +75 -0
  71. package/dist/js/treeshaking/ssr/serverRender/utils.js +1 -57
  72. package/dist/js/treeshaking/ssr/utils.js +5 -5
  73. package/dist/js/treeshaking/state/cli/index.js +2 -2
  74. package/dist/js/treeshaking/state/runtime/plugin.js +3 -3
  75. package/dist/types/router/runtime/fetch.d.ts +2 -0
  76. package/dist/types/router/runtime/fetch.node.d.ts +2 -0
  77. package/dist/types/router/runtime/fetch.worker.d.ts +2 -0
  78. package/dist/types/ssr/prefetch.worker.d.ts +13 -0
  79. package/dist/types/ssr/react/nossr/index.d.ts +4 -2
  80. package/dist/types/ssr/serverRender/renderToStream/index.worker.d.ts +6 -0
  81. package/dist/types/ssr/serverRender/renderToStream/renderToPipe.worker.d.ts +8 -0
  82. package/dist/types/ssr/serverRender/renderToString/index.worker.d.ts +6 -0
  83. package/dist/types/ssr/serverRender/time.d.ts +1 -0
  84. package/dist/types/ssr/serverRender/time.worker.d.ts +1 -0
  85. package/dist/types/ssr/serverRender/utils.d.ts +2 -3
  86. package/package.json +6 -5
@@ -120,10 +120,10 @@ var useLoader = function(loaderFn) {
120
120
  delete options._cache;
121
121
  }
122
122
  var load = useCallback(function(params) {
123
- var ref, ref1, ref2, ref3, ref4;
123
+ var _unlistenLoaderChangeRef_current, _window__SSR_DATA_data_loadersData_id, _window__SSR_DATA, _window__SSR_DATA_data, _loaderRef_current;
124
124
  if (typeof params === "undefined") {
125
- var ref5;
126
- return (ref5 = loaderRef.current) === null || ref5 === void 0 ? void 0 : ref5.load();
125
+ var _loaderRef_current1;
126
+ return (_loaderRef_current1 = loaderRef.current) === null || _loaderRef_current1 === void 0 ? void 0 : _loaderRef_current1.load();
127
127
  }
128
128
  var id = loaderManager.add(function() {
129
129
  try {
@@ -139,26 +139,26 @@ var useLoader = function(loaderFn) {
139
139
  params: params
140
140
  }));
141
141
  loaderRef.current = loaderManager.get(id);
142
- (ref = unlistenLoaderChangeRef.current) === null || ref === void 0 ? void 0 : ref.call(unlistenLoaderChangeRef);
142
+ (_unlistenLoaderChangeRef_current = unlistenLoaderChangeRef.current) === null || _unlistenLoaderChangeRef_current === void 0 ? void 0 : _unlistenLoaderChangeRef_current.call(unlistenLoaderChangeRef);
143
143
  if (isSSRRender) {
144
144
  return void 0;
145
145
  }
146
146
  if (options.skip) {
147
147
  return void 0;
148
148
  }
149
- if (context._hydration && ((ref3 = window === null || window === void 0 ? void 0 : (ref1 = window._SSR_DATA) === null || ref1 === void 0 ? void 0 : (ref2 = ref1.data) === null || ref2 === void 0 ? void 0 : ref2.loadersData[id]) === null || ref3 === void 0 ? void 0 : ref3.error) === null) {
149
+ if (context._hydration && ((_window__SSR_DATA_data_loadersData_id = window === null || window === void 0 ? void 0 : (_window__SSR_DATA = window._SSR_DATA) === null || _window__SSR_DATA === void 0 ? void 0 : (_window__SSR_DATA_data = _window__SSR_DATA.data) === null || _window__SSR_DATA_data === void 0 ? void 0 : _window__SSR_DATA_data.loadersData[id]) === null || _window__SSR_DATA_data_loadersData_id === void 0 ? void 0 : _window__SSR_DATA_data_loadersData_id.error) === null) {
150
150
  return void 0;
151
151
  }
152
152
  var res = loaderRef.current.load();
153
- unlistenLoaderChangeRef.current = (ref4 = loaderRef.current) === null || ref4 === void 0 ? void 0 : ref4.onChange(function(_status, _result) {
153
+ unlistenLoaderChangeRef.current = (_loaderRef_current = loaderRef.current) === null || _loaderRef_current === void 0 ? void 0 : _loaderRef_current.onChange(function(_status, _result) {
154
154
  setResult(_result);
155
155
  if (_status === LoaderStatus.fulfilled) {
156
- var ref;
157
- options === null || options === void 0 ? void 0 : (ref = options.onSuccess) === null || ref === void 0 ? void 0 : ref.call(options, _result.data);
156
+ var _options_onSuccess;
157
+ options === null || options === void 0 ? void 0 : (_options_onSuccess = options.onSuccess) === null || _options_onSuccess === void 0 ? void 0 : _options_onSuccess.call(options, _result.data);
158
158
  }
159
159
  if (_status === LoaderStatus.rejected) {
160
- var ref1;
161
- options === null || options === void 0 ? void 0 : (ref1 = options.onError) === null || ref1 === void 0 ? void 0 : ref1.call(options, _result.error);
160
+ var _options_onError;
161
+ options === null || options === void 0 ? void 0 : (_options_onError = options.onError) === null || _options_onError === void 0 ? void 0 : _options_onError.call(options, _result.error);
162
162
  }
163
163
  });
164
164
  return res;
@@ -167,19 +167,19 @@ var useLoader = function(loaderFn) {
167
167
  ]);
168
168
  useEffect(function() {
169
169
  return function() {
170
- var ref;
171
- (ref = unlistenLoaderChangeRef.current) === null || ref === void 0 ? void 0 : ref.call(unlistenLoaderChangeRef);
170
+ var _unlistenLoaderChangeRef_current;
171
+ (_unlistenLoaderChangeRef_current = unlistenLoaderChangeRef.current) === null || _unlistenLoaderChangeRef_current === void 0 ? void 0 : _unlistenLoaderChangeRef_current.call(unlistenLoaderChangeRef);
172
172
  };
173
173
  }, []);
174
174
  useMemo(function() {
175
- var _params;
176
- var p = (_params = options.params) !== null && _params !== void 0 ? _params : loaderFn.id;
175
+ var _options_params;
176
+ var p = (_options_params = options.params) !== null && _options_params !== void 0 ? _options_params : loaderFn.id;
177
177
  invariant(typeof p !== "undefined" && p !== null, "Params is required in useLoader");
178
178
  load(p);
179
179
  }, [
180
180
  options.params
181
181
  ]);
182
- var ref = _slicedToArray(useState(loaderRef.current.result), 2), result = ref[0], setResult = ref[1];
182
+ var _useState = _slicedToArray(useState(loaderRef.current.result), 2), result = _useState[0], setResult = _useState[1];
183
183
  return _objectSpreadProps(_objectSpread({}, result), {
184
184
  reload: load
185
185
  });
@@ -5,7 +5,7 @@ import { Scripts } from "./Scripts";
5
5
  import { Links } from "./Links";
6
6
  import { DOCUMENT_META_PLACEHOLDER } from "./constants";
7
7
  function Head(props) {
8
- var ref = useContext(DocumentStructureContext), hasSetScripts = ref.hasSetScripts, hasSetLinks = ref.hasSetLinks;
8
+ var _useContext = useContext(DocumentStructureContext), hasSetScripts = _useContext.hasSetScripts, hasSetLinks = _useContext.hasSetLinks;
9
9
  var children = props.children;
10
10
  return /* @__PURE__ */ jsxs("head", {
11
11
  children: [
@@ -19,11 +19,11 @@ function findTargetElement(tag, children) {
19
19
  try {
20
20
  for(var _iterator = children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
21
21
  var item = _step.value;
22
- var ref;
22
+ var _item_props;
23
23
  if (tag === getEleType(item)) {
24
24
  return item;
25
25
  }
26
- if (item === null || item === void 0 ? void 0 : (ref = item.props) === null || ref === void 0 ? void 0 : ref.children) {
26
+ if (item === null || item === void 0 ? void 0 : (_item_props = item.props) === null || _item_props === void 0 ? void 0 : _item_props.children) {
27
27
  nextChildren = nextChildren.concat(item.props.children);
28
28
  }
29
29
  }
@@ -4,7 +4,7 @@ import { DocumentContext } from "./DocumentContext";
4
4
  import { DOCUMENT_SSR_PLACEHOLDER } from "./constants";
5
5
  function Root(props) {
6
6
  var rootId = props.rootId, children = props.children;
7
- var ref = useContext(DocumentContext), _templateParams = ref.templateParams, _mountId = _templateParams.mountId, mountId = _mountId === void 0 ? "root" : _mountId;
7
+ var _useContext = useContext(DocumentContext), _useContext_templateParams = _useContext.templateParams, _useContext_templateParams_mountId = _useContext_templateParams.mountId, mountId = _useContext_templateParams_mountId === void 0 ? "root" : _useContext_templateParams_mountId;
8
8
  return /* @__PURE__ */ jsxs("div", {
9
9
  id: "".concat(rootId || mountId),
10
10
  children: [
@@ -14,7 +14,7 @@ function Root(props) {
14
14
  });
15
15
  }
16
16
  function DefaultRoot(props) {
17
- var ref = useContext(DocumentContext), _templateParams = ref.templateParams, _mountId = _templateParams.mountId, mountId = _mountId === void 0 ? "root" : _mountId;
17
+ var _useContext = useContext(DocumentContext), _useContext_templateParams = _useContext.templateParams, _useContext_templateParams_mountId = _useContext_templateParams.mountId, mountId = _useContext_templateParams_mountId === void 0 ? "root" : _useContext_templateParams_mountId;
18
18
  return /* @__PURE__ */ jsxs("div", {
19
19
  id: "".concat(mountId),
20
20
  children: [
@@ -184,10 +184,10 @@ import { DocumentContext } from "../DocumentContext";
184
184
  import { DOCUMENT_SCRIPTS_PLACEHOLDER, DOCUMENT_LINKS_PLACEHOLDER, DOCUMENT_FILE_NAME, DOCUMENT_META_PLACEHOLDER, PLACEHOLDER_REPLACER_MAP, DOC_EXT, DOCUMENT_SSR_PLACEHOLDER, DOCUMENT_CHUNKSMAP_PLACEHOLDER, DOCUMENT_SSRDATASCRIPT_PLACEHOLDER, DOCUMENT_SCRIPT_PLACEHOLDER_START, DOCUMENT_SCRIPT_PLACEHOLDER_END, HTML_SEPARATOR } from "../constants";
185
185
  var debug = createDebugger("html_genarate");
186
186
  var getDocumenByEntryName = function getDocumenByEntryName(entrypoints, entryName, fallbackDir) {
187
- var ref;
188
- var entryDir = (ref = entrypoints.find(function(item) {
187
+ var _entrypoints_find;
188
+ var entryDir = (_entrypoints_find = entrypoints.find(function(item) {
189
189
  return item.entryName === entryName;
190
- })) === null || ref === void 0 ? void 0 : ref.absoluteEntryDir;
190
+ })) === null || _entrypoints_find === void 0 ? void 0 : _entrypoints_find.absoluteEntryDir;
191
191
  var entryDirs = DOC_EXT.map(function(item) {
192
192
  return "".concat(entryDir).concat(path.sep).concat(DOCUMENT_FILE_NAME, ".").concat(item);
193
193
  });
@@ -223,7 +223,7 @@ var cli_default = function() {
223
223
  }
224
224
  return __generator(this, function(_state) {
225
225
  documentEntry = function(entryName, templateParameters) {
226
- var ref = api.useAppContext(), entrypoints = ref.entrypoints, internalDirectory = ref.internalDirectory, appDirectory = ref.appDirectory;
226
+ var _api_useAppContext = api.useAppContext(), entrypoints = _api_useAppContext.entrypoints, internalDirectory = _api_useAppContext.internalDirectory, appDirectory = _api_useAppContext.appDirectory;
227
227
  var documentFilePath = getDocumenByEntryName(entrypoints, entryName, appDirectory);
228
228
  if (!documentFilePath) {
229
229
  return null;
@@ -54,8 +54,8 @@ import { getEntryOptions, createRuntimeExportsUtils, PLUGIN_SCHEMAS } from "@mod
54
54
  var PLUGIN_IDENTIFIER = "router";
55
55
  var ROUTES_IDENTIFIER = "routes";
56
56
  var isV5 = function(config) {
57
- var ref, ref1;
58
- return (config === null || config === void 0 ? void 0 : (ref = config.runtime) === null || ref === void 0 ? void 0 : (ref1 = ref.router) === null || ref1 === void 0 ? void 0 : ref1.mode) === "react-router-5";
57
+ var _config_runtime, _config_runtime_router;
58
+ return (config === null || config === void 0 ? void 0 : (_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : (_config_runtime_router = _config_runtime.router) === null || _config_runtime_router === void 0 ? void 0 : _config_runtime_router.mode) === "react-router-5";
59
59
  };
60
60
  var cli_default = function() {
61
61
  return {
@@ -0,0 +1,2 @@
1
+ function installGlobals() {}
2
+ export { installGlobals };
@@ -0,0 +1,2 @@
1
+ import { installGlobals } from "@remix-run/node";
2
+ export { installGlobals };
@@ -0,0 +1,2 @@
1
+ function installGlobals() {}
2
+ export { installGlobals };
@@ -68,7 +68,7 @@ function modifyRoutes(modifyFunction) {
68
68
  }
69
69
  }
70
70
  var routerPlugin = function(param) {
71
- var _serverBase = param.serverBase, serverBase = _serverBase === void 0 ? [] : _serverBase, _supportHtml5History = param.supportHtml5History, supportHtml5History = _supportHtml5History === void 0 ? true : _supportHtml5History, _basename = param.basename, basename = _basename === void 0 ? "" : _basename, routesConfig = param.routesConfig, createRoutes = param.createRoutes;
71
+ var _param_serverBase = param.serverBase, serverBase = _param_serverBase === void 0 ? [] : _param_serverBase, _param_supportHtml5History = param.supportHtml5History, supportHtml5History = _param_supportHtml5History === void 0 ? true : _param_supportHtml5History, _param_basename = param.basename, basename = _param_basename === void 0 ? "" : _param_basename, routesConfig = param.routesConfig, createRoutes = param.createRoutes;
72
72
  var select = function(pathname) {
73
73
  return serverBase.find(function(baseUrl) {
74
74
  return pathname.search(baseUrl) === 0;
@@ -98,10 +98,10 @@ var routerPlugin = function(param) {
98
98
  }
99
99
  var getRouteApp = function() {
100
100
  return function(props) {
101
- var ref;
101
+ var _window__SERVER_DATA;
102
102
  beforeCreateRouter = true;
103
103
  var routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes(finalRouteConfig));
104
- var baseUrl = ((ref = window._SERVER_DATA) === null || ref === void 0 ? void 0 : ref.router.baseUrl) || select(location.pathname);
104
+ var baseUrl = ((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname);
105
105
  var _basename = baseUrl === "/" ? urlJoin(baseUrl, basename) : baseUrl;
106
106
  var router = supportHtml5History ? createBrowserRouter(routes, {
107
107
  basename: _basename
@@ -232,10 +232,10 @@ import { useContext } from "react";
232
232
  import { createStaticHandler } from "@remix-run/router";
233
233
  import { createStaticRouter, StaticRouterProvider } from "react-router-dom/server";
234
234
  import hoistNonReactStatics from "hoist-non-react-statics";
235
- import { installGlobals } from "@remix-run/node";
236
235
  import { createRoutesFromElements } from "react-router-dom";
237
236
  import { RuntimeReactContext } from "../../core";
238
237
  import { renderRoutes, urlJoin } from "./utils";
238
+ import { installGlobals } from "./fetch";
239
239
  installGlobals();
240
240
  function createFetchRequest(req) {
241
241
  var origin = "".concat(req.protocol, "://").concat(req.host);
@@ -252,8 +252,8 @@ function createFetchHeaders(requestHeaders) {
252
252
  var headers = new Headers();
253
253
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
254
254
  try {
255
- for(var _iterator = Object.entries(requestHeaders)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
256
- var _value = _slicedToArray(_step.value, 2), key = _value[0], values = _value[1];
255
+ for(var _iterator = Object.entries(requestHeaders || {})[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
256
+ var _step_value = _slicedToArray(_step.value, 2), key = _step_value[0], values = _step_value[1];
257
257
  if (values) {
258
258
  if (Array.isArray(values)) {
259
259
  var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
@@ -298,7 +298,7 @@ function createFetchHeaders(requestHeaders) {
298
298
  return headers;
299
299
  }
300
300
  var routerPlugin = function(param) {
301
- var _basename = param.basename, basename = _basename === void 0 ? "" : _basename, routesConfig = param.routesConfig, createRoutes = param.createRoutes;
301
+ var _param_basename = param.basename, basename = _param_basename === void 0 ? "" : _param_basename, routesConfig = param.routesConfig, createRoutes = param.createRoutes;
302
302
  return {
303
303
  name: "@modern-js/plugin-router",
304
304
  setup: function() {
@@ -362,7 +362,7 @@ var routerPlugin = function(param) {
362
362
  }
363
363
  var getRouteApp = function() {
364
364
  return function(props) {
365
- var ref = useContext(RuntimeReactContext), router = ref.router, routerContext = ref.routerContext;
365
+ var _useContext = useContext(RuntimeReactContext), router = _useContext.router, routerContext = _useContext.routerContext;
366
366
  return /* @__PURE__ */ jsx(App, _objectSpreadProps(_objectSpread({}, props), {
367
367
  children: /* @__PURE__ */ jsx(StaticRouterProvider, {
368
368
  router: router,
@@ -203,9 +203,9 @@ function renderRoutes(routesConfig) {
203
203
  return routeElements;
204
204
  }
205
205
  function getLocation(serverContext) {
206
- var ref;
207
- var ref1 = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {}, pathname = ref1.pathname, url = ref1.url;
208
- var cleanUrl = (ref = url === null || url === void 0 ? void 0 : url.replace("http://", "")) === null || ref === void 0 ? void 0 : ref.replace("https://", "");
206
+ var _url_replace;
207
+ var _ref = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {}, pathname = _ref.pathname, url = _ref.url;
208
+ var cleanUrl = (_url_replace = url === null || url === void 0 ? void 0 : url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
209
209
  var index = (cleanUrl || "").indexOf(pathname);
210
210
  if (index === -1) {
211
211
  return pathname;
@@ -118,7 +118,7 @@ var cli_default = function() {
118
118
  },
119
119
  tools: {
120
120
  webpackChain: function(chain, param) {
121
- var name = param.name, isServer = param.isServer, CHAIN_ID = param.CHAIN_ID;
121
+ var name = param.name, isServer = param.isServer, isServiceWorker = param.isServiceWorker, CHAIN_ID = param.CHAIN_ID;
122
122
  var userConfig = api.useResolvedConfigContext();
123
123
  if (isUseSSRBundle(userConfig) && name !== "server" && hasStringSSREntry(userConfig)) {
124
124
  var LoadableWebpackPlugin = require("@loadable/webpack-plugin");
@@ -128,7 +128,7 @@ var cli_default = function() {
128
128
  }
129
129
  ]);
130
130
  }
131
- var modernVars = _defineProperty({}, "process.env.MODERN_TARGET", JSON.stringify(isServer ? "node" : "browser"));
131
+ var modernVars = _defineProperty({}, "process.env.MODERN_TARGET", JSON.stringify(isServer || isServiceWorker ? "node" : "browser"));
132
132
  chain.plugin(CHAIN_ID.PLUGIN.DEFINE).tap(function(args) {
133
133
  var _args = _toArray(args), vars = _args[0], rest = _args.slice(1);
134
134
  return [
@@ -150,13 +150,13 @@ var cli_default = function() {
150
150
  var entrypoint = param.entrypoint, imports = param.imports;
151
151
  var entryName = entrypoint.entryName, fileSystemRoutes = entrypoint.fileSystemRoutes;
152
152
  var userConfig = api.useResolvedConfigContext();
153
- var ref = api.useAppContext(), packageName = ref.packageName, entrypoints = ref.entrypoints;
153
+ var _api_useAppContext = api.useAppContext(), packageName = _api_useAppContext.packageName, entrypoints = _api_useAppContext.entrypoints;
154
154
  pluginsExportsUtils.addExport("export { default as ssr } from '@modern-js/runtime/ssr'");
155
155
  var ssrConfig = getEntryOptions(entryName, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
156
156
  if (typeof ssrConfig === "object" && ssrConfig.mode === "stream") {
157
- var ref1;
157
+ var _runtimeConfig_router;
158
158
  var runtimeConfig = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName);
159
- if ((runtimeConfig === null || runtimeConfig === void 0 ? void 0 : (ref1 = runtimeConfig.router) === null || ref1 === void 0 ? void 0 : ref1.mode) === "react-router-5") {
159
+ if ((runtimeConfig === null || runtimeConfig === void 0 ? void 0 : (_runtimeConfig_router = runtimeConfig.router) === null || _runtimeConfig_router === void 0 ? void 0 : _runtimeConfig_router.mode) === "react-router-5") {
160
160
  throw new Error("router v5 plugin doesn't support streaming SSR, check your config 'runtime.router'");
161
161
  }
162
162
  if (fileSystemRoutes && !entrypoint.nestedRoutesEntry) {
@@ -188,7 +188,7 @@ var ssr = function(config) {
188
188
  return {
189
189
  client: function() {
190
190
  var _ref = _asyncToGenerator(function(param) {
191
- var App, context, ModernRender, ModernHydrate, ref, hydrateContext, callback, renderLevel;
191
+ var App, context, ModernRender, ModernHydrate, _window__SSR_DATA, hydrateContext, callback, renderLevel;
192
192
  function stringSSRHydrate() {
193
193
  if (renderLevel === RenderLevel.CLIENT_RENDER || renderLevel === RenderLevel.SERVER_PREFETCH) {
194
194
  ModernRender(/* @__PURE__ */ jsx(App, {
@@ -248,7 +248,7 @@ var ssr = function(config) {
248
248
  callback = function() {
249
249
  delete hydrateContext._hydration;
250
250
  };
251
- renderLevel = (window === null || window === void 0 ? void 0 : (ref = window._SSR_DATA) === null || ref === void 0 ? void 0 : ref.renderLevel) || RenderLevel.CLIENT_RENDER;
251
+ renderLevel = (window === null || window === void 0 ? void 0 : (_window__SSR_DATA = window._SSR_DATA) === null || _window__SSR_DATA === void 0 ? void 0 : _window__SSR_DATA.renderLevel) || RenderLevel.CLIENT_RENDER;
252
252
  if (isReact18() && config.mode === "stream") {
253
253
  return [
254
254
  2,
@@ -267,8 +267,8 @@ var ssr = function(config) {
267
267
  }(),
268
268
  init: function init(param, next) {
269
269
  var context = param.context;
270
- var ref, ref1;
271
- var request = window === null || window === void 0 ? void 0 : (ref = window._SSR_DATA) === null || ref === void 0 ? void 0 : (ref1 = ref.context) === null || ref1 === void 0 ? void 0 : ref1.request;
270
+ var _window__SSR_DATA, _window__SSR_DATA_context;
271
+ var request = window === null || window === void 0 ? void 0 : (_window__SSR_DATA = window._SSR_DATA) === null || _window__SSR_DATA === void 0 ? void 0 : (_window__SSR_DATA_context = _window__SSR_DATA.context) === null || _window__SSR_DATA_context === void 0 ? void 0 : _window__SSR_DATA_context.request;
272
272
  if (!request) {
273
273
  context.ssrContext = _objectSpreadProps(_objectSpread({}, context.ssrContext), {
274
274
  response: mockResp,
@@ -286,8 +286,8 @@ var ssr = function(config) {
286
286
  },
287
287
  pickContext: function(param, next) {
288
288
  var context = param.context, pickedContext = param.pickedContext;
289
- var ref, ref1;
290
- var request = window === null || window === void 0 ? void 0 : (ref = window._SSR_DATA) === null || ref === void 0 ? void 0 : (ref1 = ref.context) === null || ref1 === void 0 ? void 0 : ref1.request;
289
+ var _window__SSR_DATA, _window__SSR_DATA_context;
290
+ var request = window === null || window === void 0 ? void 0 : (_window__SSR_DATA = window._SSR_DATA) === null || _window__SSR_DATA === void 0 ? void 0 : (_window__SSR_DATA_context = _window__SSR_DATA.context) === null || _window__SSR_DATA_context === void 0 ? void 0 : _window__SSR_DATA_context.request;
291
291
  var initialData = context.initialData;
292
292
  if (!request) {
293
293
  return next({
@@ -220,7 +220,7 @@ var ssr = function() {
220
220
  },
221
221
  pickContext: function(param, next) {
222
222
  var context = param.context, pickedContext = param.pickedContext;
223
- var ref = context === null || context === void 0 ? void 0 : context.ssrContext, request = ref.request, response = ref.response;
223
+ var _ref = context === null || context === void 0 ? void 0 : context.ssrContext, request = _ref.request, response = _ref.response;
224
224
  var initialData = context.initialData;
225
225
  return next({
226
226
  context: context,
@@ -132,7 +132,7 @@ var prefetch = function() {
132
132
  return [
133
133
  2,
134
134
  run(context.ssrContext.request.headers, /*#__PURE__*/ _asyncToGenerator(function() {
135
- var ref, ssrContext, loadableStats, extractor, loadersData;
135
+ var _context_store, ssrContext, loadableStats, extractor, loadersData;
136
136
  return __generator(this, function(_state) {
137
137
  switch(_state.label){
138
138
  case 0:
@@ -182,7 +182,7 @@ var prefetch = function() {
182
182
  loadersData: loadersData,
183
183
  initialData: context.initialData,
184
184
  i18nData: context.__i18nData__,
185
- storeState: context === null || context === void 0 ? void 0 : (ref = context.store) === null || ref === void 0 ? void 0 : ref.getState()
185
+ storeState: context === null || context === void 0 ? void 0 : (_context_store = context.store) === null || _context_store === void 0 ? void 0 : _context_store.getState()
186
186
  }
187
187
  ];
188
188
  }
@@ -0,0 +1,191 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _asyncToGenerator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ var __generator = this && this.__generator || function(thisArg, body) {
31
+ var f, y, t, g, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ };
40
+ return(g = {
41
+ next: verb(0),
42
+ "throw": verb(1),
43
+ "return": verb(2)
44
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
+ return this;
46
+ }), g);
47
+ function verb(n) {
48
+ return function(v) {
49
+ return step([
50
+ n,
51
+ v
52
+ ]);
53
+ };
54
+ }
55
+ function step(op) {
56
+ if (f) throw new TypeError("Generator is already executing.");
57
+ while(_)try {
58
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
+ if (y = 0, t) op = [
60
+ op[0] & 2,
61
+ t.value
62
+ ];
63
+ switch(op[0]){
64
+ case 0:
65
+ case 1:
66
+ t = op;
67
+ break;
68
+ case 4:
69
+ _.label++;
70
+ return {
71
+ value: op[1],
72
+ done: false
73
+ };
74
+ case 5:
75
+ _.label++;
76
+ y = op[1];
77
+ op = [
78
+ 0
79
+ ];
80
+ continue;
81
+ case 7:
82
+ op = _.ops.pop();
83
+ _.trys.pop();
84
+ continue;
85
+ default:
86
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
+ _ = 0;
88
+ continue;
89
+ }
90
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
+ _.label = op[1];
92
+ break;
93
+ }
94
+ if (op[0] === 6 && _.label < t[1]) {
95
+ _.label = t[1];
96
+ t = op;
97
+ break;
98
+ }
99
+ if (t && _.label < t[2]) {
100
+ _.label = t[2];
101
+ _.ops.push(op);
102
+ break;
103
+ }
104
+ if (t[2]) _.ops.pop();
105
+ _.trys.pop();
106
+ continue;
107
+ }
108
+ op = body.call(thisArg, _);
109
+ } catch (e) {
110
+ op = [
111
+ 6,
112
+ e
113
+ ];
114
+ y = 0;
115
+ } finally{
116
+ f = t = 0;
117
+ }
118
+ if (op[0] & 5) throw op[1];
119
+ return {
120
+ value: op[0] ? op[1] : void 0,
121
+ done: true
122
+ };
123
+ }
124
+ };
125
+ import { jsx } from "react/jsx-runtime";
126
+ import { renderToStaticMarkup } from "react-dom/server";
127
+ import { ChunkExtractor } from "@loadable/server";
128
+ var prefetch = function() {
129
+ var _ref = _asyncToGenerator(function(App, context) {
130
+ var _context_store, ssrContext, loadableStats, extractor, loadersData;
131
+ return __generator(this, function(_state) {
132
+ switch(_state.label){
133
+ case 0:
134
+ ssrContext = context.ssrContext;
135
+ loadableStats = ssrContext.loadableStats;
136
+ if (loadableStats) {
137
+ extractor = new ChunkExtractor({
138
+ stats: loadableStats,
139
+ entrypoints: [
140
+ ssrContext.entryName
141
+ ].filter(Boolean)
142
+ });
143
+ renderToStaticMarkup(extractor.collectChunks(/* @__PURE__ */ jsx(App, {
144
+ context: context
145
+ })));
146
+ } else {
147
+ renderToStaticMarkup(/* @__PURE__ */ jsx(App, {
148
+ context: context
149
+ }));
150
+ }
151
+ if (!context.loaderManager.hasPendingLoaders()) {
152
+ return [
153
+ 2,
154
+ {
155
+ initialData: context.initialData,
156
+ i18nData: context.__i18nData__
157
+ }
158
+ ];
159
+ }
160
+ return [
161
+ 4,
162
+ context.loaderManager.awaitPendingLoaders()
163
+ ];
164
+ case 1:
165
+ loadersData = _state.sent();
166
+ Object.keys(loadersData).forEach(function(id) {
167
+ var data = loadersData[id];
168
+ if (data._error) {
169
+ ssrContext.logger.error("App Prefetch Loader", data._error);
170
+ ssrContext.metrics.emitCounter("app.prefetch.loader.error", 1);
171
+ delete data._error;
172
+ }
173
+ });
174
+ return [
175
+ 2,
176
+ {
177
+ loadersData: loadersData,
178
+ initialData: context.initialData,
179
+ i18nData: context.__i18nData__,
180
+ storeState: context === null || context === void 0 ? void 0 : (_context_store = context.store) === null || _context_store === void 0 ? void 0 : _context_store.getState()
181
+ }
182
+ ];
183
+ }
184
+ });
185
+ });
186
+ return function prefetch(App, context) {
187
+ return _ref.apply(this, arguments);
188
+ };
189
+ }();
190
+ var prefetch_worker_default = prefetch;
191
+ export { prefetch_worker_default as default };
@@ -47,12 +47,12 @@ function _unsupportedIterableToArray(o, minLen) {
47
47
  import React, { useEffect, useState } from "react";
48
48
  var csr = false;
49
49
  var NoSSR = function(props) {
50
- var ref = _slicedToArray(useState(csr), 2), isMounted = ref[0], setMounted = ref[1];
50
+ var _useState = _slicedToArray(useState(csr), 2), isMounted = _useState[0], setMounted = _useState[1];
51
51
  useEffect(function() {
52
52
  csr = true;
53
53
  setMounted(true);
54
54
  });
55
- var children = props.children;
56
- return React.createElement(React.Fragment, null, isMounted ? children : null);
55
+ var children = props.children, _props_fallback = props.fallback, fallback = _props_fallback === void 0 ? null : _props_fallback;
56
+ return React.createElement(React.Fragment, null, isMounted ? children : fallback);
57
57
  };
58
58
  export { NoSSR };
@@ -181,7 +181,7 @@ var reducePropsToState = function(propsList) {
181
181
  return reduceProps;
182
182
  };
183
183
  function factory(Component) {
184
- var _Component;
184
+ var _React_Component;
185
185
  var Spr = /*#__PURE__*/ function(_superClass) {
186
186
  "use strict";
187
187
  _inherits(Spr, _superClass);
@@ -220,7 +220,7 @@ function factory(Component) {
220
220
  }
221
221
  ]);
222
222
  return Spr;
223
- }(_Component = React.Component);
223
+ }(_React_Component = React.Component);
224
224
  _defineProperty(Spr, "peek", Component.peek);
225
225
  _defineProperty(Spr, "rewind", Component.rewind);
226
226
  _defineProperty(Spr, "config", function() {
@@ -54,9 +54,9 @@ var aggKeysFromPropsList = function aggKeysFromPropsList2(propsList, propName) {
54
54
  return result;
55
55
  }, initResult);
56
56
  return REQUEST_META.reduce(function(result, next) {
57
- var ref;
57
+ var _result_key;
58
58
  var key = next;
59
- if (result[key] && ((ref = result[key]) === null || ref === void 0 ? void 0 : ref.length) === 0) {
59
+ if (result[key] && ((_result_key = result[key]) === null || _result_key === void 0 ? void 0 : _result_key.length) === 0) {
60
60
  delete result[key];
61
61
  }
62
62
  return result;
@@ -81,7 +81,7 @@ function getHeadTemplate(beforeEntryTemplate, context) {
81
81
  var routeManifest2 = routeAssets[routeId];
82
82
  if (routeManifest2) {
83
83
  var _cssChunks;
84
- var _assets = routeManifest2.assets, assets = _assets === void 0 ? [] : _assets;
84
+ var _routeManifest2_assets = routeManifest2.assets, assets = _routeManifest2_assets === void 0 ? [] : _routeManifest2_assets;
85
85
  var _cssChunks1 = assets.filter(function(asset) {
86
86
  return asset === null || asset === void 0 ? void 0 : asset.endsWith(".css");
87
87
  });
@@ -102,7 +102,7 @@ function getHeadTemplate(beforeEntryTemplate, context) {
102
102
  },
103
103
  injectCss
104
104
  ];
105
- var ref = _slicedToArray(beforeEntryTemplate.match(HEAD_REG_EXP) || [], 1), tmp = ref[0], headTemplate = tmp === void 0 ? "" : tmp;
105
+ var _ref = _slicedToArray(beforeEntryTemplate.match(HEAD_REG_EXP) || [], 1), tmp = _ref[0], headTemplate = tmp === void 0 ? "" : tmp;
106
106
  if (!headTemplate.length) {
107
107
  return "";
108
108
  }
@@ -125,7 +125,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
125
125
  import { createElement } from "react";
126
126
  import { run } from "@modern-js/utils/ssr";
127
127
  import { PreRender } from "../../react/prerender";
128
- import { time } from "../utils";
128
+ import { time } from "../time";
129
129
  import renderToPipe from "./renderToPipe";
130
130
  var render = function(param) {
131
131
  var App = param.App, context = param.context;