@modern-js/runtime 2.10.0 → 2.12.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 +41 -0
- package/dist/cjs/core/compatible.js +7 -3
- package/dist/cjs/router/runtime/DeferredDataScripts.node.js +1 -1
- package/dist/cjs/router/runtime/PrefetchLink.js +206 -0
- package/dist/cjs/router/runtime/index.js +6 -1
- package/dist/cjs/router/runtime/plugin.js +13 -2
- package/dist/cjs/router/runtime/plugin.node.js +7 -2
- package/dist/cjs/router/runtime/utils.js +19 -9
- package/dist/cjs/ssr/cli/index.js +15 -9
- package/dist/cjs/ssr/index.js +3 -0
- package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.after.js +1 -1
- package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +2 -2
- package/dist/cjs/ssr/serverRender/renderToString/entry.js +1 -1
- package/dist/esm/core/compatible.js +3 -2
- package/dist/esm/router/runtime/DeferredDataScripts.node.js +1 -1
- package/dist/esm/router/runtime/PrefetchLink.js +447 -0
- package/dist/esm/router/runtime/index.js +3 -2
- package/dist/esm/router/runtime/plugin.js +11 -2
- package/dist/esm/router/runtime/plugin.node.js +5 -2
- package/dist/esm/router/runtime/utils.js +12 -9
- package/dist/esm/ssr/cli/index.js +12 -7
- package/dist/esm/ssr/index.js +3 -0
- package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.after.js +1 -1
- package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +2 -2
- package/dist/esm/ssr/serverRender/renderToString/entry.js +1 -1
- package/dist/esm-node/core/compatible.js +7 -3
- package/dist/esm-node/router/runtime/DeferredDataScripts.node.js +1 -1
- package/dist/esm-node/router/runtime/PrefetchLink.js +178 -0
- package/dist/esm-node/router/runtime/index.js +4 -1
- package/dist/esm-node/router/runtime/plugin.js +13 -2
- package/dist/esm-node/router/runtime/plugin.node.js +7 -2
- package/dist/esm-node/router/runtime/utils.js +19 -9
- package/dist/esm-node/ssr/cli/index.js +15 -9
- package/dist/esm-node/ssr/index.js +3 -0
- package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.after.js +1 -1
- package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +2 -2
- package/dist/esm-node/ssr/serverRender/renderToString/entry.js +1 -1
- package/dist/types/router/runtime/PrefetchLink.d.ts +30 -0
- package/dist/types/router/runtime/index.d.ts +3 -1
- package/dist/types/router/runtime/types.d.ts +10 -1
- package/dist/types/router/runtime/utils.d.ts +13 -3
- package/dist/types/runtimeContext.d.ts +3 -1
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# @modern-js/runtime
|
|
2
2
|
|
|
3
|
+
## 2.12.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0b05ec3: fix: the SSR plugin will product some effects, disable the ssr plugin when user doesn't use ssr
|
|
8
|
+
fix: SSR 插件将会尝试一些副作用,如果用户没有使用它时禁用这个插件。
|
|
9
|
+
- 1aa0cb7: fix: beforeCreateRouter should be false after render router
|
|
10
|
+
fix: 在渲染 router 后,beforeCreateRouter 应该为 false
|
|
11
|
+
- Updated dependencies [c2ca6c8]
|
|
12
|
+
- Updated dependencies [6d86e34]
|
|
13
|
+
- @modern-js/utils@2.12.0
|
|
14
|
+
- @modern-js/plugin@2.12.0
|
|
15
|
+
- @modern-js/types@2.12.0
|
|
16
|
+
|
|
17
|
+
## 2.11.0
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 5d624fd: feat: assets and data prefetching is supported
|
|
22
|
+
feat: 支持资源和数据预加载
|
|
23
|
+
- e2466a1: fix: remove nestedRoutes file from @modern-js/utils
|
|
24
|
+
fix: 将 nestedRoutes 从 @modern-js/utils 中移除
|
|
25
|
+
- 02bb383: fix: fix lost props when using nested route in micro-front-end mode
|
|
26
|
+
修复嵌套路由在微前端场景下主子应用传递 props 丢失问题
|
|
27
|
+
- 381a3b9: feat(utils): move universal utils to the universal folder
|
|
28
|
+
|
|
29
|
+
feat(utils): 将运行时使用的 utils 移动到 universal 目录
|
|
30
|
+
|
|
31
|
+
- Updated dependencies [cfb058f]
|
|
32
|
+
- Updated dependencies [0bd018b]
|
|
33
|
+
- Updated dependencies [5d624fd]
|
|
34
|
+
- Updated dependencies [e2466a1]
|
|
35
|
+
- Updated dependencies [02bb383]
|
|
36
|
+
- Updated dependencies [381a3b9]
|
|
37
|
+
- Updated dependencies [7a60f10]
|
|
38
|
+
- Updated dependencies [274b2e5]
|
|
39
|
+
- Updated dependencies [b9e1c54]
|
|
40
|
+
- @modern-js/utils@2.11.0
|
|
41
|
+
- @modern-js/plugin@2.11.0
|
|
42
|
+
- @modern-js/types@2.11.0
|
|
43
|
+
|
|
3
44
|
## 2.10.0
|
|
4
45
|
|
|
5
46
|
### Patch Changes
|
|
@@ -35,7 +35,7 @@ module.exports = __toCommonJS(compatible_exports);
|
|
|
35
35
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
36
|
var import_react = __toESM(require("react"));
|
|
37
37
|
var import_hoist_non_react_statics = __toESM(require("hoist-non-react-statics"));
|
|
38
|
-
var import_constants = require("@modern-js/utils/constants");
|
|
38
|
+
var import_constants = require("@modern-js/utils/universal/constants");
|
|
39
39
|
var import_runtimeContext = require("../runtimeContext");
|
|
40
40
|
var import_plugin = require("./plugin");
|
|
41
41
|
var import_loaderManager = require("./loader/loaderManager");
|
|
@@ -56,10 +56,14 @@ const createApp = ({ plugins }) => {
|
|
|
56
56
|
return (App) => {
|
|
57
57
|
const runner = appRuntime.init();
|
|
58
58
|
const WrapperComponent = (props) => {
|
|
59
|
+
var _a;
|
|
59
60
|
const element = import_react.default.createElement(
|
|
60
61
|
App || import_react.default.Fragment,
|
|
61
|
-
{ ...props },
|
|
62
|
-
props.children
|
|
62
|
+
App ? { ...props } : null,
|
|
63
|
+
App ? props.children : import_react.default.cloneElement(props.children, {
|
|
64
|
+
...(_a = props.children) == null ? void 0 : _a.props,
|
|
65
|
+
...props
|
|
66
|
+
})
|
|
63
67
|
);
|
|
64
68
|
const context = (0, import_react.useContext)(import_runtimeContext.RuntimeReactContext);
|
|
65
69
|
return runner.provide(
|
|
@@ -23,7 +23,7 @@ module.exports = __toCommonJS(DeferredDataScripts_node_exports);
|
|
|
23
23
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
24
24
|
var import_react = require("react");
|
|
25
25
|
var import_react_router_dom = require("react-router-dom");
|
|
26
|
-
var import_serialize = require("@modern-js/utils/serialize");
|
|
26
|
+
var import_serialize = require("@modern-js/utils/universal/serialize");
|
|
27
27
|
var import_common = require("../../common");
|
|
28
28
|
var import_utils = require("./utils");
|
|
29
29
|
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}}))};`;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var PrefetchLink_exports = {};
|
|
29
|
+
__export(PrefetchLink_exports, {
|
|
30
|
+
PrefetchLink: () => Link,
|
|
31
|
+
PrefetchNavLink: () => NavLink,
|
|
32
|
+
composeEventHandlers: () => composeEventHandlers
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(PrefetchLink_exports);
|
|
35
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
|
+
var import_react = __toESM(require("react"));
|
|
37
|
+
var import_react_router_dom = require("react-router-dom");
|
|
38
|
+
var import_core = require("../../core");
|
|
39
|
+
function composeEventHandlers(theirHandler, ourHandler) {
|
|
40
|
+
return (event) => {
|
|
41
|
+
theirHandler == null ? void 0 : theirHandler(event);
|
|
42
|
+
if (!event.defaultPrevented) {
|
|
43
|
+
ourHandler(event);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
|
|
48
|
+
function usePrefetchBehavior(prefetch, theirElementProps) {
|
|
49
|
+
const [maybePrefetch, setMaybePrefetch] = import_react.default.useState(false);
|
|
50
|
+
const [shouldPrefetch, setShouldPrefetch] = import_react.default.useState(false);
|
|
51
|
+
const { onFocus, onBlur, onMouseEnter, onMouseLeave, onTouchStart } = theirElementProps;
|
|
52
|
+
import_react.default.useEffect(() => {
|
|
53
|
+
if (prefetch === "render") {
|
|
54
|
+
setShouldPrefetch(true);
|
|
55
|
+
}
|
|
56
|
+
}, [prefetch]);
|
|
57
|
+
const setIntent = () => {
|
|
58
|
+
if (prefetch === "intent") {
|
|
59
|
+
setMaybePrefetch(true);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const cancelIntent = () => {
|
|
63
|
+
if (prefetch === "intent") {
|
|
64
|
+
setMaybePrefetch(false);
|
|
65
|
+
setShouldPrefetch(false);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
import_react.default.useEffect(() => {
|
|
69
|
+
if (maybePrefetch) {
|
|
70
|
+
const id = setTimeout(() => {
|
|
71
|
+
setShouldPrefetch(true);
|
|
72
|
+
}, 100);
|
|
73
|
+
return () => {
|
|
74
|
+
clearTimeout(id);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}, [maybePrefetch]);
|
|
78
|
+
return [
|
|
79
|
+
shouldPrefetch,
|
|
80
|
+
{
|
|
81
|
+
onFocus: composeEventHandlers(onFocus, setIntent),
|
|
82
|
+
onBlur: composeEventHandlers(onBlur, cancelIntent),
|
|
83
|
+
onMouseEnter: composeEventHandlers(onMouseEnter, setIntent),
|
|
84
|
+
onMouseLeave: composeEventHandlers(onMouseLeave, cancelIntent),
|
|
85
|
+
onTouchStart: composeEventHandlers(onTouchStart, setIntent)
|
|
86
|
+
}
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
async function loadRouteModule(route, routeAssets) {
|
|
90
|
+
const routeId = route.id;
|
|
91
|
+
if (!routeId) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (!routeAssets[routeId]) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const { chunkIds } = routeAssets[routeId];
|
|
98
|
+
if (!chunkIds) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
await Promise.all(
|
|
103
|
+
chunkIds.map((chunkId) => {
|
|
104
|
+
return __webpack_chunk_load__ == null ? void 0 : __webpack_chunk_load__(String(chunkId));
|
|
105
|
+
})
|
|
106
|
+
);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error(error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const getRequestUrl = (pathname, routeId) => {
|
|
112
|
+
const LOADER_ID_PARAM = "__loader";
|
|
113
|
+
const DIRECT_PARAM = "__ssrDirect";
|
|
114
|
+
const { protocol, host } = window.location;
|
|
115
|
+
const url = new URL(pathname, `${protocol}//${host}`);
|
|
116
|
+
url.searchParams.append(LOADER_ID_PARAM, routeId);
|
|
117
|
+
url.searchParams.append(DIRECT_PARAM, "true");
|
|
118
|
+
return url;
|
|
119
|
+
};
|
|
120
|
+
const createDataHref = (href) => {
|
|
121
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("link", { rel: "prefetch", as: "fetch", href }, href);
|
|
122
|
+
};
|
|
123
|
+
const getDataHref = (route, pathname, basename) => {
|
|
124
|
+
const { id } = route;
|
|
125
|
+
const path = basename === "/" ? pathname : `${basename}${pathname}`;
|
|
126
|
+
const url = getRequestUrl(path, id);
|
|
127
|
+
return createDataHref(url.toString());
|
|
128
|
+
};
|
|
129
|
+
const PrefetchPageLinks = ({ pathname }) => {
|
|
130
|
+
const context = (0, import_react.useContext)(import_core.RuntimeReactContext);
|
|
131
|
+
const { routeManifest, routes } = context;
|
|
132
|
+
const { routeAssets } = routeManifest;
|
|
133
|
+
const matches = Array.isArray(routes) ? (0, import_react_router_dom.matchRoutes)(routes, pathname) : [];
|
|
134
|
+
if (Array.isArray(matches)) {
|
|
135
|
+
matches == null ? void 0 : matches.forEach((match) => loadRouteModule(match.route, routeAssets));
|
|
136
|
+
}
|
|
137
|
+
if (!window._SSR_DATA) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
141
|
+
PrefetchDataLinks,
|
|
142
|
+
{
|
|
143
|
+
matches,
|
|
144
|
+
pathname,
|
|
145
|
+
routeManifest
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
const PrefetchDataLinks = ({ matches, pathname, routeManifest }) => {
|
|
150
|
+
const currentMatches = (0, import_react_router_dom.useMatches)();
|
|
151
|
+
const basename = (0, import_react_router_dom.useHref)("/");
|
|
152
|
+
const dataHrefs = (0, import_react.useMemo)(() => {
|
|
153
|
+
return matches == null ? void 0 : matches.filter((match, index) => {
|
|
154
|
+
if (!match.route.loader || typeof match.route.loader !== "function" || match.route.loader.length === 0) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
const currentMatch = currentMatches[index];
|
|
158
|
+
if (!currentMatch || currentMatch.id !== match.route.id) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
if (currentMatch.pathname !== match.pathname) {
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
if (currentMatch.pathname.endsWith("*") && currentMatch.params["*"] !== match.params["*"]) {
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
}).map((match) => getDataHref(match.route, pathname, basename));
|
|
169
|
+
}, [matches, pathname, routeManifest]);
|
|
170
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: dataHrefs });
|
|
171
|
+
};
|
|
172
|
+
const createPrefetchLink = (Link2) => {
|
|
173
|
+
return import_react.default.forwardRef(
|
|
174
|
+
({ to, prefetch = "none", ...props }, forwardedRef) => {
|
|
175
|
+
const isAbsolute = typeof to === "string" && ABSOLUTE_URL_REGEX.test(to);
|
|
176
|
+
const [shouldPrefetch, prefetchHandlers] = usePrefetchBehavior(
|
|
177
|
+
prefetch,
|
|
178
|
+
props
|
|
179
|
+
);
|
|
180
|
+
const resolvedPath = (0, import_react_router_dom.useResolvedPath)(to);
|
|
181
|
+
const { pathname } = resolvedPath;
|
|
182
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
183
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
184
|
+
Link2,
|
|
185
|
+
{
|
|
186
|
+
ref: forwardedRef,
|
|
187
|
+
to,
|
|
188
|
+
...props,
|
|
189
|
+
...prefetchHandlers
|
|
190
|
+
}
|
|
191
|
+
),
|
|
192
|
+
shouldPrefetch && __webpack_chunk_load__ && !isAbsolute ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PrefetchPageLinks, { pathname }) : null
|
|
193
|
+
] });
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
};
|
|
197
|
+
const Link = createPrefetchLink(import_react_router_dom.Link);
|
|
198
|
+
Link.displayName = "Link";
|
|
199
|
+
const NavLink = createPrefetchLink(import_react_router_dom.NavLink);
|
|
200
|
+
NavLink.displayName = "NavLink";
|
|
201
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
202
|
+
0 && (module.exports = {
|
|
203
|
+
PrefetchLink,
|
|
204
|
+
PrefetchNavLink,
|
|
205
|
+
composeEventHandlers
|
|
206
|
+
});
|
|
@@ -27,6 +27,8 @@ __export(runtime_exports, {
|
|
|
27
27
|
NavLink: () => import_react_router_dom.NavLink,
|
|
28
28
|
Navigate: () => import_react_router_dom.Navigate,
|
|
29
29
|
Outlet: () => import_react_router_dom.Outlet,
|
|
30
|
+
PrefetchLink: () => import_PrefetchLink.PrefetchLink,
|
|
31
|
+
PrefetchNavLink: () => import_PrefetchLink.PrefetchNavLink,
|
|
30
32
|
Route: () => import_react_router_dom.Route,
|
|
31
33
|
Router: () => import_react_router_dom.Router,
|
|
32
34
|
RouterProvider: () => import_react_router_dom.RouterProvider,
|
|
@@ -81,8 +83,9 @@ module.exports = __toCommonJS(runtime_exports);
|
|
|
81
83
|
var import_plugin = require("./plugin");
|
|
82
84
|
var import_plugin2 = require("./plugin");
|
|
83
85
|
__reExport(runtime_exports, require("./withRouter"), module.exports);
|
|
86
|
+
var import_PrefetchLink = require("./PrefetchLink");
|
|
84
87
|
var import_react_router_dom = require("react-router-dom");
|
|
85
|
-
var import_remix_router = require("@modern-js/utils/remix-router");
|
|
88
|
+
var import_remix_router = require("@modern-js/utils/universal/remix-router");
|
|
86
89
|
var runtime_default = import_plugin.routerPlugin;
|
|
87
90
|
// Annotate the CommonJS export names for ESM import in node:
|
|
88
91
|
0 && (module.exports = {
|
|
@@ -95,6 +98,8 @@ var runtime_default = import_plugin.routerPlugin;
|
|
|
95
98
|
NavLink,
|
|
96
99
|
Navigate,
|
|
97
100
|
Outlet,
|
|
101
|
+
PrefetchLink,
|
|
102
|
+
PrefetchNavLink,
|
|
98
103
|
Route,
|
|
99
104
|
Router,
|
|
100
105
|
RouterProvider,
|
|
@@ -60,6 +60,7 @@ const routerPlugin = ({
|
|
|
60
60
|
createRoutes
|
|
61
61
|
}) => {
|
|
62
62
|
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
|
63
|
+
let routes = [];
|
|
63
64
|
finalRouteConfig = routesConfig;
|
|
64
65
|
return {
|
|
65
66
|
name: "@modern-js/plugin-router",
|
|
@@ -70,6 +71,11 @@ const routerPlugin = ({
|
|
|
70
71
|
useMatches: import_react_router_dom.useMatches,
|
|
71
72
|
useLocation: import_react_router_dom.useLocation
|
|
72
73
|
};
|
|
74
|
+
Object.defineProperty(context, "routes", {
|
|
75
|
+
get() {
|
|
76
|
+
return routes;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
73
79
|
return next({ context });
|
|
74
80
|
},
|
|
75
81
|
hoc: ({ App }, next) => {
|
|
@@ -79,8 +85,13 @@ const routerPlugin = ({
|
|
|
79
85
|
const getRouteApp = () => {
|
|
80
86
|
return (props) => {
|
|
81
87
|
var _a;
|
|
82
|
-
beforeCreateRouter =
|
|
83
|
-
|
|
88
|
+
beforeCreateRouter = false;
|
|
89
|
+
routes = createRoutes ? createRoutes() : (0, import_react_router_dom.createRoutesFromElements)(
|
|
90
|
+
(0, import_utils.renderRoutes)({
|
|
91
|
+
routesConfig: finalRouteConfig,
|
|
92
|
+
props
|
|
93
|
+
})
|
|
94
|
+
);
|
|
84
95
|
const baseUrl = ((_a = window._SERVER_DATA) == null ? void 0 : _a.router.baseUrl) || select(location.pathname);
|
|
85
96
|
const _basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, basename) : baseUrl;
|
|
86
97
|
let hydrationData = window._ROUTER_DATA;
|
|
@@ -34,7 +34,7 @@ __export(plugin_node_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(plugin_node_exports);
|
|
35
35
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
36
|
var import_react = require("react");
|
|
37
|
-
var import_remix_router = require("@modern-js/utils/remix-router");
|
|
37
|
+
var import_remix_router = require("@modern-js/utils/universal/remix-router");
|
|
38
38
|
var import_server = require("react-router-dom/server");
|
|
39
39
|
var import_hoist_non_react_statics = __toESM(require("hoist-non-react-statics"));
|
|
40
40
|
var import_react_router_dom = require("react-router-dom");
|
|
@@ -84,7 +84,12 @@ const routerPlugin = ({
|
|
|
84
84
|
const { request, mode: ssrMode } = context.ssrContext;
|
|
85
85
|
const baseUrl = request.baseUrl;
|
|
86
86
|
const _basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, basename) : baseUrl;
|
|
87
|
-
const routes = createRoutes ? createRoutes() : (0, import_react_router_dom.createRoutesFromElements)(
|
|
87
|
+
const routes = createRoutes ? createRoutes() : (0, import_react_router_dom.createRoutesFromElements)(
|
|
88
|
+
(0, import_utils.renderRoutes)({
|
|
89
|
+
routesConfig,
|
|
90
|
+
ssrMode
|
|
91
|
+
})
|
|
92
|
+
);
|
|
88
93
|
const { query } = (0, import_remix_router.createStaticHandler)(routes, {
|
|
89
94
|
basename: _basename
|
|
90
95
|
});
|
|
@@ -38,26 +38,28 @@ __export(utils_exports, {
|
|
|
38
38
|
module.exports = __toCommonJS(utils_exports);
|
|
39
39
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
40
40
|
var import_react_router_dom = require("react-router-dom");
|
|
41
|
-
var
|
|
42
|
-
var
|
|
41
|
+
var import_remix_router = require("@modern-js/utils/universal/remix-router");
|
|
42
|
+
var import_nestedRoutes = require("@modern-js/utils/universal/nestedRoutes");
|
|
43
43
|
var import_DefaultNotFound = require("./DefaultNotFound");
|
|
44
44
|
var import_DeferredDataScripts = __toESM(require("./DeferredDataScripts"));
|
|
45
45
|
function getRouteComponents(routes, {
|
|
46
46
|
globalApp,
|
|
47
|
-
ssrMode
|
|
47
|
+
ssrMode,
|
|
48
|
+
props
|
|
48
49
|
}) {
|
|
49
|
-
const Layout = ({ Component, ...
|
|
50
|
+
const Layout = ({ Component, ...props2 }) => {
|
|
50
51
|
const GlobalLayout = globalApp;
|
|
51
52
|
if (!GlobalLayout) {
|
|
52
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...
|
|
53
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...props2 });
|
|
53
54
|
}
|
|
54
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GlobalLayout, { Component, ...
|
|
55
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GlobalLayout, { Component, ...props2 });
|
|
55
56
|
};
|
|
56
57
|
const routeElements = [];
|
|
57
58
|
for (const route of routes) {
|
|
58
59
|
if (route.type === "nested") {
|
|
59
60
|
const routeElement = (0, import_nestedRoutes.renderNestedRoute)(route, {
|
|
60
|
-
DeferredDataComponent: ssrMode === "stream" ? import_DeferredDataScripts.default : void 0
|
|
61
|
+
DeferredDataComponent: ssrMode === "stream" ? import_DeferredDataScripts.default : void 0,
|
|
62
|
+
props
|
|
61
63
|
});
|
|
62
64
|
routeElements.push(routeElement);
|
|
63
65
|
} else {
|
|
@@ -75,7 +77,11 @@ function getRouteComponents(routes, {
|
|
|
75
77
|
routeElements.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router_dom.Route, { path: "*", element: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_DefaultNotFound.DefaultNotFound, {}) }, "*"));
|
|
76
78
|
return routeElements;
|
|
77
79
|
}
|
|
78
|
-
function renderRoutes(
|
|
80
|
+
function renderRoutes({
|
|
81
|
+
routesConfig,
|
|
82
|
+
props,
|
|
83
|
+
ssrMode
|
|
84
|
+
}) {
|
|
79
85
|
if (!routesConfig) {
|
|
80
86
|
return null;
|
|
81
87
|
}
|
|
@@ -83,7 +89,11 @@ function renderRoutes(routesConfig, ssrMode) {
|
|
|
83
89
|
if (!routes) {
|
|
84
90
|
return null;
|
|
85
91
|
}
|
|
86
|
-
const routeElements = getRouteComponents(routes, {
|
|
92
|
+
const routeElements = getRouteComponents(routes, {
|
|
93
|
+
globalApp,
|
|
94
|
+
ssrMode,
|
|
95
|
+
props
|
|
96
|
+
});
|
|
87
97
|
return routeElements;
|
|
88
98
|
}
|
|
89
99
|
function getLocation(serverContext) {
|
|
@@ -61,6 +61,20 @@ var cli_default = () => ({
|
|
|
61
61
|
appContext.internalDirectory,
|
|
62
62
|
"plugins"
|
|
63
63
|
);
|
|
64
|
+
const { builder } = api.useAppContext();
|
|
65
|
+
const bundlerType = (builder == null ? void 0 : builder.context.bundlerType) || "webpack";
|
|
66
|
+
const babelConfig = bundlerType === "webpack" ? (config) => {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
(_a = config.plugins) == null ? void 0 : _a.push(
|
|
69
|
+
import_path.default.join(__dirname, "./babel-plugin-ssr-loader-id")
|
|
70
|
+
);
|
|
71
|
+
const userConfig = api.useResolvedConfigContext();
|
|
72
|
+
if ((0, import_utils.isUseSSRBundle)(userConfig) && hasStringSSREntry(userConfig)) {
|
|
73
|
+
(_b = config.plugins) == null ? void 0 : _b.push(
|
|
74
|
+
require.resolve("@loadable/babel-plugin")
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
} : void 0;
|
|
64
78
|
return {
|
|
65
79
|
source: {
|
|
66
80
|
alias: {
|
|
@@ -94,15 +108,7 @@ var cli_default = () => ({
|
|
|
94
108
|
];
|
|
95
109
|
});
|
|
96
110
|
},
|
|
97
|
-
babel:
|
|
98
|
-
config.plugins.push(
|
|
99
|
-
import_path.default.join(__dirname, "./babel-plugin-ssr-loader-id")
|
|
100
|
-
);
|
|
101
|
-
const userConfig = api.useResolvedConfigContext();
|
|
102
|
-
if ((0, import_utils.isUseSSRBundle)(userConfig) && hasStringSSREntry(userConfig)) {
|
|
103
|
-
config.plugins.push(require.resolve("@loadable/babel-plugin"));
|
|
104
|
-
}
|
|
105
|
-
}
|
|
111
|
+
babel: babelConfig
|
|
106
112
|
}
|
|
107
113
|
};
|
|
108
114
|
},
|
package/dist/cjs/ssr/index.js
CHANGED
|
@@ -20,7 +20,7 @@ __export(buildTemplate_after_exports, {
|
|
|
20
20
|
buildShellAfterTemplate: () => buildShellAfterTemplate
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(buildTemplate_after_exports);
|
|
23
|
-
var import_serialize = require("@modern-js/utils/serialize");
|
|
23
|
+
var import_serialize = require("@modern-js/utils/universal/serialize");
|
|
24
24
|
var import_buildTemplate = require("./buildTemplate.share");
|
|
25
25
|
function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
26
26
|
const callbacks = [injectSSRDataScript];
|
|
@@ -71,8 +71,8 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
71
71
|
if (routeId) {
|
|
72
72
|
const routeManifest2 = routeAssets[routeId];
|
|
73
73
|
if (routeManifest2) {
|
|
74
|
-
const {
|
|
75
|
-
const _cssChunks =
|
|
74
|
+
const { referenceCssAssets = [] } = routeManifest2;
|
|
75
|
+
const _cssChunks = referenceCssAssets.filter(
|
|
76
76
|
(asset) => asset == null ? void 0 : asset.endsWith(".css")
|
|
77
77
|
);
|
|
78
78
|
cssChunks.push(..._cssChunks);
|
|
@@ -32,7 +32,7 @@ __export(entry_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(entry_exports);
|
|
33
33
|
var import_react = __toESM(require("react"));
|
|
34
34
|
var import_server = __toESM(require("react-dom/server"));
|
|
35
|
-
var import_serialize = require("@modern-js/utils/serialize");
|
|
35
|
+
var import_serialize = require("@modern-js/utils/universal/serialize");
|
|
36
36
|
var import_react_helmet = __toESM(require("react-helmet"));
|
|
37
37
|
var import_utils = require("../../../router/runtime/utils");
|
|
38
38
|
var import_helmet = __toESM(require("../helmet"));
|
|
@@ -212,7 +212,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
212
212
|
import { jsx } from "react/jsx-runtime";
|
|
213
213
|
import React, { useContext, useMemo } from "react";
|
|
214
214
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
215
|
-
import { ROUTE_MANIFEST } from "@modern-js/utils/constants";
|
|
215
|
+
import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
|
|
216
216
|
import { RuntimeReactContext } from "../runtimeContext";
|
|
217
217
|
import { runtime } from "./plugin";
|
|
218
218
|
import { createLoaderManager } from "./loader/loaderManager";
|
|
@@ -237,7 +237,8 @@ var createApp = function(param) {
|
|
|
237
237
|
return function(App) {
|
|
238
238
|
var runner = appRuntime.init();
|
|
239
239
|
var WrapperComponent = function(props) {
|
|
240
|
-
var
|
|
240
|
+
var _props_children;
|
|
241
|
+
var element = React.createElement(App || React.Fragment, App ? _objectSpread({}, props) : null, App ? props.children : React.cloneElement(props.children, _objectSpread({}, (_props_children = props.children) === null || _props_children === void 0 ? void 0 : _props_children.props, props)));
|
|
241
242
|
var context = useContext(RuntimeReactContext);
|
|
242
243
|
return runner.provide({
|
|
243
244
|
element: element,
|
|
@@ -47,7 +47,7 @@ function _unsupportedIterableToArray(o, minLen) {
|
|
|
47
47
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
48
48
|
import { Suspense, useEffect, useRef, useMemo, useContext } from "react";
|
|
49
49
|
import { Await, UNSAFE_DataRouterContext as DataRouterContext, useAsyncError } from "react-router-dom";
|
|
50
|
-
import { serializeJson } from "@modern-js/utils/serialize";
|
|
50
|
+
import { serializeJson } from "@modern-js/utils/universal/serialize";
|
|
51
51
|
import { JSX_SHELL_STREAM_END_MARK } from "../../common";
|
|
52
52
|
import { serializeErrors } from "./utils";
|
|
53
53
|
var 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}}))};";
|