@modern-js/runtime 2.58.4-alpha.2 → 2.60.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/dist/cjs/cli/ssr/index.js +1 -1
- package/dist/cjs/core/browser/index.js +0 -5
- package/dist/cjs/core/react/index.js +7 -0
- package/dist/cjs/core/server/string/index.js +6 -6
- package/dist/cjs/router/cli/code/index.js +23 -15
- package/dist/cjs/router/cli/index.js +1 -2
- package/dist/cjs/router/runtime/plugin.js +15 -3
- package/dist/esm/cli/ssr/index.js +4 -3
- package/dist/esm/core/browser/index.js +1 -6
- package/dist/esm/core/react/index.js +7 -0
- package/dist/esm/core/server/react/prerender/index.js +2 -3
- package/dist/esm/core/server/requestHandler.js +2 -1
- package/dist/esm/core/server/stream/afterTemplate.js +2 -1
- package/dist/esm/core/server/string/index.js +15 -31
- package/dist/esm/core/server/string/ssrData.js +2 -1
- package/dist/esm/router/cli/code/index.js +35 -36
- package/dist/esm/router/cli/index.js +1 -2
- package/dist/esm/router/runtime/plugin.js +18 -4
- package/dist/esm-node/cli/ssr/index.js +1 -1
- package/dist/esm-node/core/browser/index.js +0 -5
- package/dist/esm-node/core/react/index.js +7 -0
- package/dist/esm-node/core/server/string/index.js +6 -6
- package/dist/esm-node/router/cli/code/index.js +21 -13
- package/dist/esm-node/router/cli/index.js +1 -2
- package/dist/esm-node/router/runtime/plugin.js +16 -4
- package/dist/types/router/runtime/withRouter.d.ts +5 -3
- package/package.json +13 -13
|
@@ -57,7 +57,7 @@ const ssrBuilderPlugin = (modernAPI) => ({
|
|
|
57
57
|
name: "@modern-js/builder-plugin-ssr",
|
|
58
58
|
setup(api) {
|
|
59
59
|
api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig }) => {
|
|
60
|
-
const isServerEnvironment = config.output.target === "node" || name === "
|
|
60
|
+
const isServerEnvironment = config.output.target === "node" || name === "workerSSR";
|
|
61
61
|
const userConfig = modernAPI.useResolvedConfigContext();
|
|
62
62
|
const useLoadablePlugin = (0, import_utils.isUseSSRBundle)(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig);
|
|
63
63
|
return mergeEnvironmentConfig(config, {
|
|
@@ -31,9 +31,7 @@ __export(browser_exports, {
|
|
|
31
31
|
render: () => render
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(browser_exports);
|
|
34
|
-
var import_parsed = require("@modern-js/runtime-utils/parsed");
|
|
35
34
|
var import_cookie = __toESM(require("cookie"));
|
|
36
|
-
var import_constants = require("../constants");
|
|
37
35
|
var import_context = require("../context");
|
|
38
36
|
var import_runtime = require("../context/runtime");
|
|
39
37
|
var import_loaderManager = require("../loader/loaderManager");
|
|
@@ -92,9 +90,6 @@ async function render(App, id) {
|
|
|
92
90
|
};
|
|
93
91
|
if (isClientArgs(id)) {
|
|
94
92
|
var _ssrData_data, _ssrData_data1;
|
|
95
|
-
window._SSR_DATA = window._SSR_DATA || (0, import_parsed.parsedJSONFromElement)(import_constants.SSR_DATA_JSON_ID);
|
|
96
|
-
const routeData = (0, import_parsed.parsedJSONFromElement)(import_constants.ROUTER_DATA_JSON_ID);
|
|
97
|
-
window._ROUTER_DATA = window._ROUTER_DATA || routeData;
|
|
98
93
|
const ssrData = getSSRData();
|
|
99
94
|
const loadersData = (ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_data = ssrData.data) === null || _ssrData_data === void 0 ? void 0 : _ssrData_data.loadersData) || {};
|
|
100
95
|
const initialLoadersState = Object.keys(loadersData).reduce((res, key) => {
|
|
@@ -21,10 +21,17 @@ __export(react_exports, {
|
|
|
21
21
|
createRoot: () => createRoot
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(react_exports);
|
|
24
|
+
var import_parsed = require("@modern-js/runtime-utils/parsed");
|
|
25
|
+
var import_common = require("../../common");
|
|
26
|
+
var import_constants = require("../constants");
|
|
24
27
|
var import_context = require("../context");
|
|
25
28
|
var import_runner = require("../plugin/runner");
|
|
26
29
|
function createRoot(UserApp) {
|
|
27
30
|
const App = UserApp || (0, import_context.getGlobalApp)();
|
|
31
|
+
if ((0, import_common.isBrowser)()) {
|
|
32
|
+
window._SSR_DATA = window._SSR_DATA || (0, import_parsed.parsedJSONFromElement)(import_constants.SSR_DATA_JSON_ID);
|
|
33
|
+
window._ROUTER_DATA = window._ROUTER_DATA || (0, import_parsed.parsedJSONFromElement)(import_constants.ROUTER_DATA_JSON_ID);
|
|
34
|
+
}
|
|
28
35
|
const runner = (0, import_runner.getGlobalRunner)();
|
|
29
36
|
const WrapperApp = runner.wrapRoot(App);
|
|
30
37
|
return WrapperApp;
|
|
@@ -102,26 +102,26 @@ const renderString = async (request, serverRoot, options) => {
|
|
|
102
102
|
});
|
|
103
103
|
};
|
|
104
104
|
async function generateHtml(App, htmlTemplate, chunkSet, collectors, htmlModifiers, { onError, onTiming }) {
|
|
105
|
-
const end = (0, import_time.time)();
|
|
106
105
|
let html = "";
|
|
107
106
|
let helmetData;
|
|
107
|
+
const finalApp = collectors.reduce((pre, creator) => {
|
|
108
|
+
var _creator_collect;
|
|
109
|
+
return ((_creator_collect = creator.collect) === null || _creator_collect === void 0 ? void 0 : _creator_collect.call(creator, pre)) || pre;
|
|
110
|
+
}, App);
|
|
108
111
|
try {
|
|
109
|
-
const
|
|
110
|
-
var _creator_collect;
|
|
111
|
-
return ((_creator_collect = creator.collect) === null || _creator_collect === void 0 ? void 0 : _creator_collect.call(creator, pre)) || pre;
|
|
112
|
-
}, App);
|
|
112
|
+
const end = (0, import_time.time)();
|
|
113
113
|
if (chunkSet.renderLevel >= import_constants.RenderLevel.SERVER_PREFETCH) {
|
|
114
114
|
html = import_server.default.renderToString(finalApp);
|
|
115
115
|
chunkSet.renderLevel = import_constants.RenderLevel.SERVER_RENDER;
|
|
116
116
|
}
|
|
117
117
|
helmetData = import_react_helmet.default.renderStatic();
|
|
118
|
-
await Promise.all(collectors.map((component) => component.effect()));
|
|
119
118
|
const cost = end();
|
|
120
119
|
onTiming(import_tracer.SSRTimings.RENDER_HTML, cost);
|
|
121
120
|
} catch (e) {
|
|
122
121
|
chunkSet.renderLevel = import_constants.RenderLevel.CLIENT_RENDER;
|
|
123
122
|
onError(import_tracer.SSRErrors.RENDER_HTML, e);
|
|
124
123
|
}
|
|
124
|
+
await Promise.all(collectors.map((component) => component.effect()));
|
|
125
125
|
const { ssrScripts, cssChunk, jsChunk } = chunkSet;
|
|
126
126
|
const finalHtml = await (0, import_shared.buildHtml)(htmlTemplate, [
|
|
127
127
|
createReplaceHtml(html),
|
|
@@ -34,7 +34,6 @@ __export(code_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(code_exports);
|
|
35
35
|
var import_path = __toESM(require("path"));
|
|
36
36
|
var import_utils = require("@modern-js/utils");
|
|
37
|
-
var import_route = require("@modern-js/utils/universal/route");
|
|
38
37
|
var import_lodash = require("@modern-js/utils/lodash");
|
|
39
38
|
var import_constants = require("../../../cli/constants");
|
|
40
39
|
var import_constants2 = require("../constants");
|
|
@@ -85,7 +84,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
85
84
|
const config2 = api.useResolvedConfigContext();
|
|
86
85
|
const ssrByRouteIds = config2.server.ssrByRouteIds || [];
|
|
87
86
|
const clonedRoutes = (0, import_lodash.cloneDeep)(initialRoutes);
|
|
88
|
-
const markedRoutes = ssrByRouteIds.length > 0 ?
|
|
87
|
+
const markedRoutes = ssrByRouteIds.length > 0 ? markRoutes(clonedRoutes, ssrByRouteIds) : initialRoutes;
|
|
89
88
|
const { routes } = await hookRunners.modifyFileSystemRoutes({
|
|
90
89
|
entrypoint,
|
|
91
90
|
routes: markedRoutes
|
|
@@ -116,10 +115,10 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
116
115
|
})
|
|
117
116
|
});
|
|
118
117
|
if (entrypoint.nestedRoutesEntry && (0, import_utils.isUseSSRBundle)(config2)) {
|
|
119
|
-
var _config_output1
|
|
118
|
+
var _config_output1;
|
|
120
119
|
const routesServerFile = (0, import_utils2.getServerLoadersFile)(internalDirectory, entryName);
|
|
121
|
-
const filtedRoutesForServer = (0,
|
|
122
|
-
const routesForServerLoaderMatches = (0,
|
|
120
|
+
const filtedRoutesForServer = (0, import_utils.filterRoutesForServer)(routes);
|
|
121
|
+
const routesForServerLoaderMatches = (0, import_utils.filterRoutesLoader)(routes);
|
|
123
122
|
const code2 = templates.routesForServer({
|
|
124
123
|
routesForServerLoaderMatches
|
|
125
124
|
});
|
|
@@ -135,16 +134,6 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
135
134
|
splitRouteChunks: config2 === null || config2 === void 0 ? void 0 : (_config_output1 = config2.output) === null || _config_output1 === void 0 ? void 0 : _config_output1.splitRouteChunks
|
|
136
135
|
});
|
|
137
136
|
await import_utils.fs.outputFile(import_path.default.resolve(internalDirectory, `./${entryName}/routes.server.js`), serverRoutesCode, "utf8");
|
|
138
|
-
const mfServerRoutesCode = await templates.fileSystemRoutes({
|
|
139
|
-
metaName,
|
|
140
|
-
routes,
|
|
141
|
-
ssrMode: useSSG ? "string" : mode,
|
|
142
|
-
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
143
|
-
entryName: entrypoint.entryName,
|
|
144
|
-
internalDirectory,
|
|
145
|
-
splitRouteChunks: config2 === null || config2 === void 0 ? void 0 : (_config_output2 = config2.output) === null || _config_output2 === void 0 ? void 0 : _config_output2.splitRouteChunks
|
|
146
|
-
});
|
|
147
|
-
await import_utils.fs.outputFile(import_path.default.resolve(internalDirectory, `./${entryName}/mf-routes.js`), mfServerRoutesCode, "utf8");
|
|
148
137
|
}
|
|
149
138
|
const serverLoaderCombined = templates.ssrLoaderCombinedModule(entrypoints, entrypoint, config2, appContext);
|
|
150
139
|
if (serverLoaderCombined) {
|
|
@@ -156,6 +145,25 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
156
145
|
}
|
|
157
146
|
}
|
|
158
147
|
};
|
|
148
|
+
function markRoutes(routes, routeIds) {
|
|
149
|
+
return routes.map((route) => {
|
|
150
|
+
if (route.type !== "nested") {
|
|
151
|
+
return route;
|
|
152
|
+
}
|
|
153
|
+
if (route.children && route.children.length > 0) {
|
|
154
|
+
route.children = markRoutes(route.children, routeIds);
|
|
155
|
+
}
|
|
156
|
+
if (route.children && route.children.length > 0) {
|
|
157
|
+
route.inValidSSRRoute = route.children.every((child) => {
|
|
158
|
+
var _child_inValidSSRRoute;
|
|
159
|
+
return (_child_inValidSSRRoute = child.inValidSSRRoute) !== null && _child_inValidSSRRoute !== void 0 ? _child_inValidSSRRoute : false;
|
|
160
|
+
});
|
|
161
|
+
} else if (route.id) {
|
|
162
|
+
route.inValidSSRRoute = !routeIds.includes(route.id);
|
|
163
|
+
}
|
|
164
|
+
return route;
|
|
165
|
+
});
|
|
166
|
+
}
|
|
159
167
|
function generatorRegisterCode(internalDirectory, entryName, code) {
|
|
160
168
|
import_utils.fs.outputFileSync(import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME}`), code, "utf8");
|
|
161
169
|
}
|
|
@@ -37,7 +37,6 @@ __export(cli_exports, {
|
|
|
37
37
|
module.exports = __toCommonJS(cli_exports);
|
|
38
38
|
var import_node_path = __toESM(require("node:path"));
|
|
39
39
|
var import_utils = require("@modern-js/utils");
|
|
40
|
-
var import_route = require("@modern-js/utils/universal/route");
|
|
41
40
|
var import_entry = require("./entry");
|
|
42
41
|
var import_handler = require("./handler");
|
|
43
42
|
var import_entry2 = require("./entry");
|
|
@@ -116,7 +115,7 @@ const routerPlugin = () => ({
|
|
|
116
115
|
},
|
|
117
116
|
async modifyFileSystemRoutes({ entrypoint, routes }) {
|
|
118
117
|
nestedRoutes[entrypoint.entryName] = routes;
|
|
119
|
-
nestedRoutesForServer[entrypoint.entryName] = (0,
|
|
118
|
+
nestedRoutesForServer[entrypoint.entryName] = (0, import_utils.filterRoutesForServer)(routes);
|
|
120
119
|
return {
|
|
121
120
|
entrypoint,
|
|
122
121
|
routes
|
|
@@ -135,12 +135,24 @@ const routerPlugin = (userConfig = {}) => {
|
|
|
135
135
|
getBlockNavState
|
|
136
136
|
]);
|
|
137
137
|
};
|
|
138
|
+
const Null = () => null;
|
|
138
139
|
return (props) => {
|
|
139
140
|
beforeCreateRouter = false;
|
|
140
141
|
const router = useCreateRouter(props);
|
|
141
|
-
return
|
|
142
|
-
router
|
|
143
|
-
|
|
142
|
+
return (
|
|
143
|
+
// To match the node tree about https://github.com/web-infra-dev/modern.js/blob/v2.59.0/packages/runtime/plugin-runtime/src/router/runtime/plugin.node.tsx#L150-L168
|
|
144
|
+
// According to react [useId generation algorithm](https://github.com/facebook/react/pull/22644), `useId` will generate id with the react node react struct.
|
|
145
|
+
// To void hydration failed, we must guarantee that the node tree when browser hydrate must have same struct with node tree when ssr render.
|
|
146
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
147
|
+
children: [
|
|
148
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_router.RouterProvider, {
|
|
149
|
+
router
|
|
150
|
+
}),
|
|
151
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Null, {}),
|
|
152
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Null, {})
|
|
153
|
+
]
|
|
154
|
+
})
|
|
155
|
+
);
|
|
144
156
|
};
|
|
145
157
|
};
|
|
146
158
|
return getRouteApp();
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
2
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
3
|
+
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
3
4
|
import path from "path";
|
|
4
5
|
import { LOADABLE_STATS_FILE, isUseSSRBundle } from "@modern-js/utils";
|
|
5
6
|
var hasStringSSREntry = function(userConfig) {
|
|
6
7
|
var isStreaming = function(ssr) {
|
|
7
|
-
return ssr && typeof ssr === "object" && ssr.mode === "stream";
|
|
8
|
+
return ssr && (typeof ssr === "undefined" ? "undefined" : _type_of(ssr)) === "object" && ssr.mode === "stream";
|
|
8
9
|
};
|
|
9
10
|
var server = userConfig.server, output = userConfig.output;
|
|
10
11
|
if (((server === null || server === void 0 ? void 0 : server.ssr) || output.ssg) && !isStreaming(server.ssr)) {
|
|
11
12
|
return true;
|
|
12
13
|
}
|
|
13
|
-
if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) &&
|
|
14
|
+
if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && _type_of(server.ssrByEntries) === "object") {
|
|
14
15
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
15
16
|
try {
|
|
16
17
|
for (var _iterator = Object.keys(server.ssrByEntries)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
@@ -46,7 +47,7 @@ var ssrBuilderPlugin = function(modernAPI) {
|
|
|
46
47
|
setup: function setup(api) {
|
|
47
48
|
api.modifyEnvironmentConfig(function(config, param) {
|
|
48
49
|
var name = param.name, mergeEnvironmentConfig = param.mergeEnvironmentConfig;
|
|
49
|
-
var isServerEnvironment = config.output.target === "node" || name === "
|
|
50
|
+
var isServerEnvironment = config.output.target === "node" || name === "workerSSR";
|
|
50
51
|
var userConfig = modernAPI.useResolvedConfigContext();
|
|
51
52
|
var useLoadablePlugin = isUseSSRBundle(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig);
|
|
52
53
|
return mergeEnvironmentConfig(config, {
|
|
@@ -4,9 +4,7 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
|
4
4
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
5
5
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
6
6
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
7
|
-
import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
|
|
8
7
|
import cookieTool from "cookie";
|
|
9
|
-
import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../constants";
|
|
10
8
|
import { getGlobalAppInit } from "../context";
|
|
11
9
|
import { getInitialContext } from "../context/runtime";
|
|
12
10
|
import { createLoaderManager } from "../loader/loaderManager";
|
|
@@ -56,7 +54,7 @@ function render(App, id) {
|
|
|
56
54
|
}
|
|
57
55
|
function _render() {
|
|
58
56
|
_render = _async_to_generator(function(App, id) {
|
|
59
|
-
var runner, context, runBeforeRender, ModernRender, ModernHydrate, _ssrData_data, _ssrData_data1,
|
|
57
|
+
var runner, context, runBeforeRender, ModernRender, ModernHydrate, _ssrData_data, _ssrData_data1, ssrData, loadersData, initialLoadersState, initialData, rootElement;
|
|
60
58
|
function _ModernRender() {
|
|
61
59
|
_ModernRender = _async_to_generator(function(App2) {
|
|
62
60
|
var renderFunc;
|
|
@@ -123,9 +121,6 @@ function _render() {
|
|
|
123
121
|
ModernHydrate = function ModernHydrate2(App2, callback) {
|
|
124
122
|
return _ModernHydrate.apply(this, arguments);
|
|
125
123
|
};
|
|
126
|
-
window._SSR_DATA = window._SSR_DATA || parsedJSONFromElement(SSR_DATA_JSON_ID);
|
|
127
|
-
routeData = parsedJSONFromElement(ROUTER_DATA_JSON_ID);
|
|
128
|
-
window._ROUTER_DATA = window._ROUTER_DATA || routeData;
|
|
129
124
|
ssrData = getSSRData();
|
|
130
125
|
loadersData = (ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_data = ssrData.data) === null || _ssrData_data === void 0 ? void 0 : _ssrData_data.loadersData) || {};
|
|
131
126
|
initialLoadersState = Object.keys(loadersData).reduce(function(res, key) {
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
|
|
2
|
+
import { isBrowser } from "../../common";
|
|
3
|
+
import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../constants";
|
|
1
4
|
import { getGlobalApp } from "../context";
|
|
2
5
|
import { getGlobalRunner } from "../plugin/runner";
|
|
3
6
|
function createRoot(UserApp) {
|
|
4
7
|
var App = UserApp || getGlobalApp();
|
|
8
|
+
if (isBrowser()) {
|
|
9
|
+
window._SSR_DATA = window._SSR_DATA || parsedJSONFromElement(SSR_DATA_JSON_ID);
|
|
10
|
+
window._ROUTER_DATA = window._ROUTER_DATA || parsedJSONFromElement(ROUTER_DATA_JSON_ID);
|
|
11
|
+
}
|
|
5
12
|
var runner = getGlobalRunner();
|
|
6
13
|
var WrapperApp = runner.wrapRoot(App);
|
|
7
14
|
return WrapperApp;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { _ as _call_super } from "@swc/helpers/_/_call_super";
|
|
1
2
|
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
2
3
|
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
|
3
4
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
4
5
|
import { _ as _inherits } from "@swc/helpers/_/_inherits";
|
|
5
6
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
6
7
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
7
|
-
import { _ as _create_super } from "@swc/helpers/_/_create_super";
|
|
8
8
|
import React, { createElement } from "react";
|
|
9
9
|
import withSideEffect from "react-side-effect";
|
|
10
10
|
import { aggKeysFromPropsList, aggMatchesFromPropsList, exist, getOutermostProperty } from "./util";
|
|
@@ -55,10 +55,9 @@ function factory(Component) {
|
|
|
55
55
|
var Spr = /* @__PURE__ */ function(_React_Component) {
|
|
56
56
|
"use strict";
|
|
57
57
|
_inherits(Spr2, _React_Component);
|
|
58
|
-
var _super = _create_super(Spr2);
|
|
59
58
|
function Spr2() {
|
|
60
59
|
_class_call_check(this, Spr2);
|
|
61
|
-
return
|
|
60
|
+
return _call_super(this, Spr2, arguments);
|
|
62
61
|
}
|
|
63
62
|
var _proto = Spr2.prototype;
|
|
64
63
|
_proto.verify = function verify() {
|
|
@@ -3,6 +3,7 @@ import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
|
3
3
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
4
4
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
5
5
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
6
|
+
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
6
7
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
7
8
|
import { getPathname, parseCookie, parseHeaders, parseQuery } from "@modern-js/runtime-utils/universal/request";
|
|
8
9
|
import { getGlobalAppInit } from "../context";
|
|
@@ -30,7 +31,7 @@ function createSSRContext(request, options) {
|
|
|
30
31
|
}
|
|
31
32
|
var ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries);
|
|
32
33
|
var ssrMode = getSSRMode(ssrConfig);
|
|
33
|
-
var loaderFailureMode = typeof ssrConfig === "object" ? ssrConfig.loaderFailureMode : void 0;
|
|
34
|
+
var loaderFailureMode = (typeof ssrConfig === "undefined" ? "undefined" : _type_of(ssrConfig)) === "object" ? ssrConfig.loaderFailureMode : void 0;
|
|
34
35
|
return {
|
|
35
36
|
nonce,
|
|
36
37
|
loaderContext,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
3
|
+
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
3
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
5
|
import { serializeJson } from "@modern-js/runtime-utils/node";
|
|
5
6
|
import { SSR_DATA_PLACEHOLDER } from "../constants";
|
|
@@ -57,7 +58,7 @@ function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
|
57
58
|
function createReplaceSSRData(options) {
|
|
58
59
|
var runtimeContext = options.runtimeContext, nonce = options.nonce, renderLevel = options.renderLevel, ssrConfig = options.ssrConfig;
|
|
59
60
|
var _runtimeContext_ssrContext = runtimeContext.ssrContext, request = _runtimeContext_ssrContext.request, reporter = _runtimeContext_ssrContext.reporter;
|
|
60
|
-
var headers = typeof ssrConfig === "object" && ssrConfig.unsafeHeaders ? Object.fromEntries(Object.entries(request.headers).filter(function(param) {
|
|
61
|
+
var headers = (typeof ssrConfig === "undefined" ? "undefined" : _type_of(ssrConfig)) === "object" && ssrConfig.unsafeHeaders ? Object.fromEntries(Object.entries(request.headers).filter(function(param) {
|
|
61
62
|
var _param = _sliced_to_array(param, 2), key = _param[0], _ = _param[1];
|
|
62
63
|
var _ssrConfig_unsafeHeaders_map, _ssrConfig_unsafeHeaders;
|
|
63
64
|
return (_ssrConfig_unsafeHeaders = ssrConfig.unsafeHeaders) === null || _ssrConfig_unsafeHeaders === void 0 ? void 0 : (_ssrConfig_unsafeHeaders_map = _ssrConfig_unsafeHeaders.map(function(header) {
|
|
@@ -121,53 +121,37 @@ function generateHtml(App, htmlTemplate, chunkSet, collectors, htmlModifiers, _)
|
|
|
121
121
|
}
|
|
122
122
|
function _generateHtml() {
|
|
123
123
|
_generateHtml = _async_to_generator(function(App, htmlTemplate, chunkSet, collectors, htmlModifiers, param) {
|
|
124
|
-
var onError, onTiming,
|
|
124
|
+
var onError, onTiming, html, helmetData, finalApp, end, cost, ssrScripts, cssChunk, jsChunk, finalHtml;
|
|
125
125
|
return _ts_generator(this, function(_state) {
|
|
126
126
|
switch (_state.label) {
|
|
127
127
|
case 0:
|
|
128
128
|
onError = param.onError, onTiming = param.onTiming;
|
|
129
|
-
end = time();
|
|
130
129
|
html = "";
|
|
131
|
-
_state.label = 1;
|
|
132
|
-
case 1:
|
|
133
|
-
_state.trys.push([
|
|
134
|
-
1,
|
|
135
|
-
3,
|
|
136
|
-
,
|
|
137
|
-
4
|
|
138
|
-
]);
|
|
139
130
|
finalApp = collectors.reduce(function(pre, creator) {
|
|
140
131
|
var _creator_collect;
|
|
141
132
|
return ((_creator_collect = creator.collect) === null || _creator_collect === void 0 ? void 0 : _creator_collect.call(creator, pre)) || pre;
|
|
142
133
|
}, App);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
chunkSet.renderLevel
|
|
134
|
+
try {
|
|
135
|
+
end = time();
|
|
136
|
+
if (chunkSet.renderLevel >= RenderLevel.SERVER_PREFETCH) {
|
|
137
|
+
html = ReactDomServer.renderToString(finalApp);
|
|
138
|
+
chunkSet.renderLevel = RenderLevel.SERVER_RENDER;
|
|
139
|
+
}
|
|
140
|
+
helmetData = ReactHelmet.renderStatic();
|
|
141
|
+
cost = end();
|
|
142
|
+
onTiming(SSRTimings.RENDER_HTML, cost);
|
|
143
|
+
} catch (e) {
|
|
144
|
+
chunkSet.renderLevel = RenderLevel.CLIENT_RENDER;
|
|
145
|
+
onError(SSRErrors.RENDER_HTML, e);
|
|
146
146
|
}
|
|
147
|
-
helmetData = ReactHelmet.renderStatic();
|
|
148
147
|
return [
|
|
149
148
|
4,
|
|
150
149
|
Promise.all(collectors.map(function(component) {
|
|
151
150
|
return component.effect();
|
|
152
151
|
}))
|
|
153
152
|
];
|
|
154
|
-
case
|
|
153
|
+
case 1:
|
|
155
154
|
_state.sent();
|
|
156
|
-
cost = end();
|
|
157
|
-
onTiming(SSRTimings.RENDER_HTML, cost);
|
|
158
|
-
return [
|
|
159
|
-
3,
|
|
160
|
-
4
|
|
161
|
-
];
|
|
162
|
-
case 3:
|
|
163
|
-
e = _state.sent();
|
|
164
|
-
chunkSet.renderLevel = RenderLevel.CLIENT_RENDER;
|
|
165
|
-
onError(SSRErrors.RENDER_HTML, e);
|
|
166
|
-
return [
|
|
167
|
-
3,
|
|
168
|
-
4
|
|
169
|
-
];
|
|
170
|
-
case 4:
|
|
171
155
|
ssrScripts = chunkSet.ssrScripts, cssChunk = chunkSet.cssChunk, jsChunk = chunkSet.jsChunk;
|
|
172
156
|
return [
|
|
173
157
|
4,
|
|
@@ -179,7 +163,7 @@ function _generateHtml() {
|
|
|
179
163
|
createReplaceHelemt(helmetData)
|
|
180
164
|
].concat(_to_consumable_array(htmlModifiers)))
|
|
181
165
|
];
|
|
182
|
-
case
|
|
166
|
+
case 2:
|
|
183
167
|
finalHtml = _state.sent();
|
|
184
168
|
return [
|
|
185
169
|
2,
|
|
@@ -5,6 +5,7 @@ import { _ as _class_private_field_set } from "@swc/helpers/_/_class_private_fie
|
|
|
5
5
|
import { _ as _class_private_method_get } from "@swc/helpers/_/_class_private_method_get";
|
|
6
6
|
import { _ as _class_private_method_init } from "@swc/helpers/_/_class_private_method_init";
|
|
7
7
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
8
|
+
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
8
9
|
import { serializeJson } from "@modern-js/runtime-utils/node";
|
|
9
10
|
import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../../constants";
|
|
10
11
|
import { attributesToString, serializeErrors } from "../utils";
|
|
@@ -37,7 +38,7 @@ var SSRDataCollector = /* @__PURE__ */ function() {
|
|
|
37
38
|
function getSSRData() {
|
|
38
39
|
var _$_class_private_field_get = _class_private_field_get(this, _options), prefetchData = _$_class_private_field_get.prefetchData, chunkSet = _$_class_private_field_get.chunkSet, ssrConfig = _$_class_private_field_get.ssrConfig, ssrContext = _$_class_private_field_get.ssrContext;
|
|
39
40
|
var reporter = ssrContext.reporter, request = ssrContext.request;
|
|
40
|
-
var headers = typeof ssrConfig === "object" && ssrConfig.unsafeHeaders ? Object.fromEntries(Object.entries(request.headers).filter(function(param) {
|
|
41
|
+
var headers = (typeof ssrConfig === "undefined" ? "undefined" : _type_of(ssrConfig)) === "object" && ssrConfig.unsafeHeaders ? Object.fromEntries(Object.entries(request.headers).filter(function(param) {
|
|
41
42
|
var _param = _sliced_to_array(param, 2), key = _param[0], _ = _param[1];
|
|
42
43
|
var _ssrConfig_unsafeHeaders_map, _ssrConfig_unsafeHeaders;
|
|
43
44
|
return (_ssrConfig_unsafeHeaders = ssrConfig.unsafeHeaders) === null || _ssrConfig_unsafeHeaders === void 0 ? void 0 : (_ssrConfig_unsafeHeaders_map = _ssrConfig_unsafeHeaders.map(function(header) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
2
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
4
|
import path from "path";
|
|
4
|
-
import { fs, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger } from "@modern-js/utils";
|
|
5
|
-
import { filterRoutesForServer, filterRoutesLoader, markRoutes } from "@modern-js/utils/universal/route";
|
|
5
|
+
import { fs, filterRoutesForServer, filterRoutesLoader, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger } from "@modern-js/utils";
|
|
6
6
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
7
7
|
import { ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME } from "../../../cli/constants";
|
|
8
8
|
import { FILE_SYSTEM_ROUTES_FILE_NAME } from "../constants";
|
|
@@ -18,7 +18,7 @@ var generateCode = function() {
|
|
|
18
18
|
}
|
|
19
19
|
function _generateEntryCode() {
|
|
20
20
|
_generateEntryCode = _async_to_generator(function(entrypoint) {
|
|
21
|
-
var entryName, isMainEntry, isAutoMount, pageRoutesEntry, nestedRoutesEntry, metaName, _config_output, initialRoutes, nestedRoutes, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, _$config, ssrByRouteIds, clonedRoutes, markedRoutes, routes, ssr, useSSG, mode, hasPageRoute, code, _, _tmp, _config_output1,
|
|
21
|
+
var entryName, isMainEntry, isAutoMount, pageRoutesEntry, nestedRoutesEntry, metaName, _config_output, initialRoutes, nestedRoutes, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, _$config, ssrByRouteIds, clonedRoutes, markedRoutes, routes, ssr, useSSG, mode, hasPageRoute, code, _, _tmp, _config_output1, routesServerFile, filtedRoutesForServer, routesForServerLoaderMatches, code1, serverRoutesCode, serverLoaderCombined, serverLoaderFile;
|
|
22
22
|
return _ts_generator(this, function(_state) {
|
|
23
23
|
switch (_state.label) {
|
|
24
24
|
case 0:
|
|
@@ -27,12 +27,12 @@ var generateCode = function() {
|
|
|
27
27
|
if (!isAutoMount)
|
|
28
28
|
return [
|
|
29
29
|
3,
|
|
30
|
-
|
|
30
|
+
14
|
|
31
31
|
];
|
|
32
32
|
if (!(pageRoutesEntry || nestedRoutesEntry))
|
|
33
33
|
return [
|
|
34
34
|
3,
|
|
35
|
-
|
|
35
|
+
14
|
|
36
36
|
];
|
|
37
37
|
initialRoutes = [];
|
|
38
38
|
nestedRoutes = null;
|
|
@@ -104,7 +104,7 @@ var generateCode = function() {
|
|
|
104
104
|
ssr = getEntryOptions(entryName, isMainEntry, _$config.server.ssr, _$config.server.ssrByEntries, packageName);
|
|
105
105
|
useSSG = isSSGEntry(_$config, entryName, entrypoints);
|
|
106
106
|
if (ssr) {
|
|
107
|
-
mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
|
|
107
|
+
mode = (typeof ssr === "undefined" ? "undefined" : _type_of(ssr)) === "object" ? ssr.mode || "string" : "string";
|
|
108
108
|
}
|
|
109
109
|
if (mode === "stream") {
|
|
110
110
|
hasPageRoute = routes.some(function(route2) {
|
|
@@ -143,7 +143,7 @@ var generateCode = function() {
|
|
|
143
143
|
if (!(entrypoint.nestedRoutesEntry && isUseSSRBundle(_$config)))
|
|
144
144
|
return [
|
|
145
145
|
3,
|
|
146
|
-
|
|
146
|
+
10
|
|
147
147
|
];
|
|
148
148
|
routesServerFile = getServerLoadersFile(internalDirectory, entryName);
|
|
149
149
|
filtedRoutesForServer = filterRoutesForServer(routes);
|
|
@@ -183,51 +183,31 @@ var generateCode = function() {
|
|
|
183
183
|
];
|
|
184
184
|
case 9:
|
|
185
185
|
_state.sent();
|
|
186
|
-
|
|
187
|
-
4,
|
|
188
|
-
templates.fileSystemRoutes({
|
|
189
|
-
metaName,
|
|
190
|
-
routes,
|
|
191
|
-
ssrMode: useSSG ? "string" : mode,
|
|
192
|
-
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
193
|
-
entryName: entrypoint.entryName,
|
|
194
|
-
internalDirectory,
|
|
195
|
-
splitRouteChunks: _$config === null || _$config === void 0 ? void 0 : (_config_output2 = _$config.output) === null || _config_output2 === void 0 ? void 0 : _config_output2.splitRouteChunks
|
|
196
|
-
})
|
|
197
|
-
];
|
|
186
|
+
_state.label = 10;
|
|
198
187
|
case 10:
|
|
199
|
-
mfServerRoutesCode = _state.sent();
|
|
200
|
-
return [
|
|
201
|
-
4,
|
|
202
|
-
fs.outputFile(path.resolve(internalDirectory, "./".concat(entryName, "/mf-routes.js")), mfServerRoutesCode, "utf8")
|
|
203
|
-
];
|
|
204
|
-
case 11:
|
|
205
|
-
_state.sent();
|
|
206
|
-
_state.label = 12;
|
|
207
|
-
case 12:
|
|
208
188
|
serverLoaderCombined = templates.ssrLoaderCombinedModule(entrypoints, entrypoint, _$config, appContext);
|
|
209
189
|
if (!serverLoaderCombined)
|
|
210
190
|
return [
|
|
211
191
|
3,
|
|
212
|
-
|
|
192
|
+
12
|
|
213
193
|
];
|
|
214
194
|
serverLoaderFile = getServerCombinedModueFile(internalDirectory, entryName);
|
|
215
195
|
return [
|
|
216
196
|
4,
|
|
217
197
|
fs.outputFile(serverLoaderFile, serverLoaderCombined)
|
|
218
198
|
];
|
|
219
|
-
case
|
|
199
|
+
case 11:
|
|
220
200
|
_state.sent();
|
|
221
|
-
_state.label =
|
|
222
|
-
case
|
|
201
|
+
_state.label = 12;
|
|
202
|
+
case 12:
|
|
223
203
|
return [
|
|
224
204
|
4,
|
|
225
205
|
fs.outputFile(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME)), code, "utf8")
|
|
226
206
|
];
|
|
227
|
-
case
|
|
207
|
+
case 13:
|
|
228
208
|
_state.sent();
|
|
229
|
-
_state.label =
|
|
230
|
-
case
|
|
209
|
+
_state.label = 14;
|
|
210
|
+
case 14:
|
|
231
211
|
return [
|
|
232
212
|
2
|
|
233
213
|
];
|
|
@@ -243,7 +223,7 @@ var generateCode = function() {
|
|
|
243
223
|
hookRunners = api.useHookRunners();
|
|
244
224
|
isV5 = isRouterV5(config);
|
|
245
225
|
getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
|
246
|
-
oldVersion =
|
|
226
|
+
oldVersion = _type_of(config === null || config === void 0 ? void 0 : config.runtime.router) === "object" ? Boolean((config === null || config === void 0 ? void 0 : config.runtime.router).oldVersion) : false;
|
|
247
227
|
return [
|
|
248
228
|
4,
|
|
249
229
|
Promise.all(entrypoints.map(generateEntryCode))
|
|
@@ -260,6 +240,25 @@ var generateCode = function() {
|
|
|
260
240
|
return _ref.apply(this, arguments);
|
|
261
241
|
};
|
|
262
242
|
}();
|
|
243
|
+
function markRoutes(routes, routeIds) {
|
|
244
|
+
return routes.map(function(route) {
|
|
245
|
+
if (route.type !== "nested") {
|
|
246
|
+
return route;
|
|
247
|
+
}
|
|
248
|
+
if (route.children && route.children.length > 0) {
|
|
249
|
+
route.children = markRoutes(route.children, routeIds);
|
|
250
|
+
}
|
|
251
|
+
if (route.children && route.children.length > 0) {
|
|
252
|
+
route.inValidSSRRoute = route.children.every(function(child) {
|
|
253
|
+
var _child_inValidSSRRoute;
|
|
254
|
+
return (_child_inValidSSRRoute = child.inValidSSRRoute) !== null && _child_inValidSSRRoute !== void 0 ? _child_inValidSSRRoute : false;
|
|
255
|
+
});
|
|
256
|
+
} else if (route.id) {
|
|
257
|
+
route.inValidSSRRoute = !routeIds.includes(route.id);
|
|
258
|
+
}
|
|
259
|
+
return route;
|
|
260
|
+
});
|
|
261
|
+
}
|
|
263
262
|
function generatorRegisterCode(internalDirectory, entryName, code) {
|
|
264
263
|
fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME)), code, "utf8");
|
|
265
264
|
}
|
|
@@ -3,8 +3,7 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
|
3
3
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import { fs, NESTED_ROUTE_SPEC_FILE, createRuntimeExportsUtils, getEntryOptions, isRouterV5 as isV5 } from "@modern-js/utils";
|
|
7
|
-
import { filterRoutesForServer } from "@modern-js/utils/universal/route";
|
|
6
|
+
import { fs, NESTED_ROUTE_SPEC_FILE, createRuntimeExportsUtils, filterRoutesForServer, getEntryOptions, isRouterV5 as isV5 } from "@modern-js/utils";
|
|
8
7
|
import { isRouteEntry } from "./entry";
|
|
9
8
|
import { handleFileChange, handleGeneratorEntryCode, handleModifyEntrypoints } from "./handler";
|
|
10
9
|
import { isRouteEntry as isRouteEntry2 } from "./entry";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
2
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
3
3
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
5
5
|
import { merge } from "@modern-js/runtime-utils/merge";
|
|
6
6
|
import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
|
|
7
7
|
import { RouterProvider, createBrowserRouter, createHashRouter, createRoutesFromElements, useHref, useLocation, useMatches } from "@modern-js/runtime-utils/router";
|
|
@@ -118,12 +118,26 @@ var routerPlugin = function() {
|
|
|
118
118
|
getBlockNavState
|
|
119
119
|
]);
|
|
120
120
|
};
|
|
121
|
+
var Null = function() {
|
|
122
|
+
return null;
|
|
123
|
+
};
|
|
121
124
|
return function(props) {
|
|
122
125
|
beforeCreateRouter = false;
|
|
123
126
|
var router = useCreateRouter(props);
|
|
124
|
-
return
|
|
125
|
-
router
|
|
126
|
-
|
|
127
|
+
return (
|
|
128
|
+
// To match the node tree about https://github.com/web-infra-dev/modern.js/blob/v2.59.0/packages/runtime/plugin-runtime/src/router/runtime/plugin.node.tsx#L150-L168
|
|
129
|
+
// According to react [useId generation algorithm](https://github.com/facebook/react/pull/22644), `useId` will generate id with the react node react struct.
|
|
130
|
+
// To void hydration failed, we must guarantee that the node tree when browser hydrate must have same struct with node tree when ssr render.
|
|
131
|
+
/* @__PURE__ */ _jsxs(_Fragment, {
|
|
132
|
+
children: [
|
|
133
|
+
/* @__PURE__ */ _jsx(RouterProvider, {
|
|
134
|
+
router
|
|
135
|
+
}),
|
|
136
|
+
/* @__PURE__ */ _jsx(Null, {}),
|
|
137
|
+
/* @__PURE__ */ _jsx(Null, {})
|
|
138
|
+
]
|
|
139
|
+
})
|
|
140
|
+
);
|
|
127
141
|
};
|
|
128
142
|
};
|
|
129
143
|
return getRouteApp();
|
|
@@ -23,7 +23,7 @@ const ssrBuilderPlugin = (modernAPI) => ({
|
|
|
23
23
|
name: "@modern-js/builder-plugin-ssr",
|
|
24
24
|
setup(api) {
|
|
25
25
|
api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig }) => {
|
|
26
|
-
const isServerEnvironment = config.output.target === "node" || name === "
|
|
26
|
+
const isServerEnvironment = config.output.target === "node" || name === "workerSSR";
|
|
27
27
|
const userConfig = modernAPI.useResolvedConfigContext();
|
|
28
28
|
const useLoadablePlugin = isUseSSRBundle(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig);
|
|
29
29
|
return mergeEnvironmentConfig(config, {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
|
|
2
1
|
import cookieTool from "cookie";
|
|
3
|
-
import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../constants";
|
|
4
2
|
import { getGlobalAppInit } from "../context";
|
|
5
3
|
import { getInitialContext } from "../context/runtime";
|
|
6
4
|
import { createLoaderManager } from "../loader/loaderManager";
|
|
@@ -59,9 +57,6 @@ async function render(App, id) {
|
|
|
59
57
|
};
|
|
60
58
|
if (isClientArgs(id)) {
|
|
61
59
|
var _ssrData_data, _ssrData_data1;
|
|
62
|
-
window._SSR_DATA = window._SSR_DATA || parsedJSONFromElement(SSR_DATA_JSON_ID);
|
|
63
|
-
const routeData = parsedJSONFromElement(ROUTER_DATA_JSON_ID);
|
|
64
|
-
window._ROUTER_DATA = window._ROUTER_DATA || routeData;
|
|
65
60
|
const ssrData = getSSRData();
|
|
66
61
|
const loadersData = (ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_data = ssrData.data) === null || _ssrData_data === void 0 ? void 0 : _ssrData_data.loadersData) || {};
|
|
67
62
|
const initialLoadersState = Object.keys(loadersData).reduce((res, key) => {
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
|
|
2
|
+
import { isBrowser } from "../../common";
|
|
3
|
+
import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../constants";
|
|
1
4
|
import { getGlobalApp } from "../context";
|
|
2
5
|
import { getGlobalRunner } from "../plugin/runner";
|
|
3
6
|
function createRoot(UserApp) {
|
|
4
7
|
const App = UserApp || getGlobalApp();
|
|
8
|
+
if (isBrowser()) {
|
|
9
|
+
window._SSR_DATA = window._SSR_DATA || parsedJSONFromElement(SSR_DATA_JSON_ID);
|
|
10
|
+
window._ROUTER_DATA = window._ROUTER_DATA || parsedJSONFromElement(ROUTER_DATA_JSON_ID);
|
|
11
|
+
}
|
|
5
12
|
const runner = getGlobalRunner();
|
|
6
13
|
const WrapperApp = runner.wrapRoot(App);
|
|
7
14
|
return WrapperApp;
|
|
@@ -69,26 +69,26 @@ const renderString = async (request, serverRoot, options) => {
|
|
|
69
69
|
});
|
|
70
70
|
};
|
|
71
71
|
async function generateHtml(App, htmlTemplate, chunkSet, collectors, htmlModifiers, { onError, onTiming }) {
|
|
72
|
-
const end = time();
|
|
73
72
|
let html = "";
|
|
74
73
|
let helmetData;
|
|
74
|
+
const finalApp = collectors.reduce((pre, creator) => {
|
|
75
|
+
var _creator_collect;
|
|
76
|
+
return ((_creator_collect = creator.collect) === null || _creator_collect === void 0 ? void 0 : _creator_collect.call(creator, pre)) || pre;
|
|
77
|
+
}, App);
|
|
75
78
|
try {
|
|
76
|
-
const
|
|
77
|
-
var _creator_collect;
|
|
78
|
-
return ((_creator_collect = creator.collect) === null || _creator_collect === void 0 ? void 0 : _creator_collect.call(creator, pre)) || pre;
|
|
79
|
-
}, App);
|
|
79
|
+
const end = time();
|
|
80
80
|
if (chunkSet.renderLevel >= RenderLevel.SERVER_PREFETCH) {
|
|
81
81
|
html = ReactDomServer.renderToString(finalApp);
|
|
82
82
|
chunkSet.renderLevel = RenderLevel.SERVER_RENDER;
|
|
83
83
|
}
|
|
84
84
|
helmetData = ReactHelmet.renderStatic();
|
|
85
|
-
await Promise.all(collectors.map((component) => component.effect()));
|
|
86
85
|
const cost = end();
|
|
87
86
|
onTiming(SSRTimings.RENDER_HTML, cost);
|
|
88
87
|
} catch (e) {
|
|
89
88
|
chunkSet.renderLevel = RenderLevel.CLIENT_RENDER;
|
|
90
89
|
onError(SSRErrors.RENDER_HTML, e);
|
|
91
90
|
}
|
|
91
|
+
await Promise.all(collectors.map((component) => component.effect()));
|
|
92
92
|
const { ssrScripts, cssChunk, jsChunk } = chunkSet;
|
|
93
93
|
const finalHtml = await buildHtml(htmlTemplate, [
|
|
94
94
|
createReplaceHtml(html),
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { fs, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger } from "@modern-js/utils";
|
|
3
|
-
import { filterRoutesForServer, filterRoutesLoader, markRoutes } from "@modern-js/utils/universal/route";
|
|
2
|
+
import { fs, filterRoutesForServer, filterRoutesLoader, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger } from "@modern-js/utils";
|
|
4
3
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
5
4
|
import { ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME } from "../../../cli/constants";
|
|
6
5
|
import { FILE_SYSTEM_ROUTES_FILE_NAME } from "../constants";
|
|
@@ -82,7 +81,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
82
81
|
})
|
|
83
82
|
});
|
|
84
83
|
if (entrypoint.nestedRoutesEntry && isUseSSRBundle(config2)) {
|
|
85
|
-
var _config_output1
|
|
84
|
+
var _config_output1;
|
|
86
85
|
const routesServerFile = getServerLoadersFile(internalDirectory, entryName);
|
|
87
86
|
const filtedRoutesForServer = filterRoutesForServer(routes);
|
|
88
87
|
const routesForServerLoaderMatches = filterRoutesLoader(routes);
|
|
@@ -101,16 +100,6 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
101
100
|
splitRouteChunks: config2 === null || config2 === void 0 ? void 0 : (_config_output1 = config2.output) === null || _config_output1 === void 0 ? void 0 : _config_output1.splitRouteChunks
|
|
102
101
|
});
|
|
103
102
|
await fs.outputFile(path.resolve(internalDirectory, `./${entryName}/routes.server.js`), serverRoutesCode, "utf8");
|
|
104
|
-
const mfServerRoutesCode = await templates.fileSystemRoutes({
|
|
105
|
-
metaName,
|
|
106
|
-
routes,
|
|
107
|
-
ssrMode: useSSG ? "string" : mode,
|
|
108
|
-
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
109
|
-
entryName: entrypoint.entryName,
|
|
110
|
-
internalDirectory,
|
|
111
|
-
splitRouteChunks: config2 === null || config2 === void 0 ? void 0 : (_config_output2 = config2.output) === null || _config_output2 === void 0 ? void 0 : _config_output2.splitRouteChunks
|
|
112
|
-
});
|
|
113
|
-
await fs.outputFile(path.resolve(internalDirectory, `./${entryName}/mf-routes.js`), mfServerRoutesCode, "utf8");
|
|
114
103
|
}
|
|
115
104
|
const serverLoaderCombined = templates.ssrLoaderCombinedModule(entrypoints, entrypoint, config2, appContext);
|
|
116
105
|
if (serverLoaderCombined) {
|
|
@@ -122,6 +111,25 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
122
111
|
}
|
|
123
112
|
}
|
|
124
113
|
};
|
|
114
|
+
function markRoutes(routes, routeIds) {
|
|
115
|
+
return routes.map((route) => {
|
|
116
|
+
if (route.type !== "nested") {
|
|
117
|
+
return route;
|
|
118
|
+
}
|
|
119
|
+
if (route.children && route.children.length > 0) {
|
|
120
|
+
route.children = markRoutes(route.children, routeIds);
|
|
121
|
+
}
|
|
122
|
+
if (route.children && route.children.length > 0) {
|
|
123
|
+
route.inValidSSRRoute = route.children.every((child) => {
|
|
124
|
+
var _child_inValidSSRRoute;
|
|
125
|
+
return (_child_inValidSSRRoute = child.inValidSSRRoute) !== null && _child_inValidSSRRoute !== void 0 ? _child_inValidSSRRoute : false;
|
|
126
|
+
});
|
|
127
|
+
} else if (route.id) {
|
|
128
|
+
route.inValidSSRRoute = !routeIds.includes(route.id);
|
|
129
|
+
}
|
|
130
|
+
return route;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
125
133
|
function generatorRegisterCode(internalDirectory, entryName, code) {
|
|
126
134
|
fs.outputFileSync(path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME}`), code, "utf8");
|
|
127
135
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import { fs, NESTED_ROUTE_SPEC_FILE, createRuntimeExportsUtils, getEntryOptions, isRouterV5 as isV5 } from "@modern-js/utils";
|
|
3
|
-
import { filterRoutesForServer } from "@modern-js/utils/universal/route";
|
|
2
|
+
import { fs, NESTED_ROUTE_SPEC_FILE, createRuntimeExportsUtils, filterRoutesForServer, getEntryOptions, isRouterV5 as isV5 } from "@modern-js/utils";
|
|
4
3
|
import { isRouteEntry } from "./entry";
|
|
5
4
|
import { handleFileChange, handleGeneratorEntryCode, handleModifyEntrypoints } from "./handler";
|
|
6
5
|
import { isRouteEntry as isRouteEntry2 } from "./entry";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { merge } from "@modern-js/runtime-utils/merge";
|
|
3
3
|
import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
|
|
4
4
|
import { RouterProvider, createBrowserRouter, createHashRouter, createRoutesFromElements, useHref, useLocation, useMatches } from "@modern-js/runtime-utils/router";
|
|
@@ -109,12 +109,24 @@ const routerPlugin = (userConfig = {}) => {
|
|
|
109
109
|
getBlockNavState
|
|
110
110
|
]);
|
|
111
111
|
};
|
|
112
|
+
const Null = () => null;
|
|
112
113
|
return (props) => {
|
|
113
114
|
beforeCreateRouter = false;
|
|
114
115
|
const router = useCreateRouter(props);
|
|
115
|
-
return
|
|
116
|
-
router
|
|
117
|
-
|
|
116
|
+
return (
|
|
117
|
+
// To match the node tree about https://github.com/web-infra-dev/modern.js/blob/v2.59.0/packages/runtime/plugin-runtime/src/router/runtime/plugin.node.tsx#L150-L168
|
|
118
|
+
// According to react [useId generation algorithm](https://github.com/facebook/react/pull/22644), `useId` will generate id with the react node react struct.
|
|
119
|
+
// To void hydration failed, we must guarantee that the node tree when browser hydrate must have same struct with node tree when ssr render.
|
|
120
|
+
/* @__PURE__ */ _jsxs(_Fragment, {
|
|
121
|
+
children: [
|
|
122
|
+
/* @__PURE__ */ _jsx(RouterProvider, {
|
|
123
|
+
router
|
|
124
|
+
}),
|
|
125
|
+
/* @__PURE__ */ _jsx(Null, {}),
|
|
126
|
+
/* @__PURE__ */ _jsx(Null, {})
|
|
127
|
+
]
|
|
128
|
+
})
|
|
129
|
+
);
|
|
118
130
|
};
|
|
119
131
|
};
|
|
120
132
|
return getRouteApp();
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { useLocation, useNavigate } from '@modern-js/runtime-utils/router';
|
|
2
2
|
import type React from 'react';
|
|
3
|
-
export interface WithRouterProps {
|
|
3
|
+
export interface WithRouterProps<Params extends {
|
|
4
|
+
[K in keyof Params]?: string;
|
|
5
|
+
} = {}> {
|
|
4
6
|
location: ReturnType<typeof useLocation>;
|
|
5
|
-
params:
|
|
7
|
+
params: Params;
|
|
6
8
|
navigate: ReturnType<typeof useNavigate>;
|
|
7
9
|
}
|
|
8
|
-
export declare const withRouter: <Props extends WithRouterProps
|
|
10
|
+
export declare const withRouter: <Props extends WithRouterProps<{}>>(Component: React.ComponentType<Props>) => (props: Omit<Props, keyof WithRouterProps<{}>>) => JSX.Element;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.60.0",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14.17.6"
|
|
21
21
|
},
|
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
"@modern-js-reduck/plugin-immutable": "^1.1.10",
|
|
187
187
|
"@modern-js-reduck/react": "^1.1.10",
|
|
188
188
|
"@modern-js-reduck/store": "^1.1.10",
|
|
189
|
-
"@swc/helpers": "0.5.
|
|
189
|
+
"@swc/helpers": "0.5.13",
|
|
190
190
|
"@types/loadable__component": "^5.13.4",
|
|
191
191
|
"@types/react-helmet": "^6.1.2",
|
|
192
192
|
"@types/styled-components": "^5.1.14",
|
|
@@ -199,11 +199,11 @@
|
|
|
199
199
|
"react-is": "^18",
|
|
200
200
|
"react-side-effect": "^2.1.1",
|
|
201
201
|
"styled-components": "^5.3.1",
|
|
202
|
-
"@modern-js/plugin": "2.
|
|
203
|
-
"@modern-js/
|
|
204
|
-
"@modern-js/
|
|
205
|
-
"@modern-js/
|
|
206
|
-
"@modern-js/
|
|
202
|
+
"@modern-js/plugin": "2.60.0",
|
|
203
|
+
"@modern-js/runtime-utils": "2.60.0",
|
|
204
|
+
"@modern-js/types": "2.60.0",
|
|
205
|
+
"@modern-js/utils": "2.60.0",
|
|
206
|
+
"@modern-js/plugin-data-loader": "2.60.0"
|
|
207
207
|
},
|
|
208
208
|
"peerDependencies": {
|
|
209
209
|
"react": ">=17",
|
|
@@ -211,7 +211,7 @@
|
|
|
211
211
|
},
|
|
212
212
|
"devDependencies": {
|
|
213
213
|
"@remix-run/web-fetch": "^4.1.3",
|
|
214
|
-
"@rsbuild/core": "1.0.
|
|
214
|
+
"@rsbuild/core": "1.0.2",
|
|
215
215
|
"@testing-library/react": "^13.4.0",
|
|
216
216
|
"@types/cookie": "0.5.1",
|
|
217
217
|
"@types/invariant": "^2.2.30",
|
|
@@ -225,11 +225,11 @@
|
|
|
225
225
|
"react-dom": "^18",
|
|
226
226
|
"ts-jest": "^29.1.0",
|
|
227
227
|
"typescript": "^5",
|
|
228
|
-
"webpack": "^5.
|
|
229
|
-
"@modern-js/
|
|
230
|
-
"@modern-js/
|
|
231
|
-
"@scripts/
|
|
232
|
-
"@scripts/
|
|
228
|
+
"webpack": "^5.94.0",
|
|
229
|
+
"@modern-js/core": "2.60.0",
|
|
230
|
+
"@modern-js/app-tools": "2.60.0",
|
|
231
|
+
"@scripts/build": "2.60.0",
|
|
232
|
+
"@scripts/jest-config": "2.60.0"
|
|
233
233
|
},
|
|
234
234
|
"sideEffects": false,
|
|
235
235
|
"publishConfig": {
|