@modern-js/runtime 2.0.1 → 2.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # @modern-js/runtime
2
2
 
3
+ ## 2.1.0
4
+
5
+ ### Patch Changes
6
+
7
+ - f3237db: fix: loadable component should not be wrapped in suspense
8
+ fix: loadable component 不应该被 suspense 包裹
9
+ - 776cc27: chore: hard code MODER_TARGET
10
+ chore: 硬编码 MODER_TARGET
11
+ - 35d3e84: fix: add missing esbuild
12
+ fix: 添加缺失的 esbuild
13
+ - Updated dependencies [837620c]
14
+ - Updated dependencies [8a9482c]
15
+ - @modern-js/utils@2.1.0
16
+ - @modern-js/plugin@2.1.0
17
+ - @modern-js/types@2.1.0
18
+
19
+ ## 2.0.2
20
+
21
+ ### Patch Changes
22
+
23
+ - 39988b2: feat: advance the timing of static resource loading
24
+ feat: 将嵌套路由下静态资源加载时机提前
25
+ - Updated dependencies [39988b2]
26
+ - @modern-js/types@2.0.2
27
+ - @modern-js/utils@2.0.2
28
+ - @modern-js/plugin@2.0.2
29
+
3
30
  ## 2.0.1
4
31
 
5
32
  ### Patch Changes
@@ -33,14 +33,14 @@ import { jsx } from "react/jsx-runtime";
33
33
  import { Suspense } from "react";
34
34
  import { Route } from "react-router-dom";
35
35
  import { DefaultNotFound } from "./DefaultNotFound";
