@modern-js/runtime 2.56.2 → 2.57.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/index.js +5 -1
- package/dist/cjs/core/browser/hydrate.js +3 -1
- package/dist/cjs/core/browser/index.js +8 -9
- package/dist/cjs/core/compatible.js +28 -48
- package/dist/cjs/core/plugin/base.js +20 -9
- package/dist/cjs/core/plugin/index.js +8 -2
- package/dist/cjs/core/react/index.js +11 -18
- package/dist/cjs/core/server/requestHandler.js +10 -10
- package/dist/cjs/core/server/stream/shared.js +2 -2
- package/dist/cjs/core/server/string/index.js +3 -2
- package/dist/cjs/core/server/utils.js +2 -5
- package/dist/cjs/router/cli/code/index.js +40 -4
- package/dist/cjs/router/cli/code/templates.js +13 -8
- package/dist/cjs/router/cli/index.js +32 -3
- package/dist/cjs/router/runtime/plugin.js +29 -40
- package/dist/cjs/router/runtime/plugin.node.js +27 -38
- package/dist/cjs/state/runtime/plugin.js +10 -21
- package/dist/esm/cli/index.js +10 -11
- package/dist/esm/core/browser/hydrate.js +3 -1
- package/dist/esm/core/browser/index.js +28 -13
- package/dist/esm/core/compatible.js +47 -56
- package/dist/esm/core/plugin/base.js +20 -9
- package/dist/esm/core/plugin/index.js +12 -3
- package/dist/esm/core/react/index.js +12 -20
- package/dist/esm/core/server/requestHandler.js +33 -14
- package/dist/esm/core/server/stream/shared.js +3 -3
- package/dist/esm/core/server/string/index.js +4 -3
- package/dist/esm/core/server/utils.js +2 -5
- package/dist/esm/router/cli/code/index.js +66 -16
- package/dist/esm/router/cli/code/templates.js +13 -8
- package/dist/esm/router/cli/index.js +48 -4
- package/dist/esm/router/runtime/plugin.js +32 -47
- package/dist/esm/router/runtime/plugin.node.js +27 -42
- package/dist/esm/state/runtime/plugin.js +11 -24
- package/dist/esm-node/cli/index.js +5 -1
- package/dist/esm-node/core/browser/hydrate.js +3 -1
- package/dist/esm-node/core/browser/index.js +8 -9
- package/dist/esm-node/core/compatible.js +28 -48
- package/dist/esm-node/core/plugin/base.js +18 -9
- package/dist/esm-node/core/plugin/index.js +10 -4
- package/dist/esm-node/core/react/index.js +11 -18
- package/dist/esm-node/core/server/requestHandler.js +10 -10
- package/dist/esm-node/core/server/stream/shared.js +2 -2
- package/dist/esm-node/core/server/string/index.js +3 -2
- package/dist/esm-node/core/server/utils.js +2 -5
- package/dist/esm-node/router/cli/code/index.js +41 -5
- package/dist/esm-node/router/cli/code/templates.js +13 -8
- package/dist/esm-node/router/cli/index.js +23 -4
- package/dist/esm-node/router/runtime/plugin.js +29 -40
- package/dist/esm-node/router/runtime/plugin.node.js +27 -38
- package/dist/esm-node/state/runtime/plugin.js +10 -21
- package/dist/types/core/compatible.d.ts +1 -1
- package/dist/types/core/context/index.d.ts +1 -1
- package/dist/types/core/context/runtime.d.ts +1 -1
- package/dist/types/core/plugin/base.d.ts +26 -36
- package/dist/types/core/plugin/index.d.ts +5 -12
- package/dist/types/core/plugin/runner.d.ts +4 -11
- package/dist/types/core/react/index.d.ts +1 -5
- package/dist/types/core/server/utils.d.ts +1 -1
- package/dist/types/router/cli/code/templates.d.ts +2 -2
- package/dist/types/router/runtime/plugin.d.ts +1 -1
- package/dist/types/router/runtime/plugin.node.d.ts +1 -1
- package/dist/types/state/runtime/plugin.d.ts +1 -1
- package/package.json +10 -10
- package/dist/cjs/core/utils/merge.js +0 -53
- package/dist/esm/core/utils/merge.js +0 -32
- package/dist/esm-node/core/utils/merge.js +0 -29
- package/dist/types/core/utils/merge.d.ts +0 -6
package/dist/cjs/cli/index.js
CHANGED
|
@@ -124,7 +124,11 @@ const runtimePlugin = (params) => ({
|
|
|
124
124
|
/**
|
|
125
125
|
* Compatible with the reference path of the old version of the plugin.
|
|
126
126
|
*/
|
|
127
|
-
[`@${metaName}/runtime/plugins`]: pluginsExportsUtils.getPath()
|
|
127
|
+
[`@${metaName}/runtime/plugins`]: pluginsExportsUtils.getPath(),
|
|
128
|
+
"@meta/runtime/browser": "@modern-js/runtime/browser",
|
|
129
|
+
"@meta/runtime/react": "@modern-js/runtime/react",
|
|
130
|
+
"@meta/runtime/context": "@modern-js/runtime/context",
|
|
131
|
+
"@meta/runtime": "@modern-js/runtime"
|
|
128
132
|
},
|
|
129
133
|
globalVars: {
|
|
130
134
|
"process.env.IS_REACT18": process.env.IS_REACT18
|
|
@@ -97,7 +97,9 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
97
97
|
});
|
|
98
98
|
} else {
|
|
99
99
|
(0, import_component.loadableReady)(() => {
|
|
100
|
-
ModernHydrate(
|
|
100
|
+
ModernHydrate(/* @__PURE__ */ import_react.default.cloneElement(App, {
|
|
101
|
+
_internal_context: hydrateContext
|
|
102
|
+
}), callback).then((root) => {
|
|
101
103
|
resolve(root);
|
|
102
104
|
});
|
|
103
105
|
});
|
|
@@ -64,14 +64,11 @@ function isClientArgs(id) {
|
|
|
64
64
|
async function render(App, id) {
|
|
65
65
|
const runner = (0, import_runner.getGlobalRunner)();
|
|
66
66
|
const context = (0, import_runtime.getInitialContext)(runner);
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return init === null || init === void 0 ? void 0 : init(context1);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
67
|
+
const runBeforeRender = async (context2) => {
|
|
68
|
+
await runner.beforeRender(context2);
|
|
69
|
+
const init = (0, import_context.getGlobalAppInit)();
|
|
70
|
+
return init === null || init === void 0 ? void 0 : init(context2);
|
|
71
|
+
};
|
|
75
72
|
if (isClientArgs(id)) {
|
|
76
73
|
var _ssrData_data, _ssrData_data1;
|
|
77
74
|
const ssrData = getSSRData();
|
|
@@ -88,12 +85,14 @@ async function render(App, id) {
|
|
|
88
85
|
loaderManager: (0, import_loaderManager.createLoaderManager)(initialLoadersState, {
|
|
89
86
|
skipStatic: true
|
|
90
87
|
}),
|
|
88
|
+
// garfish plugin params
|
|
89
|
+
_internalRouterBaseName: App.props.basename,
|
|
91
90
|
...ssrData ? {
|
|
92
91
|
ssrContext: ssrData === null || ssrData === void 0 ? void 0 : ssrData.context
|
|
93
92
|
} : {}
|
|
94
93
|
});
|
|
95
94
|
context.initialData = ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_data1 = ssrData.data) === null || _ssrData_data1 === void 0 ? void 0 : _ssrData_data1.initialData;
|
|
96
|
-
const initialData = await
|
|
95
|
+
const initialData = await runBeforeRender(context);
|
|
97
96
|
if (initialData) {
|
|
98
97
|
context.initialData = initialData;
|
|
99
98
|
}
|
|
@@ -65,53 +65,38 @@ const createApp = ({ plugins, runtime, props: globalProps }) => {
|
|
|
65
65
|
...props
|
|
66
66
|
}) : child));
|
|
67
67
|
};
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
contextValue = getInitialContext(runner);
|
|
77
|
-
runner.init({
|
|
78
|
-
context: contextValue
|
|
79
|
-
}, {
|
|
80
|
-
onLast: ({ context: context1 }) => {
|
|
81
|
-
var _getGlobalAppInit;
|
|
82
|
-
return (_getGlobalAppInit = (0, import_context.getGlobalAppInit)()) === null || _getGlobalAppInit === void 0 ? void 0 : _getGlobalAppInit(context1);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
const mergedProps = {
|
|
87
|
-
...props,
|
|
88
|
-
...globalProps
|
|
89
|
-
};
|
|
90
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_runtime.RuntimeReactContext.Provider, {
|
|
91
|
-
value: contextValue,
|
|
92
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App2, {
|
|
93
|
-
...mergedProps
|
|
94
|
-
})
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
return WrapComponent;
|
|
68
|
+
const WrapperApp = runner.wrapRoot(WrapperComponent);
|
|
69
|
+
const WrapComponent = ({ _internal_context, ...props }) => {
|
|
70
|
+
let contextValue = _internal_context;
|
|
71
|
+
if (!(contextValue === null || contextValue === void 0 ? void 0 : contextValue.runner)) {
|
|
72
|
+
var _getGlobalAppInit;
|
|
73
|
+
contextValue = getInitialContext(runner);
|
|
74
|
+
runner === null || runner === void 0 ? void 0 : runner.beforeRender(contextValue);
|
|
75
|
+
(_getGlobalAppInit = (0, import_context.getGlobalAppInit)()) === null || _getGlobalAppInit === void 0 ? void 0 : _getGlobalAppInit(contextValue);
|
|
98
76
|
}
|
|
99
|
-
|
|
100
|
-
|
|
77
|
+
const mergedProps = {
|
|
78
|
+
...props,
|
|
79
|
+
...globalProps
|
|
80
|
+
};
|
|
81
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_runtime.RuntimeReactContext.Provider, {
|
|
82
|
+
value: contextValue,
|
|
83
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WrapperApp, {
|
|
84
|
+
...mergedProps
|
|
85
|
+
})
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
return WrapComponent;
|
|
101
89
|
};
|
|
102
90
|
};
|
|
103
91
|
const bootstrap = async (BootApp, id, root, ReactDOM) => {
|
|
104
92
|
const App = BootApp;
|
|
105
93
|
const runner = (0, import_runner.getGlobalRunner)();
|
|
106
94
|
const context = getInitialContext(runner);
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return init === null || init === void 0 ? void 0 : init(context1);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
95
|
+
const runBeforeRender = async (context2) => {
|
|
96
|
+
await runner.beforeRender(context2);
|
|
97
|
+
const init = (0, import_context.getGlobalAppInit)();
|
|
98
|
+
return init === null || init === void 0 ? void 0 : init(context2);
|
|
99
|
+
};
|
|
115
100
|
if (!id) {
|
|
116
101
|
return /* @__PURE__ */ import_react.default.createElement(App, {
|
|
117
102
|
_internal_context: context
|
|
@@ -140,7 +125,7 @@ const bootstrap = async (BootApp, id, root, ReactDOM) => {
|
|
|
140
125
|
} : {}
|
|
141
126
|
});
|
|
142
127
|
context.initialData = ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_data1 = ssrData.data) === null || _ssrData_data1 === void 0 ? void 0 : _ssrData_data1.initialData;
|
|
143
|
-
const initialData = await
|
|
128
|
+
const initialData = await runBeforeRender(context);
|
|
144
129
|
if (initialData) {
|
|
145
130
|
context.initialData = initialData;
|
|
146
131
|
}
|
|
@@ -200,16 +185,11 @@ const useRuntimeContext = () => {
|
|
|
200
185
|
var _context_ssrContext, _context_ssrContext1;
|
|
201
186
|
const context = (0, import_react.useContext)(import_runtime.RuntimeReactContext);
|
|
202
187
|
const pickedContext = {
|
|
203
|
-
|
|
188
|
+
...context,
|
|
204
189
|
request: (_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.request,
|
|
205
190
|
response: (_context_ssrContext1 = context.ssrContext) === null || _context_ssrContext1 === void 0 ? void 0 : _context_ssrContext1.response
|
|
206
191
|
};
|
|
207
|
-
const memoizedContext = (0, import_react.useMemo)(() => context.runner.pickContext(
|
|
208
|
-
context,
|
|
209
|
-
pickedContext
|
|
210
|
-
}, {
|
|
211
|
-
onLast: ({ pickedContext: pickedContext2 }) => pickedContext2
|
|
212
|
-
}), [
|
|
192
|
+
const memoizedContext = (0, import_react.useMemo)(() => context.runner.pickContext(pickedContext), [
|
|
213
193
|
context
|
|
214
194
|
]);
|
|
215
195
|
return memoizedContext;
|
|
@@ -18,23 +18,34 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var base_exports = {};
|
|
20
20
|
__export(base_exports, {
|
|
21
|
+
RuntimeConfigContext: () => RuntimeConfigContext,
|
|
21
22
|
createRuntime: () => createRuntime,
|
|
22
|
-
runtime: () => runtime
|
|
23
|
+
runtime: () => runtime,
|
|
24
|
+
useRuntimeConfigContext: () => useRuntimeConfigContext
|
|
23
25
|
});
|
|
24
26
|
module.exports = __toCommonJS(base_exports);
|
|
25
27
|
var import_plugin = require("@modern-js/plugin");
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
28
|
+
const RuntimeConfigContext = (0, import_plugin.createContext)({});
|
|
29
|
+
const useRuntimeConfigContext = () => RuntimeConfigContext.use().value;
|
|
30
|
+
const wrapRoot = (0, import_plugin.createWaterfall)();
|
|
31
|
+
const beforeRender = (0, import_plugin.createAsyncInterruptWorkflow)();
|
|
32
|
+
const pickContext = (0, import_plugin.createWaterfall)();
|
|
33
|
+
const modifyRuntimeConfig = (0, import_plugin.createSyncParallelWorkflow)();
|
|
29
34
|
const runtimeHooks = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
pickContext
|
|
35
|
+
beforeRender,
|
|
36
|
+
wrapRoot,
|
|
37
|
+
pickContext,
|
|
38
|
+
modifyRuntimeConfig
|
|
33
39
|
};
|
|
34
|
-
const
|
|
40
|
+
const runtimePluginAPI = {
|
|
41
|
+
useRuntimeConfigContext
|
|
42
|
+
};
|
|
43
|
+
const createRuntime = () => (0, import_plugin.createManager)(runtimeHooks, runtimePluginAPI);
|
|
35
44
|
const runtime = createRuntime();
|
|
36
45
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
46
|
0 && (module.exports = {
|
|
47
|
+
RuntimeConfigContext,
|
|
38
48
|
createRuntime,
|
|
39
|
-
runtime
|
|
49
|
+
runtime,
|
|
50
|
+
useRuntimeConfigContext
|
|
40
51
|
});
|
|
@@ -23,19 +23,25 @@ __export(plugin_exports, {
|
|
|
23
23
|
registerPlugin: () => registerPlugin
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(plugin_exports);
|
|
26
|
-
var import_merge = require("
|
|
26
|
+
var import_merge = require("@modern-js/runtime-utils/merge");
|
|
27
27
|
var import_base = require("./base");
|
|
28
28
|
var import_runner = require("./runner");
|
|
29
29
|
__reExport(plugin_exports, require("./base"), module.exports);
|
|
30
|
+
function setupConfigContext() {
|
|
31
|
+
const runner = (0, import_runner.getGlobalRunner)();
|
|
32
|
+
const configs = runner.modifyRuntimeConfig();
|
|
33
|
+
import_base.RuntimeConfigContext.set((0, import_merge.merge)({}, ...configs));
|
|
34
|
+
}
|
|
30
35
|
function registerPlugin(internalPlugins, runtimeConfig, customRuntime) {
|
|
31
36
|
const { plugins = [] } = runtimeConfig || {};
|
|
32
37
|
(customRuntime || import_base.runtime).usePlugin(...internalPlugins, ...plugins);
|
|
33
38
|
const runner = (customRuntime || import_base.runtime).init();
|
|
34
39
|
(0, import_runner.setGlobalRunner)(runner);
|
|
40
|
+
setupConfigContext();
|
|
35
41
|
return runner;
|
|
36
42
|
}
|
|
37
43
|
function mergeConfig(config, ...otherConfig) {
|
|
38
|
-
return (0, import_merge.merge)(config, ...otherConfig);
|
|
44
|
+
return (0, import_merge.merge)({}, config, ...otherConfig);
|
|
39
45
|
}
|
|
40
46
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
47
|
0 && (module.exports = {
|
|
@@ -24,26 +24,19 @@ module.exports = __toCommonJS(react_exports);
|
|
|
24
24
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
25
|
var import_context = require("../context");
|
|
26
26
|
var import_runner = require("../plugin/runner");
|
|
27
|
-
function createRoot(UserApp
|
|
27
|
+
function createRoot(UserApp) {
|
|
28
28
|
const App = UserApp || (0, import_context.getGlobalApp)();
|
|
29
29
|
const runner = (0, import_runner.getGlobalRunner)();
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
})
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
return WrapComponent;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
return HOCApp;
|
|
30
|
+
const WrapperApp = runner.wrapRoot(App);
|
|
31
|
+
const WrapComponent = ({ _internal_context, ...props }) => {
|
|
32
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_context.RuntimeReactContext.Provider, {
|
|
33
|
+
value: _internal_context,
|
|
34
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WrapperApp, {
|
|
35
|
+
...props
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
return WrapComponent;
|
|
47
40
|
}
|
|
48
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
49
42
|
0 && (module.exports = {
|
|
@@ -30,7 +30,7 @@ var import_loaderManager = require("../loader/loaderManager");
|
|
|
30
30
|
var import_utils = require("./utils");
|
|
31
31
|
var import_constants = require("./constants");
|
|
32
32
|
function createSSRContext(request, options) {
|
|
33
|
-
const { config, loaderContext, onError, onTiming, locals, resource, params, responseProxy,
|
|
33
|
+
const { config, loaderContext, onError, onTiming, locals, resource, params, responseProxy, logger, metrics, reporter } = options;
|
|
34
34
|
const { nonce } = config;
|
|
35
35
|
const { entryName, route } = resource;
|
|
36
36
|
const cookie = request.headers.get("cookie");
|
|
@@ -39,7 +39,7 @@ function createSSRContext(request, options) {
|
|
|
39
39
|
const query = (0, import_request.parseQuery)(request);
|
|
40
40
|
const headersData = (0, import_request.parseHeaders)(request);
|
|
41
41
|
const url = new URL(request.url);
|
|
42
|
-
const ssrConfig = (0, import_utils.getSSRConfigByEntry)(entryName, config.ssr, config.ssrByEntries
|
|
42
|
+
const ssrConfig = (0, import_utils.getSSRConfigByEntry)(entryName, config.ssr, config.ssrByEntries);
|
|
43
43
|
const ssrMode = (0, import_utils.getSSRMode)(ssrConfig);
|
|
44
44
|
const loaderFailureMode = typeof ssrConfig === "object" ? ssrConfig.loaderFailureMode : void 0;
|
|
45
45
|
return {
|
|
@@ -83,14 +83,14 @@ const createRequestHandler = async (handleRequest) => {
|
|
|
83
83
|
const runner = (0, import_runner.getGlobalRunner)();
|
|
84
84
|
const { routeManifest } = options.resource;
|
|
85
85
|
const context = (0, import_runtime.getInitialContext)(runner, false, routeManifest);
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const init = (0, import_context.getGlobalAppInit)();
|
|
91
|
-
return init === null || init === void 0 ? void 0 : init(context1);
|
|
86
|
+
const runBeforeRender = async (context2) => {
|
|
87
|
+
const result = await runner.beforeRender(context2);
|
|
88
|
+
if (typeof Response !== "undefined" && result instanceof Response) {
|
|
89
|
+
return result;
|
|
92
90
|
}
|
|
93
|
-
|
|
91
|
+
const init = (0, import_context.getGlobalAppInit)();
|
|
92
|
+
return init === null || init === void 0 ? void 0 : init(context2);
|
|
93
|
+
};
|
|
94
94
|
const responseProxy = {
|
|
95
95
|
headers: {},
|
|
96
96
|
code: -1
|
|
@@ -125,7 +125,7 @@ const createRequestHandler = async (handleRequest) => {
|
|
|
125
125
|
}
|
|
126
126
|
return void 0;
|
|
127
127
|
};
|
|
128
|
-
const initialData = await
|
|
128
|
+
const initialData = await runBeforeRender(context);
|
|
129
129
|
context.initialData = initialData;
|
|
130
130
|
const redirectResponse = getRedirectResponse(initialData);
|
|
131
131
|
if (redirectResponse) {
|
|
@@ -69,11 +69,11 @@ function createRenderStreaming(createReadableStreamFromElement) {
|
|
|
69
69
|
const headersData = (0, import_request.parseHeaders)(request);
|
|
70
70
|
return (0, import_node.run)(headersData, async () => {
|
|
71
71
|
const end = (0, import_time.time)();
|
|
72
|
-
const { runtimeContext, config, resource
|
|
72
|
+
const { runtimeContext, config, resource } = options;
|
|
73
73
|
const onError = (0, import_tracer.createOnError)(options.onError);
|
|
74
74
|
const onTiming = (0, import_tracer.createOnTiming)(options.onTiming);
|
|
75
75
|
const { htmlTemplate, entryName } = resource;
|
|
76
|
-
const ssrConfig = (0, import_utils.getSSRConfigByEntry)(entryName, config.ssr, config.ssrByEntries
|
|
76
|
+
const ssrConfig = (0, import_utils.getSSRConfigByEntry)(entryName, config.ssr, config.ssrByEntries);
|
|
77
77
|
const rootElement = import_react.default.cloneElement(serverRoot, {
|
|
78
78
|
_internal_context: Object.assign(runtimeContext, {
|
|
79
79
|
ssr: true
|
|
@@ -51,14 +51,14 @@ const renderString = async (request, serverRoot, options) => {
|
|
|
51
51
|
const headersData = (0, import_request.parseHeaders)(request);
|
|
52
52
|
return (0, import_node.run)(headersData, async () => {
|
|
53
53
|
var _runtimeContext_ssrContext;
|
|
54
|
-
const { resource, runtimeContext, config, onError, onTiming
|
|
54
|
+
const { resource, runtimeContext, config, onError, onTiming } = options;
|
|
55
55
|
const tracer = {
|
|
56
56
|
onError: (0, import_tracer.createOnError)(onError),
|
|
57
57
|
onTiming: (0, import_tracer.createOnTiming)(onTiming)
|
|
58
58
|
};
|
|
59
59
|
const routerContext = runtimeContext.routerContext;
|
|
60
60
|
const { htmlTemplate, entryName, loadableStats, routeManifest } = resource;
|
|
61
|
-
const ssrConfig = (0, import_utils.getSSRConfigByEntry)(entryName, config.ssr, config.ssrByEntries
|
|
61
|
+
const ssrConfig = (0, import_utils.getSSRConfigByEntry)(entryName, config.ssr, config.ssrByEntries);
|
|
62
62
|
const chunkSet = {
|
|
63
63
|
renderLevel: import_constants2.RenderLevel.CLIENT_RENDER,
|
|
64
64
|
ssrScripts: "",
|
|
@@ -71,6 +71,7 @@ const renderString = async (request, serverRoot, options) => {
|
|
|
71
71
|
chunkSet.renderLevel = import_constants2.RenderLevel.SERVER_PREFETCH;
|
|
72
72
|
} catch (e) {
|
|
73
73
|
chunkSet.renderLevel = import_constants2.RenderLevel.CLIENT_RENDER;
|
|
74
|
+
tracer.onError(import_tracer.SSRErrors.PRERENDER, e);
|
|
74
75
|
}
|
|
75
76
|
const collectors = [
|
|
76
77
|
new import_styledComponent.StyledCollector(chunkSet),
|
|
@@ -63,14 +63,11 @@ function serializeErrors(errors) {
|
|
|
63
63
|
}
|
|
64
64
|
return serialized;
|
|
65
65
|
}
|
|
66
|
-
function getSSRConfigByEntry(entryName, ssr, ssrByEntries
|
|
67
|
-
if (staticGenerate) {
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
66
|
+
function getSSRConfigByEntry(entryName, ssr, ssrByEntries) {
|
|
70
67
|
if (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[entryName]) {
|
|
71
68
|
return ssrByEntries[entryName];
|
|
72
69
|
}
|
|
73
|
-
return ssr;
|
|
70
|
+
return ssr || true;
|
|
74
71
|
}
|
|
75
72
|
function getSSRMode(ssrConfig) {
|
|
76
73
|
if (typeof ssrConfig === "boolean") {
|
|
@@ -34,6 +34,7 @@ __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_lodash = require("@modern-js/utils/lodash");
|
|
37
38
|
var import_constants = require("../constants");
|
|
38
39
|
var import_constants2 = require("../../../cli/constants");
|
|
39
40
|
var templates = __toESM(require("./templates"));
|
|
@@ -80,11 +81,14 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
}
|
|
84
|
+
const config2 = api.useResolvedConfigContext();
|
|
85
|
+
const ssrByRouteIds = config2.server.ssrByRouteIds || [];
|
|
86
|
+
const clonedRoutes = (0, import_lodash.cloneDeep)(initialRoutes);
|
|
87
|
+
const markedRoutes = ssrByRouteIds.length > 0 ? markRoutes(clonedRoutes, ssrByRouteIds) : initialRoutes;
|
|
83
88
|
const { routes } = await hookRunners.modifyFileSystemRoutes({
|
|
84
89
|
entrypoint,
|
|
85
|
-
routes:
|
|
90
|
+
routes: markedRoutes
|
|
86
91
|
});
|
|
87
|
-
const config2 = api.useResolvedConfigContext();
|
|
88
92
|
const ssr = (0, import_utils.getEntryOptions)(entryName, isMainEntry, config2.server.ssr, config2.server.ssrByEntries, packageName);
|
|
89
93
|
const useSSG = (0, import_utils.isSSGEntry)(config2, entryName, entrypoints);
|
|
90
94
|
let mode;
|
|
@@ -111,23 +115,55 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
111
115
|
})
|
|
112
116
|
});
|
|
113
117
|
if (entrypoint.nestedRoutesEntry && (0, import_utils.isUseSSRBundle)(config2)) {
|
|
118
|
+
var _config_output1;
|
|
114
119
|
const routesServerFile = (0, import_utils2.getServerLoadersFile)(internalDirectory, entryName);
|
|
120
|
+
const filtedRoutesForServer = (0, import_utils.filterRoutesForServer)(routes);
|
|
121
|
+
const routesForServerLoaderMatches = (0, import_utils.filterRoutesLoader)(routes);
|
|
115
122
|
const code2 = templates.routesForServer({
|
|
116
|
-
|
|
123
|
+
routesForServerLoaderMatches
|
|
117
124
|
});
|
|
118
125
|
await import_utils.fs.ensureFile(routesServerFile);
|
|
119
126
|
await import_utils.fs.writeFile(routesServerFile, code2);
|
|
127
|
+
const serverRoutesCode = await templates.fileSystemRoutes({
|
|
128
|
+
metaName,
|
|
129
|
+
routes: filtedRoutesForServer,
|
|
130
|
+
ssrMode: useSSG ? "string" : mode,
|
|
131
|
+
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
132
|
+
entryName: entrypoint.entryName,
|
|
133
|
+
internalDirectory,
|
|
134
|
+
splitRouteChunks: config2 === null || config2 === void 0 ? void 0 : (_config_output1 = config2.output) === null || _config_output1 === void 0 ? void 0 : _config_output1.splitRouteChunks
|
|
135
|
+
});
|
|
136
|
+
await import_utils.fs.outputFile(import_path.default.resolve(internalDirectory, `./${entryName}/routes.server.js`), serverRoutesCode, "utf8");
|
|
120
137
|
}
|
|
121
138
|
const serverLoaderCombined = templates.ssrLoaderCombinedModule(entrypoints, entrypoint, config2, appContext);
|
|
122
139
|
if (serverLoaderCombined) {
|
|
123
140
|
const serverLoaderFile = (0, import_utils2.getServerCombinedModueFile)(internalDirectory, entryName);
|
|
124
141
|
await import_utils.fs.outputFile(serverLoaderFile, serverLoaderCombined);
|
|
125
142
|
}
|
|
126
|
-
import_utils.fs.
|
|
143
|
+
await import_utils.fs.outputFile(import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.FILE_SYSTEM_ROUTES_FILE_NAME}`), code, "utf8");
|
|
127
144
|
}
|
|
128
145
|
}
|
|
129
146
|
}
|
|
130
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
|
+
}
|
|
131
167
|
function generatorRegisterCode(internalDirectory, entryName, code) {
|
|
132
168
|
import_utils.fs.outputFileSync(import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants2.ENTRY_POINT_RUNTIME_GLOBAL_CONTEXT_FILE_NAME}`), code, "utf8");
|
|
133
169
|
}
|
|
@@ -39,7 +39,7 @@ var import_utils = require("@modern-js/utils");
|
|
|
39
39
|
var import_constants = require("@modern-js/utils/universal/constants");
|
|
40
40
|
var import_constants2 = require("../constants");
|
|
41
41
|
var import_utils2 = require("./utils");
|
|
42
|
-
const routesForServer = ({
|
|
42
|
+
const routesForServer = ({ routesForServerLoaderMatches }) => {
|
|
43
43
|
const loaders = [];
|
|
44
44
|
const actions = [];
|
|
45
45
|
const loadersMap = {};
|
|
@@ -82,7 +82,7 @@ const routesForServer = ({ routes }) => {
|
|
|
82
82
|
let routesCode = `
|
|
83
83
|
export const routes = [
|
|
84
84
|
`;
|
|
85
|
-
for (const route of
|
|
85
|
+
for (const route of routesForServerLoaderMatches) {
|
|
86
86
|
if ("type" in route) {
|
|
87
87
|
const keywords = [
|
|
88
88
|
"loader",
|
|
@@ -135,13 +135,14 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
|
|
|
135
135
|
import loadable, { lazy as loadableLazy } from "@${metaName}/runtime/loadable"
|
|
136
136
|
`;
|
|
137
137
|
let rootLayoutCode = ``;
|
|
138
|
-
const getDataLoaderPath = ({ loaderId, clientData, action, inline, routeId }) => {
|
|
138
|
+
const getDataLoaderPath = ({ loaderId, clientData, action, inline, routeId, inValidSSRRoute }) => {
|
|
139
139
|
if (!ssrMode) {
|
|
140
140
|
return "";
|
|
141
141
|
}
|
|
142
142
|
const clientDataStr = clientData ? `&clientData=${clientData}` : "";
|
|
143
|
+
const retain = inValidSSRRoute !== null && inValidSSRRoute !== void 0 ? inValidSSRRoute : false;
|
|
143
144
|
if (nestedRoutesEntry) {
|
|
144
|
-
return `?loaderId=${loaderId}${clientDataStr}&action=${action ? (0, import_utils.slash)(action) : action}&inline=${inline}&routeId=${routeId}`;
|
|
145
|
+
return `?loaderId=${loaderId}${clientDataStr}&action=${action ? (0, import_utils.slash)(action) : action}&inline=${inline}&routeId=${routeId}&retain=${retain}`;
|
|
145
146
|
}
|
|
146
147
|
return "";
|
|
147
148
|
};
|
|
@@ -175,6 +176,7 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
|
|
|
175
176
|
loadersMap[loader] = {
|
|
176
177
|
loaderId,
|
|
177
178
|
routeId: route.id,
|
|
179
|
+
inValidSSRRoute: route.inValidSSRRoute,
|
|
178
180
|
filePath: route.data || route.loader,
|
|
179
181
|
clientData: Boolean(route.clientData),
|
|
180
182
|
route,
|
|
@@ -299,7 +301,8 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
|
|
|
299
301
|
clientData: loaderInfo.clientData,
|
|
300
302
|
action: route.action,
|
|
301
303
|
inline: loaderInfo.inline,
|
|
302
|
-
routeId: loaderInfo.routeId
|
|
304
|
+
routeId: loaderInfo.routeId,
|
|
305
|
+
inValidSSRRoute: loaderInfo.inValidSSRRoute
|
|
303
306
|
})}";
|
|
304
307
|
`;
|
|
305
308
|
} else {
|
|
@@ -308,7 +311,8 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
|
|
|
308
311
|
clientData: loaderInfo.clientData,
|
|
309
312
|
action: false,
|
|
310
313
|
inline: loaderInfo.inline,
|
|
311
|
-
routeId: route.id
|
|
314
|
+
routeId: route.id,
|
|
315
|
+
inValidSSRRoute: loaderInfo.inValidSSRRoute
|
|
312
316
|
})}";
|
|
313
317
|
`;
|
|
314
318
|
}
|
|
@@ -318,7 +322,8 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
|
|
|
318
322
|
clientData: loaderInfo.clientData,
|
|
319
323
|
action: false,
|
|
320
324
|
inline: loaderInfo.inline,
|
|
321
|
-
routeId: loaderInfo.routeId
|
|
325
|
+
routeId: loaderInfo.routeId,
|
|
326
|
+
inValidSSRRoute: loaderInfo.inValidSSRRoute
|
|
322
327
|
})}";
|
|
323
328
|
`;
|
|
324
329
|
}
|
|
@@ -418,7 +423,7 @@ const runtimeGlobalContext = async ({ metaName, srcDirectory, nestedRoutesEntry,
|
|
|
418
423
|
}
|
|
419
424
|
return `${imports.join("\n")}
|
|
420
425
|
|
|
421
|
-
import { routes } from './routes
|
|
426
|
+
import { routes } from './routes';
|
|
422
427
|
|
|
423
428
|
setGlobalContext({
|
|
424
429
|
layoutApp,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var cli_exports = {};
|
|
20
30
|
__export(cli_exports, {
|
|
@@ -25,6 +35,7 @@ __export(cli_exports, {
|
|
|
25
35
|
routerPlugin: () => routerPlugin
|
|
26
36
|
});
|
|
27
37
|
module.exports = __toCommonJS(cli_exports);
|
|
38
|
+
var import_node_path = __toESM(require("node:path"));
|
|
28
39
|
var import_utils = require("@modern-js/utils");
|
|
29
40
|
var import_entry = require("./entry");
|
|
30
41
|
var import_handler = require("./handler");
|
|
@@ -36,6 +47,8 @@ const routerPlugin = () => ({
|
|
|
36
47
|
"@modern-js/runtime"
|
|
37
48
|
],
|
|
38
49
|
setup: (api) => {
|
|
50
|
+
const nestedRoutes = {};
|
|
51
|
+
const nestedRoutesForServer = {};
|
|
39
52
|
return {
|
|
40
53
|
_internalRuntimePlugins({ entrypoint, plugins }) {
|
|
41
54
|
var _getEntryOptions;
|
|
@@ -60,10 +73,10 @@ const routerPlugin = () => ({
|
|
|
60
73
|
plugins
|
|
61
74
|
};
|
|
62
75
|
},
|
|
63
|
-
checkEntryPoint({ path, entry }) {
|
|
76
|
+
checkEntryPoint({ path: path2, entry }) {
|
|
64
77
|
return {
|
|
65
|
-
path,
|
|
66
|
-
entry: entry || (0, import_entry.isRouteEntry)(
|
|
78
|
+
path: path2,
|
|
79
|
+
entry: entry || (0, import_entry.isRouteEntry)(path2)
|
|
67
80
|
};
|
|
68
81
|
},
|
|
69
82
|
config() {
|
|
@@ -99,6 +112,22 @@ const routerPlugin = () => ({
|
|
|
99
112
|
},
|
|
100
113
|
async fileChange(e) {
|
|
101
114
|
await (0, import_handler.handleFileChange)(api, e);
|
|
115
|
+
},
|
|
116
|
+
async modifyFileSystemRoutes({ entrypoint, routes }) {
|
|
117
|
+
nestedRoutes[entrypoint.entryName] = routes;
|
|
118
|
+
nestedRoutesForServer[entrypoint.entryName] = (0, import_utils.filterRoutesForServer)(routes);
|
|
119
|
+
return {
|
|
120
|
+
entrypoint,
|
|
121
|
+
routes
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
async beforeGenerateRoutes({ entrypoint, code }) {
|
|
125
|
+
const { distDirectory } = api.useAppContext();
|
|
126
|
+
await import_utils.fs.outputJSON(import_node_path.default.resolve(distDirectory, import_utils.NESTED_ROUTE_SPEC_FILE), nestedRoutesForServer);
|
|
127
|
+
return {
|
|
128
|
+
entrypoint,
|
|
129
|
+
code
|
|
130
|
+
};
|
|
102
131
|
}
|
|
103
132
|
};
|
|
104
133
|
}
|