@modern-js/runtime 2.0.2 → 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,21 @@
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
+
3
19
  ## 2.0.2
4
20
 
5
21
  ### Patch Changes
@@ -34,7 +34,8 @@ import { Suspense } from "react";
34
34
  import { Route } from "react-router-dom";
35
35
  import { DefaultNotFound } from "./DefaultNotFound";
36
36
  const renderNestedRoute = (nestedRoute, parent) => {
37
- const { children, index, id, component: Component } = nestedRoute;
37
+ const { children, index, id, component, isRoot } = nestedRoute;
38
+ const Component = component;
38
39
  const routeProps = {
39
40
  caseSensitive: nestedRoute.caseSensitive,
40
41
  path: nestedRoute.path,
@@ -56,16 +57,22 @@ const renderNestedRoute = (nestedRoute, parent) => {
56
57
  if (Component) {
57
58
  if (parent == null ? void 0 : parent.loading) {
58
59
  const Loading = parent.loading;
59
- element = /* @__PURE__ */ jsx(Suspense, {
60
- fallback: /* @__PURE__ */ jsx(Loading, {}),
61
- children: /* @__PURE__ */ jsx(Component, {})
62
- });
63
- } 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 {
64
73
  element = /* @__PURE__ */ jsx(Suspense, {
65
74
  children: /* @__PURE__ */ jsx(Component, {})
66
75
  });
67
- } else {
68
- element = /* @__PURE__ */ jsx(Component, {});
69
76
  }
70
77
  } else {
71
78
  nestedRoute.loading = parent == null ? void 0 : parent.loading;
@@ -176,6 +183,9 @@ function createLoader(route) {
176
183
  };
177
184
  }
178
185
  }
186
+ function isLoadableComponent(component) {
187
+ return component && component.displayName === "Loadable" && component.preload && typeof component.preload === "function";
188
+ }
179
189
  export {
180
190
  getLocation,
181
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
  };
@@ -58,7 +58,8 @@ var import_react = require("react");
58
58
  var import_react_router_dom = require("react-router-dom");
59
59
  var import_DefaultNotFound = require("./DefaultNotFound");
60
60
  const renderNestedRoute = (nestedRoute, parent) => {
61
- const { children, index, id, component: Component } = nestedRoute;
61
+ const { children, index, id, component, isRoot } = nestedRoute;
62
+ const Component = component;
62
63
  const routeProps = {
63
64
  caseSensitive: nestedRoute.caseSensitive,
64
65
  path: nestedRoute.path,
@@ -80,16 +81,22 @@ const renderNestedRoute = (nestedRoute, parent) => {
80
81
  if (Component) {
81
82
  if (parent == null ? void 0 : parent.loading) {
82
83
  const Loading = parent.loading;
83
- element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, {
84
- fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Loading, {}),
85
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {})
86
- });
87
- } 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 {
88
97
  element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, {
89
98
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {})
90
99
  });
91
- } else {
92
- element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {});
93
100
  }
94
101
  } else {
95
102
  nestedRoute.loading = parent == null ? void 0 : parent.loading;
@@ -200,6 +207,9 @@ function createLoader(route) {
200
207
  };
201
208
  }
202
209
  }
210
+ function isLoadableComponent(component) {
211
+ return component && component.displayName === "Loadable" && component.preload && typeof component.preload === "function";
212
+ }
203
213
  // Annotate the CommonJS export names for ESM import in node:
204
214
  0 && (module.exports = {
205
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
  };
@@ -82,7 +82,8 @@ import { Suspense } from "react";
82
82
  import { Route } from "react-router-dom";
83
83
  import { DefaultNotFound } from "./DefaultNotFound";
84
84
  var renderNestedRoute = function(nestedRoute, parent) {
85
- 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;
86
87
  var routeProps = {
87
88
  caseSensitive: nestedRoute.caseSensitive,
88
89
  path: nestedRoute.path,
@@ -104,16 +105,22 @@ var renderNestedRoute = function(nestedRoute, parent) {
104
105
  if (Component) {
105
106
  if (parent === null || parent === void 0 ? void 0 : parent.loading) {
106
107
  var Loading = parent.loading;
107
- element = /* @__PURE__ */ jsx(Suspense, {
108
- fallback: /* @__PURE__ */ jsx(Loading, {}),
109
- children: /* @__PURE__ */ jsx(Component, {})
110
- });
111
- } 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 {
112
121
  element = /* @__PURE__ */ jsx(Suspense, {
113
122
  children: /* @__PURE__ */ jsx(Component, {})
114
123
  });
115
- } else {
116
- element = /* @__PURE__ */ jsx(Component, {});
117
124
  }
118
125
  } else {
119
126
  nestedRoute.loading = parent === null || parent === void 0 ? void 0 : parent.loading;
@@ -246,4 +253,7 @@ function createLoader(route) {
246
253
  };
247
254
  }
248
255
  }
256
+ function isLoadableComponent(component) {
257
+ return component && component.displayName === "Loadable" && component.preload && typeof component.preload === "function";
258
+ }
249
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.2",
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/types": "2.0.2",
159
- "@modern-js/utils": "2.0.2",
160
- "@modern-js/plugin": "2.0.2"
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/core": "2.0.2",
182
- "@modern-js/app-tools": "2.0.2",
183
- "@modern-js/server-core": "2.0.2",
184
- "@scripts/build": "2.0.2",
185
- "@scripts/jest-config": "2.0.2"
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": {},