36
- import { RootLayout } from "./root";
37
36
  const renderNestedRoute = (nestedRoute, parent) => {
38
- const { children, index, id, component: Component } = nestedRoute;
37
+ const { children, index, id, component, isRoot } = nestedRoute;
38
+ const Component = component;
39
39
  const routeProps = {
40
40
  caseSensitive: nestedRoute.caseSensitive,
41
41
  path: nestedRoute.path,
42
42
  id: nestedRoute.id,
43
- loader: nestedRoute.loader,
43
+ loader: createLoader(nestedRoute),
44
44
  action: nestedRoute.action,
45
45
  hasErrorBoundary: nestedRoute.hasErrorBoundary,
46
46
  shouldRevalidate: nestedRoute.shouldRevalidate,
@@ -57,26 +57,26 @@ const renderNestedRoute = (nestedRoute, parent) => {
57
57
  if (Component) {
58
58
  if (parent == null ? void 0 : parent.loading) {
59
59
  const Loading = parent.loading;
60
- element = /* @__PURE__ */ jsx(Suspense, {
61
- fallback: /* @__PURE__ */ jsx(Loading, {}),
62
- children: /* @__PURE__ */ jsx(Component, {})
63
- });
64
- } else if (!(parent == null ? void 0 : parent.index)) {
60
+ if (isLoadableComponent(Component)) {
61
+ element = /* @__PURE__ */ jsx(Component, {
62
+ fallback: /* @__PURE__ */ jsx(Loading, {})
63
+ });
64
+ } else {
65
+ element = /* @__PURE__ */ jsx(Suspense, {
66
+ fallback: /* @__PURE__ */ jsx(Loading, {}),
67
+ children: /* @__PURE__ */ jsx(Component, {})
68
+ });
69
+ }
70
+ } else if (isLoadableComponent(Component) || isRoot) {
71
+ element = /* @__PURE__ */ jsx(Component, {});
72
+ } else {
65
73
  element = /* @__PURE__ */ jsx(Suspense, {
66
74
  children: /* @__PURE__ */ jsx(Component, {})
67
75
  });
68
- } else {
69
- element = /* @__PURE__ */ jsx(Component, {});
70
76
  }
71
77
  } else {
72
78
  nestedRoute.loading = parent == null ? void 0 : parent.loading;
73
79
  }
74
- if (!parent && element) {
75
- element = /* @__PURE__ */ jsx(RootLayout, {
76
- routes: [nestedRoute],
77
- children: element
78
- });
79
- }
80
80
  if (element) {
81
81
  routeProps.element = element;
82
82
  }
@@ -165,6 +165,27 @@ function standardSlash(str) {
165
165
  }
166
166
  return addr;
167
167
  }
168
+ function createLoader(route) {
169
+ const { loader } = route;
170
+ if (loader) {
171
+ return (args) => {
172
+ if (typeof route.lazyImport === "function") {
173
+ route.lazyImport();
174
+ }
175
+ return loader(args);
176
+ };
177
+ } else {
178
+ return () => {
179
+ if (typeof route.lazyImport === "function") {
180
+ route.lazyImport();
181
+ }
182
+ return null;
183
+ };
184
+ }
185
+ }
186
+ function isLoadableComponent(component) {
187
+ return component && component.displayName === "Loadable" && component.preload && typeof component.preload === "function";
188
+ }
168
189
  export {
169
190
  getLocation,
170
191
  getRouteComponents,
@@ -67,9 +67,8 @@ var cli_default = () => ({
67
67
  { filename: LOADABLE_STATS_FILE }
68
68
  ]);
69
69
  }
70
- const prefix = `${appContext.metaName.split(/[-_]/)[0]}_`.toUpperCase();
71
70
  const modernVars = {
72
- [`process.env.${prefix}TARGET`]: JSON.stringify(
71
+ [`process.env.MODERN_TARGET`]: JSON.stringify(
73
72
  isServer ? "node" : "browser"
74
73
  )
75
74
  };
@@ -57,14 +57,14 @@ var import_jsx_runtime = require("react/jsx-runtime");
57
57
  var import_react = require("react");
58
58
  var import_react_router_dom = require("react-router-dom");
59
59
  var import_DefaultNotFound = require("./DefaultNotFound");
60
- var import_root = require("./root");
61
60
  const renderNestedRoute = (nestedRoute, parent) => {
62
- const { children, index, id, component: Component } = nestedRoute;
61
+ const { children, index, id, component, isRoot } = nestedRoute;
62
+ const Component = component;
63
63
  const routeProps = {
64
64
  caseSensitive: nestedRoute.caseSensitive,
65
65
  path: nestedRoute.path,
66
66
  id: nestedRoute.id,
67
- loader: nestedRoute.loader,
67
+ loader: createLoader(nestedRoute),
68
68
  action: nestedRoute.action,
69
69
  hasErrorBoundary: nestedRoute.hasErrorBoundary,
70
70
  shouldRevalidate: nestedRoute.shouldRevalidate,
@@ -81,26 +81,26 @@ const renderNestedRoute = (nestedRoute, parent) => {
81
81
  if (Component) {
82
82
  if (parent == null ? void 0 : parent.loading) {
83
83
  const Loading = parent.loading;
84
- element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, {
85
- fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Loading, {}),
86
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {})
87
- });
88
- } else if (!(parent == null ? void 0 : parent.index)) {
84
+ if (isLoadableComponent(Component)) {
85
+ element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {
86
+ fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Loading, {})
87
+ });
88
+ } else {
89
+ element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, {
90
+ fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Loading, {}),
91
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {})
92
+ });
93
+ }
94
+ } else if (isLoadableComponent(Component) || isRoot) {
95
+ element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {});
96
+ } else {
89
97
  element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, {
90
98
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {})
91
99
  });
92
- } else {
93
- element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {});
94
100
  }
95
101
  } else {
96
102
  nestedRoute.loading = parent == null ? void 0 : parent.loading;
97
103
  }
98
- if (!parent && element) {
99
- element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_root.RootLayout, {
100
- routes: [nestedRoute],
101
- children: element
102
- });
103
- }
104
104
  if (element) {
105
105
  routeProps.element = element;
106
106
  }
@@ -189,6 +189,27 @@ function standardSlash(str) {
189
189
  }
190
190
  return addr;
191
191
  }
