@modern-js/runtime 2.0.2 → 2.1.1-alpha.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,23 @@ const renderNestedRoute = (nestedRoute, parent) => {
56
57
  if (Component) {
57
58
  if (parent == null ? void 0 : parent.loading) {
58
59
  const Loading = parent.loading;
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 {
59
73
  element = /* @__PURE__ */ jsx(Suspense, {
60
- fallback: /* @__PURE__ */ jsx(Loading, {}),
61
- children: /* @__PURE__ */ jsx(Component, {})
62
- });
63
- } else if (!(parent == null ? void 0 : parent.index)) {
64
- element = /* @__PURE__ */ jsx(Suspense, {
74
+ fallback: null,
65
75
  children: /* @__PURE__ */ jsx(Component, {})
66
76
  });
67
- } else {
68
- element = /* @__PURE__ */ jsx(Component, {});
69
77
  }
70
78
  } else {
71
79
  nestedRoute.loading = parent == null ? void 0 : parent.loading;
@@ -176,6 +184,9 @@ function createLoader(route) {
176
184
  };
177
185
  }
178
186
  }
187
+ function isLoadableComponent(component) {
188
+ return component && component.displayName === "Loadable" && component.preload && typeof component.preload === "function";
189
+ }
179
190
  export {
180
191
  getLocation,
181
192
  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,23 @@ const renderNestedRoute = (nestedRoute, parent) => {
80
81
  if (Component) {
81
82
  if (parent == null ? void 0 : parent.loading) {
82
83
  const Loading = parent.loading;
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 {
83
97
  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)) {
88
- element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, {
98
+ fallback: null,
89
99
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {})
90
100
  });
91
- } else {
92
- element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {});
93
101
  }
94
102
  } else {
95
103
  nestedRoute.loading = parent == null ? void 0 : parent.loading;
@@ -200,6 +208,9 @@ function createLoader(route) {
200
208
  };
201
209
  }
202
210
  }
211
+ function isLoadableComponent(component) {
212
+ return component && component.displayName === "Loadable" && component.preload && typeof component.preload === "function";
213
+ }
203
214
  // Annotate the CommonJS export names for ESM import in node:
204
215
  0 && (module.exports = {
205
216
  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,23 @@ 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;
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 {
107
121
  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)) {
112
- element = /* @__PURE__ */ jsx(Suspense, {
122
+ fallback: null,
113
123
  children: /* @__PURE__ */ jsx(Component, {})
114
124
  });
115
- } else {
116
- element = /* @__PURE__ */ jsx(Component, {});
117
125
  }
118
126
  } else {
119
127
  nestedRoute.loading = parent === null || parent === void 0 ? void 0 : parent.loading;
@@ -246,4 +254,7 @@ function createLoader(route) {
246
254
  };
247
255
  }
248
256
  }
257
+ function isLoadableComponent(component) {
258
+ return component && component.displayName === "Loadable" && component.preload && typeof component.preload === "function";
259
+ }
249
260
  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.1-alpha.0",
15
15
  "engines": {
16
16
  "node": ">=14.17.6"
17
17
  },
@@ -78,9 +78,9 @@
78
78
  "default": "./dist/js/treeshaking/router/index.js"
79
79
  },
80
80
  "./router/server": {
81
- "jsnext:source": "./src/router/server.ts",
82
- "node": "./dist/js/node/router/server.js",
83
- "default": "./dist/js/treeshaking/router/server.js"
81
+ "jsnext:source": "./src/router/runtime/server.ts",
82
+ "node": "./dist/js/node/router/runtime/server.js",
83
+ "default": "./dist/js/treeshaking/router/runtime/server.js"
84
84
  }
85
85
  },
86
86
  "typesVersions": {
@@ -140,6 +140,9 @@
140
140
  "@modern-js-reduck/plugin-immutable": "^1.1.4",
141
141
  "@modern-js-reduck/react": "^1.1.4",
142
142
  "@modern-js-reduck/store": "^1.1.4",
143
+ "@modern-js/plugin": "2.1.0",
144
+ "@modern-js/types": "2.1.0",
145
+ "@modern-js/utils": "2.1.0",
143
146
  "@remix-run/node": "^1.9.0",
144
147
  "@remix-run/router": "^1.2.0",
145
148
  "@types/loadable__component": "^5.13.4",
@@ -155,16 +158,19 @@
155
158
  "redux-logger": "^3.0.6",
156
159
  "serialize-javascript": "^6.0.0",
157
160
  "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"
161
+ "esbuild": "0.15.7"
161
162
  },
162
163
  "peerDependencies": {
163
164
  "react": ">=17",
164
165
  "react-dom": ">=17"
165
166
  },
166
167
  "devDependencies": {
168
+ "@modern-js/app-tools": "2.1.0",
169
+ "@modern-js/core": "2.1.0",
170
+ "@modern-js/server-core": "2.1.0",
167
171
  "@remix-run/web-fetch": "^4.1.3",
172
+ "@scripts/build": "2.1.0",
173
+ "@scripts/jest-config": "2.1.0",
168
174
  "@testing-library/react": "^13.4.0",
169
175
  "@testing-library/react-hooks": "^8.0.1",
170
176
  "@types/invariant": "^2.2.30",
@@ -177,12 +183,7 @@
177
183
  "react": "^18",
178
184
  "react-dom": "^18",
179
185
  "ts-jest": "^27.0.4",
180
- "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"
186
+ "typescript": "^4"
186
187
  },
187
188
  "sideEffects": false,
188
189
  "modernConfig": {},