192
+ function createLoader(route) {
193
+ const { loader } = route;
194
+ if (loader) {
195
+ return (args) => {
196
+ if (typeof route.lazyImport === "function") {
197
+ route.lazyImport();
198
+ }
199
+ return loader(args);
200
+ };
201
+ } else {
202
+ return () => {
203
+ if (typeof route.lazyImport === "function") {
204
+ route.lazyImport();
205
+ }
206
+ return null;
207
+ };
208
+ }
209
+ }
210
+ function isLoadableComponent(component) {
211
+ return component && component.displayName === "Loadable" && component.preload && typeof component.preload === "function";
212
+ }
192
213
  // Annotate the CommonJS export names for ESM import in node:
193
214
  0 && (module.exports = {
194
215
  getLocation,
@@ -86,9 +86,8 @@ var cli_default = () => ({
86
86
  { filename: import_utils.LOADABLE_STATS_FILE }
87
87
  ]);
88
88
  }
89
- const prefix = `${appContext.metaName.split(/[-_]/)[0]}_`.toUpperCase();
90
89
  const modernVars = {
91
- [`process.env.${prefix}TARGET`]: JSON.stringify(
90
+ [`process.env.MODERN_TARGET`]: JSON.stringify(
92
91
  isServer ? "node" : "browser"
93
92
  )
94
93
  };
@@ -81,14 +81,14 @@ import { jsx } from "react/jsx-runtime";
81
81
  import { Suspense } from "react";
82
82
  import { Route } from "react-router-dom";
83
83
  import { DefaultNotFound } from "./DefaultNotFound";
84
- import { RootLayout } from "./root";
85
84
  var renderNestedRoute = function(nestedRoute, parent) {
86
- var children = nestedRoute.children, index = nestedRoute.index, id = nestedRoute.id, Component = nestedRoute.component;
85
+ var children = nestedRoute.children, index = nestedRoute.index, id = nestedRoute.id, component = nestedRoute.component, isRoot = nestedRoute.isRoot;
86
+ var Component = component;
87
87
  var routeProps = {
88
88
  caseSensitive: nestedRoute.caseSensitive,
89
89
  path: nestedRoute.path,
90
90
  id: nestedRoute.id,
91
- loader: nestedRoute.loader,
91
+ loader: createLoader(nestedRoute),
92
92
  action: nestedRoute.action,
93
93
  hasErrorBoundary: nestedRoute.hasErrorBoundary,
94
94
  shouldRevalidate: nestedRoute.shouldRevalidate,
@@ -105,28 +105,26 @@ var renderNestedRoute = function(nestedRoute, parent) {
105
105
  if (Component) {
106
106
  if (parent === null || parent === void 0 ? void 0 : parent.loading) {
107
107
  var Loading = parent.loading;
108
- element = /* @__PURE__ */ jsx(Suspense, {
109
- fallback: /* @__PURE__ */ jsx(Loading, {}),
110
- children: /* @__PURE__ */ jsx(Component, {})
111
- });
112
- } else if (!(parent === null || parent === void 0 ? void 0 : parent.index)) {
108
+ if (isLoadableComponent(Component)) {
109
+ element = /* @__PURE__ */ jsx(Component, {
110
+ fallback: /* @__PURE__ */ jsx(Loading, {})
111
+ });
112
+ } else {
113
+ element = /* @__PURE__ */ jsx(Suspense, {
114
+ fallback: /* @__PURE__ */ jsx(Loading, {}),
115
+ children: /* @__PURE__ */ jsx(Component, {})
116
+ });
117
+ }
118
+ } else if (isLoadableComponent(Component) || isRoot) {
119
+ element = /* @__PURE__ */ jsx(Component, {});
120
+ } else {
113
121
  element = /* @__PURE__ */ jsx(Suspense, {
114
122
  children: /* @__PURE__ */ jsx(Component, {})
115
123
  });
116
- } else {
117
- element = /* @__PURE__ */ jsx(Component, {});
118
124
  }
119
125
  } else {
120
126
  nestedRoute.loading = parent === null || parent === void 0 ? void 0 : parent.loading;
121
127
  }
122
- if (!parent && element) {
123
- element = /* @__PURE__ */ jsx(RootLayout, {
124
- routes: [
125
- nestedRoute
126
- ],
127
- children: element
128
- });
129
- }
130
128
  if (element) {
131
129
  routeProps.element = element;
132
130
  }
@@ -237,4 +235,25 @@ function standardSlash(str) {
237
235
  }
238
236
  return addr;
239
237
  }
238
+ function createLoader(route) {
239
+ var loader = route.loader;
240
+ if (loader) {
241
+ return function(args) {
242
+ if (typeof route.lazyImport === "function") {
243
+ route.lazyImport();
244
+ }
245
+ return loader(args);
246
+ };
247
+ } else {
248
+ return function() {
249
+ if (typeof route.lazyImport === "function") {
250
+ route.lazyImport();
251
+ }
252
+ return null;
253
+ };
254
+ }
255
+ }
256
+ function isLoadableComponent(component) {
257
+ return component && component.displayName === "Loadable" && component.preload && typeof component.preload === "function";
258
+ }
240
259
  export { getLocation, getRouteComponents, renderRoutes, standardSlash, urlJoin };
@@ -128,8 +128,7 @@ var cli_default = function() {
128
128
  }
129
129
  ]);
130
130
  }
131
- var prefix = "".concat(appContext.metaName.split(/[-_]/)[0], "_").toUpperCase();
132
- var modernVars = _defineProperty({}, "process.env.".concat(prefix, "TARGET"), JSON.stringify(isServer ? "node" : "browser"));
131
+ var modernVars = _defineProperty({}, "process.env.MODERN_TARGET", JSON.stringify(isServer ? "node" : "browser"));
133
132
  chain.plugin(CHAIN_ID.PLUGIN.DEFINE).tap(function(args) {
134
133
  var _args = _toArray(args), vars = _args[0], rest = _args.slice(1);
135
134
  return [
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.0.1",
14
+ "version": "2.1.0",
15
15
  "engines": {
16
16
  "node": ">=14.17.6"
17
17
  },
@@ -155,9 +155,10 @@
155
155
  "redux-logger": "^3.0.6",
156
156
  "serialize-javascript": "^6.0.0",
157
157
  "styled-components": "^5.3.1",
158
- "@modern-js/plugin": "2.0.1",
159
- "@modern-js/types": "2.0.1",
160
- "@modern-js/utils": "2.0.1"
158
+ "esbuild": "0.15.7",
159
+ "@modern-js/plugin": "2.1.0",
160
+ "@modern-js/types": "2.1.0",
161
+ "@modern-js/utils": "2.1.0"
161
162
  },
162
163
  "peerDependencies": {
163
164
  "react": ">=17",
@@ -178,11 +179,11 @@
178
179
  "react-dom": "^18",
179
180
  "ts-jest": "^27.0.4",
180
181
  "typescript": "^4",
181
- "@modern-js/app-tools": "2.0.1",
182
- "@modern-js/core": "2.0.1",
183
- "@modern-js/server-core": "2.0.1",
184
- "@scripts/jest-config": "2.0.1",
185
- "@scripts/build": "2.0.1"
182
+ "@modern-js/app-tools": "2.1.0",
183
+ "@modern-js/core": "2.1.0",
184
+ "@modern-js/server-core": "2.1.0",
185
+ "@scripts/build": "2.1.0",
186
+ "@scripts/jest-config": "2.1.0"
186
187
  },
187
188
  "sideEffects": false,
188
189
  "modernConfig": {},
@@ -1,19 +0,0 @@
1
- import { Fragment, jsx } from "react/jsx-runtime";
2
- import { useContext, useEffect } from "react";
3
- import { useLocation } from "react-router-dom";
4
- import { RuntimeReactContext } from "../../../core";
5
- import { handleLoad } from "./load";
6
- function RootLayout(props) {
7
- const location = useLocation();
8
- const context = useContext(RuntimeReactContext);
9
- useEffect(() => {
10
- const { routes } = props;
11
- handleLoad(routes, location, context.routeManifest);
12
- }, [location]);
13
- return /* @__PURE__ */ jsx(Fragment, {
14
- children: props.children
15
- });
16
- }
17
- export {
18
- RootLayout
19
- };
@@ -1,82 +0,0 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
- import { matchRoutes } from "react-router-dom";
22
- class Logger {
23
- static getLogger(options) {
24
- if (this.logger) {
25
- return this.logger;
26
- }
27
- this.logger = new Logger(options);
28
- return this.logger;
29
- }
30
- constructor(options) {
31
- this.enableLogging = options.enableLogging;
32
- }
33
- log(...args) {
34
- if (this.enableLogging) {
35
- console.log(...args);
36
- }
37
- }
38
- }
39
- function handleLoad(routes, location, routeManifest) {
40
- if (!routeManifest || !routeManifest.enableFetchParallel === false) {
41
- return;
42
- }
43
- const { routeAssets } = routeManifest;
44
- Logger.getLogger({ enableLogging: routeManifest.enableLogging }).log(
45
- "handle page load"
46
- );
47
- const matches = matchClientRoutes(routes, location);
48
- matches == null ? void 0 : matches.forEach((match) => loadRouteModule(match.route, routeAssets));
49
- }
50
- function matchClientRoutes(routes, location) {
51
- const matches = matchRoutes(routes, location);
52
- return matches;
53
- }
54
- function loadRouteModule(route, routeAssets) {
55
- return __async(this, null, function* () {
56
- const routeId = route.id;
57
- if (!routeId) {
58
- return;
59
- }
60
- if (!routeAssets[routeId]) {
61
- return;
62
- }
63
- const { chunkIds } = routeAssets[routeId];
64
- if (!chunkIds) {
65
- return;
66
- }
67
- try {
68
- yield Promise.all(
69
- chunkIds.map((chunkId) => {
70
- return __webpack_chunk_load__(String(chunkId));
71
- })
72
- );
73
- } catch (error) {
74
- console.error(error);
75
- }
76
- });
77
- }
78
- export {
79
- handleLoad,
80
- loadRouteModule,
81
- matchClientRoutes
82
- };
@@ -1,42 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var root_exports = {};
19
- __export(root_exports, {
20
- RootLayout: () => RootLayout
21
- });
22
- module.exports = __toCommonJS(root_exports);
23
- var import_jsx_runtime = require("react/jsx-runtime");
24
- var import_react = require("react");
25
- var import_react_router_dom = require("react-router-dom");
26
- var import_core = require("../../../core");
27
- var import_load = require("./load");
28
- function RootLayout(props) {
29
- const location = (0, import_react_router_dom.useLocation)();
30
- const context = (0, import_react.useContext)(import_core.RuntimeReactContext);
31
- (0, import_react.useEffect)(() => {
32
- const { routes } = props;
33
- (0, import_load.handleLoad)(routes, location, context.routeManifest);
34
- }, [location]);
35
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
36
- children: props.children
37
- });
38
- }
39
- // Annotate the CommonJS export names for ESM import in node:
40
- 0 && (module.exports = {
41
- RootLayout
42
- });
@@ -1,107 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var __async = (__this, __arguments, generator) => {
19
- return new Promise((resolve, reject) => {
20
- var fulfilled = (value) => {
21
- try {
22
- step(generator.next(value));
23
- } catch (e) {
24
- reject(e);
25
- }
26
- };
27
- var rejected = (value) => {
28
- try {
29
- step(generator.throw(value));
30
- } catch (e) {
31
- reject(e);
32
- }
33
- };
34
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
35
- step((generator = generator.apply(__this, __arguments)).next());
36
- });
37
- };
38
- var load_exports = {};
39
- __export(load_exports, {
40
- handleLoad: () => handleLoad,
41
- loadRouteModule: () => loadRouteModule,
42
- matchClientRoutes: () => matchClientRoutes
43
- });
44
- module.exports = __toCommonJS(load_exports);
45
- var import_react_router_dom = require("react-router-dom");
46
- class Logger {
47
- static getLogger(options) {
48
- if (this.logger) {
49
- return this.logger;
50
- }
51
- this.logger = new Logger(options);
52
- return this.logger;
53
- }
54
- constructor(options) {
55
- this.enableLogging = options.enableLogging;
56
- }
57
- log(...args) {
58
- if (this.enableLogging) {
59
- console.log(...args);
60
- }
61
- }
62
- }
63
- function handleLoad(routes, location, routeManifest) {
64
- if (!routeManifest || !routeManifest.enableFetchParallel === false) {
65
- return;
66
- }
67
- const { routeAssets } = routeManifest;
68
- Logger.getLogger({ enableLogging: routeManifest.enableLogging }).log(
69
- "handle page load"
70
- );
71
- const matches = matchClientRoutes(routes, location);
72
- matches == null ? void 0 : matches.forEach((match) => loadRouteModule(match.route, routeAssets));
73
- }
74
- function matchClientRoutes(routes, location) {
75
- const matches = (0, import_react_router_dom.matchRoutes)(routes, location);
76
- return matches;
77
- }
78
- function loadRouteModule(route, routeAssets) {
79
- return __async(this, null, function* () {
80
- const routeId = route.id;
81
- if (!routeId) {
82
- return;
83
- }
84
- if (!routeAssets[routeId]) {
85
- return;
86
- }
87
- const { chunkIds } = routeAssets[routeId];
88
- if (!chunkIds) {
89
- return;
90
- }
91
- try {
92
- yield Promise.all(
93
- chunkIds.map((chunkId) => {
94
- return __webpack_chunk_load__(String(chunkId));
95
- })
96
- );
97
- } catch (error) {
98
- console.error(error);
99
- }
100
- });
101
- }
102
- // Annotate the CommonJS export names for ESM import in node:
103
- 0 && (module.exports = {
104
- handleLoad,
105
- loadRouteModule,
106
- matchClientRoutes
107
- });
@@ -1,19 +0,0 @@
1
- import { Fragment, jsx } from "react/jsx-runtime";
2
- import { useContext, useEffect } from "react";
3
- import { useLocation } from "react-router-dom";
4
- import { RuntimeReactContext } from "../../../core";
5
- import { handleLoad } from "./load";
6
- function RootLayout(props) {
7
- var location = useLocation();
8
- var context = useContext(RuntimeReactContext);
9
- useEffect(function() {
10
- var routes = props.routes;
11
- handleLoad(routes, location, context.routeManifest);
12
- }, [
13
- location
14
- ]);
15
- return /* @__PURE__ */ jsx(Fragment, {
16
- children: props.children
17
- });
18
- }
19
- export { RootLayout };
@@ -1,297 +0,0 @@
1
- function _arrayLikeToArray(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _arrayWithoutHoles(arr) {
7
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
8
- }
9
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
- try {
11
- var info = gen[key](arg);
12
- var value = info.value;
13
- } catch (error) {
14
- reject(error);
15
- return;
16
- }
17
- if (info.done) {
18
- resolve(value);
19
- } else {
20
- Promise.resolve(value).then(_next, _throw);
21
- }
22
- }
23
- function _asyncToGenerator(fn) {
24
- return function() {
25
- var self = this, args = arguments;
26
- return new Promise(function(resolve, reject) {
27
- var gen = fn.apply(self, args);
28
- function _next(value) {
29
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
- }
31
- function _throw(err) {
32
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
- }
34
- _next(undefined);
35
- });
36
- };
37
- }
38
- function _classCallCheck(instance, Constructor) {
39
- if (!(instance instanceof Constructor)) {
40
- throw new TypeError("Cannot call a class as a function");
41
- }
42
- }
43
- function _defineProperties(target, props) {
44
- for(var i = 0; i < props.length; i++){
45
- var descriptor = props[i];
46
- descriptor.enumerable = descriptor.enumerable || false;
47
- descriptor.configurable = true;
48
- if ("value" in descriptor) descriptor.writable = true;
49
- Object.defineProperty(target, descriptor.key, descriptor);
50
- }
51
- }
52
- function _createClass(Constructor, protoProps, staticProps) {
53
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
54
- if (staticProps) _defineProperties(Constructor, staticProps);
55
- return Constructor;
56
- }
57
- function _defineProperty(obj, key, value) {
58
- if (key in obj) {
59
- Object.defineProperty(obj, key, {
60
- value: value,
61
- enumerable: true,
62
- configurable: true,
63
- writable: true
64
- });
65
- } else {
66
- obj[key] = value;
67
- }
68
- return obj;
69
- }
70
- function _iterableToArray(iter) {
71
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
72
- }
73
- function _nonIterableSpread() {
74
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
75
- }
76
- function _toConsumableArray(arr) {
77
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
78
- }
79
- function _unsupportedIterableToArray(o, minLen) {
80
- if (!o) return;
81
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
82
- var n = Object.prototype.toString.call(o).slice(8, -1);
83
- if (n === "Object" && o.constructor) n = o.constructor.name;
84
- if (n === "Map" || n === "Set") return Array.from(n);
85
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
86
- }
87
- var __generator = this && this.__generator || function(thisArg, body) {
88
- var f, y, t, g, _ = {
89
- label: 0,
90
- sent: function() {
91
- if (t[0] & 1) throw t[1];
92
- return t[1];
93
- },
94
- trys: [],
95
- ops: []
96
- };
97
- return g = {
98
- next: verb(0),
99
- "throw": verb(1),
100
- "return": verb(2)
101
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
102
- return this;
103
- }), g;
104
- function verb(n) {
105
- return function(v) {
106
- return step([
107
- n,
108
- v
109
- ]);
110
- };
111
- }
112
- function step(op) {
113
- if (f) throw new TypeError("Generator is already executing.");
114
- while(_)try {
115
- 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;
116
- if (y = 0, t) op = [
117
- op[0] & 2,
118
- t.value
119
- ];
120
- switch(op[0]){
121
- case 0:
122
- case 1:
123
- t = op;
124
- break;
125
- case 4:
126
- _.label++;
127
- return {
128
- value: op[1],
129
- done: false
130
- };
131
- case 5:
132
- _.label++;
133
- y = op[1];
134
- op = [
135
- 0
136
- ];
137
- continue;
138
- case 7:
139
- op = _.ops.pop();
140
- _.trys.pop();
141
- continue;
142
- default:
143
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
144
- _ = 0;
145
- continue;
146
- }
147
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
148
- _.label = op[1];
149
- break;
150
- }
151
- if (op[0] === 6 && _.label < t[1]) {
152
- _.label = t[1];
153
- t = op;
154
- break;
155
- }
156
- if (t && _.label < t[2]) {
157
- _.label = t[2];
158
- _.ops.push(op);
159
- break;
160
- }
161
- if (t[2]) _.ops.pop();
162
- _.trys.pop();
163
- continue;
164
- }
165
- op = body.call(thisArg, _);
166
- } catch (e) {
167
- op = [
168
- 6,
169
- e
170
- ];
171
- y = 0;
172
- } finally{
173
- f = t = 0;
174
- }
175
- if (op[0] & 5) throw op[1];
176
- return {
177
- value: op[0] ? op[1] : void 0,
178
- done: true
179
- };
180
- }
181
- };
182
- import { matchRoutes } from "react-router-dom";
183
- var Logger = /*#__PURE__*/ function() {
184
- "use strict";
185
- function Logger(options) {
186
- _classCallCheck(this, Logger);
187
- _defineProperty(this, "enableLogging", void 0);
188
- this.enableLogging = options.enableLogging;
189
- }
190
- _createClass(Logger, [
191
- {
192
- key: "log",
193
- value: function log() {
194
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
195
- args[_key] = arguments[_key];
196
- }
197
- if (this.enableLogging) {
198
- var _console;
199
- (_console = console).log.apply(_console, _toConsumableArray(args));
200
- }
201
- }
202
- }
203
- ], [
204
- {
205
- key: "getLogger",
206
- value: function getLogger(options) {
207
- if (this.logger) {
208
- return this.logger;
209
- }
210
- this.logger = new Logger(options);
211
- return this.logger;
212
- }
213
- }
214
- ]);
215
- return Logger;
216
- }();
217
- _defineProperty(Logger, "logger", void 0);
218
- function handleLoad(routes, location, routeManifest) {
219
- if (!routeManifest || !routeManifest.enableFetchParallel === false) {
220
- return;
221
- }
222
- var routeAssets = routeManifest.routeAssets;
223
- Logger.getLogger({
224
- enableLogging: routeManifest.enableLogging
225
- }).log("handle page load");
226
- var matches = matchClientRoutes(routes, location);
227
- matches === null || matches === void 0 ? void 0 : matches.forEach(function(match) {
228
- return loadRouteModule(match.route, routeAssets);
229
- });
230
- }
231
- function matchClientRoutes(routes, location) {
232
- var matches = matchRoutes(routes, location);
233
- return matches;
234
- }
235
- function loadRouteModule(route, routeAssets) {
236
- return _loadRouteModule.apply(this, arguments);
237
- }
238
- function _loadRouteModule() {
239
- _loadRouteModule = _asyncToGenerator(function(route, routeAssets) {
240
- var routeId, chunkIds, error;
241
- return __generator(this, function(_state) {
242
- switch(_state.label){
243
- case 0:
244
- routeId = route.id;
245
- if (!routeId) {
246
- return [
247
- 2
248
- ];
249
- }
250
- if (!routeAssets[routeId]) {
251
- return [
252
- 2
253
- ];
254
- }
255
- chunkIds = routeAssets[routeId].chunkIds;
256
- if (!chunkIds) {
257
- return [
258
- 2
259
- ];
260
- }
261
- _state.label = 1;
262
- case 1:
263
- _state.trys.push([
264
- 1,
265
- 3,
266
- ,
267
- 4
268
- ]);
269
- return [
270
- 4,
271
- Promise.all(chunkIds.map(function(chunkId) {
272
- return __webpack_chunk_load__(String(chunkId));
273
- }))
274
- ];
275
- case 2:
276
- _state.sent();
277
- return [
278
- 3,
279
- 4
280
- ];
281
- case 3:
282
- error = _state.sent();
283
- console.error(error);
284
- return [
285
- 3,
286
- 4
287
- ];
288
- case 4:
289
- return [
290
- 2
291
- ];
292
- }
293
- });
294
- });
295
- return _loadRouteModule.apply(this, arguments);
296
- }
297
- export { handleLoad, loadRouteModule, matchClientRoutes };
@@ -1,8 +0,0 @@
1
- import React from 'react';
2
- import type { NestedRoute } from '@modern-js/types';
3
- interface IProps {
4
- children: React.ReactNode;
5
- routes: NestedRoute[];
6
- }
7
- export declare function RootLayout(props: IProps): JSX.Element;
8
- export {};
@@ -1,22 +0,0 @@
1
- import { Location, Params } from 'react-router-dom';
2
- import type { NestedRoute } from '@modern-js/types';
3
- interface RouteAssets {
4
- [routeId: string]: {
5
- chunkIds?: (string | number)[];
6
- assets?: string[];
7
- };
8
- }
9
- interface RouteManifest {
10
- routeAssets: RouteAssets;
11
- enableFetchParallel?: boolean;
12
- enableLogging?: boolean;
13
- }
14
- export interface RouteMatch<Route> {
15
- params: Params;
16
- pathname: string;
17
- route: Route;
18
- }
19
- export declare function handleLoad(routes: NestedRoute[], location: Location, routeManifest: RouteManifest): void;
20
- export declare function matchClientRoutes(routes: NestedRoute[], location: Location): RouteMatch<NestedRoute>[];
21
- export declare function loadRouteModule(route: NestedRoute, routeAssets: RouteAssets): Promise<string[] | void>;
22
- export {};