@modern-js/runtime 2.56.3-alpha.0 → 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/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/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/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/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/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/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/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 +12 -11
- 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
|
@@ -27,6 +27,7 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
|
27
27
|
var import_react = require("react");
|
|
28
28
|
var import_store = require("@modern-js-reduck/store");
|
|
29
29
|
var import_react2 = require("@modern-js-reduck/react");
|
|
30
|
+
var import_merge = require("@modern-js/runtime-utils/merge");
|
|
30
31
|
var import_plugins = require("../plugins");
|
|
31
32
|
var import_core = require("../../core");
|
|
32
33
|
var import_common = require("../../common");
|
|
@@ -55,12 +56,12 @@ const getStoreConfig = (config) => {
|
|
|
55
56
|
storeConfig.plugins = plugins;
|
|
56
57
|
return storeConfig;
|
|
57
58
|
};
|
|
58
|
-
const statePlugin = (
|
|
59
|
+
const statePlugin = (userConfig = {}) => ({
|
|
59
60
|
name: "@modern-js/plugin-state",
|
|
60
|
-
setup: () => {
|
|
61
|
-
|
|
61
|
+
setup: (api) => {
|
|
62
|
+
let storeConfig;
|
|
62
63
|
return {
|
|
63
|
-
|
|
64
|
+
wrapRoot(App) {
|
|
64
65
|
const getStateApp = (props) => {
|
|
65
66
|
const context = (0, import_react.useContext)(import_core.RuntimeReactContext);
|
|
66
67
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react2.Provider, {
|
|
@@ -71,29 +72,17 @@ const statePlugin = (config) => ({
|
|
|
71
72
|
})
|
|
72
73
|
});
|
|
73
74
|
};
|
|
74
|
-
return
|
|
75
|
-
App: getStateApp,
|
|
76
|
-
config: config2
|
|
77
|
-
});
|
|
75
|
+
return getStateApp;
|
|
78
76
|
},
|
|
79
|
-
|
|
77
|
+
beforeRender(context) {
|
|
78
|
+
const pluginConfig = api.useRuntimeConfigContext();
|
|
79
|
+
const config = (0, import_merge.merge)(pluginConfig.state || {}, userConfig);
|
|
80
|
+
storeConfig = getStoreConfig(config);
|
|
80
81
|
if ((0, import_common.isBrowser)()) {
|
|
81
82
|
var _window__SSR_DATA_data, _window__SSR_DATA, _window;
|
|
82
83
|
storeConfig.initialState = storeConfig.initialState || ((_window = window) === null || _window === void 0 ? void 0 : (_window__SSR_DATA = _window._SSR_DATA) === null || _window__SSR_DATA === void 0 ? void 0 : (_window__SSR_DATA_data = _window__SSR_DATA.data) === null || _window__SSR_DATA_data === void 0 ? void 0 : _window__SSR_DATA_data.storeState) || {};
|
|
83
84
|
}
|
|
84
85
|
context.store = (0, import_store.createStore)(storeConfig);
|
|
85
|
-
return next({
|
|
86
|
-
context
|
|
87
|
-
});
|
|
88
|
-
},
|
|
89
|
-
pickContext({ context, pickedContext }, next) {
|
|
90
|
-
return next({
|
|
91
|
-
context,
|
|
92
|
-
pickedContext: {
|
|
93
|
-
...pickedContext,
|
|
94
|
-
store: context.store
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
86
|
}
|
|
98
87
|
};
|
|
99
88
|
}
|
|
@@ -70,7 +70,9 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
70
70
|
});
|
|
71
71
|
} else {
|
|
72
72
|
loadableReady(function() {
|
|
73
|
-
ModernHydrate(
|
|
73
|
+
ModernHydrate(/* @__PURE__ */ React.cloneElement(App, {
|
|
74
|
+
_internal_context: hydrateContext
|
|
75
|
+
}), callback).then(function(root) {
|
|
74
76
|
resolve(root);
|
|
75
77
|
});
|
|
76
78
|
});
|
|
@@ -35,7 +35,7 @@ function render(App, id) {
|
|
|
35
35
|
}
|
|
36
36
|
function _render() {
|
|
37
37
|
_render = _async_to_generator(function(App, id) {
|
|
38
|
-
var runner, context,
|
|
38
|
+
var runner, context, runBeforeRender, ModernRender, ModernHydrate, _ssrData_data, _ssrData_data1, ssrData, loadersData, initialLoadersState, initialData, rootElement;
|
|
39
39
|
function _ModernRender() {
|
|
40
40
|
_ModernRender = _async_to_generator(function(App2) {
|
|
41
41
|
var renderFunc;
|
|
@@ -69,17 +69,30 @@ function _render() {
|
|
|
69
69
|
case 0:
|
|
70
70
|
runner = getGlobalRunner();
|
|
71
71
|
context = getInitialContext(runner);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
runBeforeRender = function() {
|
|
73
|
+
var _ref = _async_to_generator(function(context2) {
|
|
74
|
+
var init;
|
|
75
|
+
return _ts_generator(this, function(_state2) {
|
|
76
|
+
switch (_state2.label) {
|
|
77
|
+
case 0:
|
|
78
|
+
return [
|
|
79
|
+
4,
|
|
80
|
+
runner.beforeRender(context2)
|
|
81
|
+
];
|
|
82
|
+
case 1:
|
|
83
|
+
_state2.sent();
|
|
84
|
+
init = getGlobalAppInit();
|
|
85
|
+
return [
|
|
86
|
+
2,
|
|
87
|
+
init === null || init === void 0 ? void 0 : init(context2)
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
81
91
|
});
|
|
82
|
-
|
|
92
|
+
return function runBeforeRender2(context2) {
|
|
93
|
+
return _ref.apply(this, arguments);
|
|
94
|
+
};
|
|
95
|
+
}();
|
|
83
96
|
if (!isClientArgs(id))
|
|
84
97
|
return [
|
|
85
98
|
3,
|
|
@@ -104,14 +117,16 @@ function _render() {
|
|
|
104
117
|
Object.assign(context, _object_spread({
|
|
105
118
|
loaderManager: createLoaderManager(initialLoadersState, {
|
|
106
119
|
skipStatic: true
|
|
107
|
-
})
|
|
120
|
+
}),
|
|
121
|
+
// garfish plugin params
|
|
122
|
+
_internalRouterBaseName: App.props.basename
|
|
108
123
|
}, ssrData ? {
|
|
109
124
|
ssrContext: ssrData === null || ssrData === void 0 ? void 0 : ssrData.context
|
|
110
125
|
} : {}));
|
|
111
126
|
context.initialData = ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_data1 = ssrData.data) === null || _ssrData_data1 === void 0 ? void 0 : _ssrData_data1.initialData;
|
|
112
127
|
return [
|
|
113
128
|
4,
|
|
114
|
-
|
|
129
|
+
runBeforeRender(context)
|
|
115
130
|
];
|
|
116
131
|
case 1:
|
|
117
132
|
initialData = _state.sent();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
3
3
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
4
|
+
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
5
|
import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
|
|
5
6
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
6
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -35,61 +36,60 @@ var createApp = function(param) {
|
|
|
35
36
|
return /* @__PURE__ */ React.isValidElement(child) ? /* @__PURE__ */ React.cloneElement(child, _object_spread({}, child.props, props)) : child;
|
|
36
37
|
}));
|
|
37
38
|
};
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (!(contextValue === null || contextValue === void 0 ? void 0 : contextValue.runner)) {
|
|
50
|
-
contextValue = getInitialContext(runner);
|
|
51
|
-
runner.init({
|
|
52
|
-
context: contextValue
|
|
53
|
-
}, {
|
|
54
|
-
onLast: function(param3) {
|
|
55
|
-
var context1 = param3.context;
|
|
56
|
-
var _getGlobalAppInit;
|
|
57
|
-
return (_getGlobalAppInit = getGlobalAppInit()) === null || _getGlobalAppInit === void 0 ? void 0 : _getGlobalAppInit(context1);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
var mergedProps = _object_spread({}, props, globalProps);
|
|
62
|
-
return /* @__PURE__ */ _jsx(RuntimeReactContext.Provider, {
|
|
63
|
-
value: contextValue,
|
|
64
|
-
children: /* @__PURE__ */ _jsx(App2, _object_spread({}, mergedProps))
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
return WrapComponent;
|
|
39
|
+
var WrapperApp = runner.wrapRoot(WrapperComponent);
|
|
40
|
+
var WrapComponent = function(_param) {
|
|
41
|
+
var _internal_context = _param._internal_context, props = _object_without_properties(_param, [
|
|
42
|
+
"_internal_context"
|
|
43
|
+
]);
|
|
44
|
+
var contextValue = _internal_context;
|
|
45
|
+
if (!(contextValue === null || contextValue === void 0 ? void 0 : contextValue.runner)) {
|
|
46
|
+
var _getGlobalAppInit;
|
|
47
|
+
contextValue = getInitialContext(runner);
|
|
48
|
+
runner === null || runner === void 0 ? void 0 : runner.beforeRender(contextValue);
|
|
49
|
+
(_getGlobalAppInit = getGlobalAppInit()) === null || _getGlobalAppInit === void 0 ? void 0 : _getGlobalAppInit(contextValue);
|
|
68
50
|
}
|
|
69
|
-
|
|
70
|
-
|
|
51
|
+
var mergedProps = _object_spread({}, props, globalProps);
|
|
52
|
+
return /* @__PURE__ */ _jsx(RuntimeReactContext.Provider, {
|
|
53
|
+
value: contextValue,
|
|
54
|
+
children: /* @__PURE__ */ _jsx(WrapperApp, _object_spread({}, mergedProps))
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
return WrapComponent;
|
|
71
58
|
};
|
|
72
59
|
};
|
|
73
60
|
var bootstrap = function() {
|
|
74
61
|
var _ref = _async_to_generator(function(BootApp, id, root, ReactDOM) {
|
|
75
|
-
var App, runner, context,
|
|
62
|
+
var App, runner, context, runBeforeRender, isBrowser, _ssrData_data, _ssrData_data1, ssrData, loadersData, initialLoadersState, initialData, rootElement, ModernRender, ModernHydrate;
|
|
76
63
|
return _ts_generator(this, function(_state) {
|
|
77
64
|
switch (_state.label) {
|
|
78
65
|
case 0:
|
|
79
66
|
App = BootApp;
|
|
80
67
|
runner = getGlobalRunner();
|
|
81
68
|
context = getInitialContext(runner);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
69
|
+
runBeforeRender = function() {
|
|
70
|
+
var _ref2 = _async_to_generator(function(context2) {
|
|
71
|
+
var init;
|
|
72
|
+
return _ts_generator(this, function(_state2) {
|
|
73
|
+
switch (_state2.label) {
|
|
74
|
+
case 0:
|
|
75
|
+
return [
|
|
76
|
+
4,
|
|
77
|
+
runner.beforeRender(context2)
|
|
78
|
+
];
|
|
79
|
+
case 1:
|
|
80
|
+
_state2.sent();
|
|
81
|
+
init = getGlobalAppInit();
|
|
82
|
+
return [
|
|
83
|
+
2,
|
|
84
|
+
init === null || init === void 0 ? void 0 : init(context2)
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
91
88
|
});
|
|
92
|
-
|
|
89
|
+
return function runBeforeRender2(context2) {
|
|
90
|
+
return _ref2.apply(this, arguments);
|
|
91
|
+
};
|
|
92
|
+
}();
|
|
93
93
|
if (!id) {
|
|
94
94
|
return [
|
|
95
95
|
2,
|
|
@@ -129,7 +129,7 @@ var bootstrap = function() {
|
|
|
129
129
|
context.initialData = ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_data1 = ssrData.data) === null || _ssrData_data1 === void 0 ? void 0 : _ssrData_data1.initialData;
|
|
130
130
|
return [
|
|
131
131
|
4,
|
|
132
|
-
|
|
132
|
+
runBeforeRender(context)
|
|
133
133
|
];
|
|
134
134
|
case 1:
|
|
135
135
|
initialData = _state.sent();
|
|
@@ -210,21 +210,12 @@ var bootstrap = function() {
|
|
|
210
210
|
var useRuntimeContext = function() {
|
|
211
211
|
var _context_ssrContext, _context_ssrContext1;
|
|
212
212
|
var context = useContext(RuntimeReactContext);
|
|
213
|
-
var pickedContext = {
|
|
214
|
-
initialData: context.initialData,
|
|
213
|
+
var pickedContext = _object_spread_props(_object_spread({}, context), {
|
|
215
214
|
request: (_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.request,
|
|
216
215
|
response: (_context_ssrContext1 = context.ssrContext) === null || _context_ssrContext1 === void 0 ? void 0 : _context_ssrContext1.response
|
|
217
|
-
};
|
|
216
|
+
});
|
|
218
217
|
var memoizedContext = useMemo(function() {
|
|
219
|
-
return context.runner.pickContext(
|
|
220
|
-
context,
|
|
221
|
-
pickedContext
|
|
222
|
-
}, {
|
|
223
|
-
onLast: function(param) {
|
|
224
|
-
var pickedContext2 = param.pickedContext;
|
|
225
|
-
return pickedContext2;
|
|
226
|
-
}
|
|
227
|
-
});
|
|
218
|
+
return context.runner.pickContext(pickedContext);
|
|
228
219
|
}, [
|
|
229
220
|
context
|
|
230
221
|
]);
|
|
@@ -1,17 +1,28 @@
|
|
|
1
|
-
import { createManager,
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
1
|
+
import { createManager, createWaterfall, createAsyncInterruptWorkflow, createSyncParallelWorkflow, createContext } from "@modern-js/plugin";
|
|
2
|
+
var RuntimeConfigContext = createContext({});
|
|
3
|
+
var useRuntimeConfigContext = function() {
|
|
4
|
+
return RuntimeConfigContext.use().value;
|
|
5
|
+
};
|
|
6
|
+
var wrapRoot = createWaterfall();
|
|
7
|
+
var beforeRender = createAsyncInterruptWorkflow();
|
|
8
|
+
var pickContext = createWaterfall();
|
|
9
|
+
var modifyRuntimeConfig = createSyncParallelWorkflow();
|
|
5
10
|
var runtimeHooks = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
pickContext
|
|
11
|
+
beforeRender,
|
|
12
|
+
wrapRoot,
|
|
13
|
+
pickContext,
|
|
14
|
+
modifyRuntimeConfig
|
|
15
|
+
};
|
|
16
|
+
var runtimePluginAPI = {
|
|
17
|
+
useRuntimeConfigContext
|
|
9
18
|
};
|
|
10
19
|
var createRuntime = function() {
|
|
11
|
-
return createManager(runtimeHooks);
|
|
20
|
+
return createManager(runtimeHooks, runtimePluginAPI);
|
|
12
21
|
};
|
|
13
22
|
var runtime = createRuntime();
|
|
14
23
|
export {
|
|
24
|
+
RuntimeConfigContext,
|
|
15
25
|
createRuntime,
|
|
16
|
-
runtime
|
|
26
|
+
runtime,
|
|
27
|
+
useRuntimeConfigContext
|
|
17
28
|
};
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
2
|
-
import { merge } from "
|
|
3
|
-
import { runtime } from "./base";
|
|
4
|
-
import { setGlobalRunner } from "./runner";
|
|
2
|
+
import { merge } from "@modern-js/runtime-utils/merge";
|
|
3
|
+
import { runtime, RuntimeConfigContext } from "./base";
|
|
4
|
+
import { getGlobalRunner, setGlobalRunner } from "./runner";
|
|
5
5
|
export * from "./base";
|
|
6
|
+
function setupConfigContext() {
|
|
7
|
+
var runner = getGlobalRunner();
|
|
8
|
+
var configs = runner.modifyRuntimeConfig();
|
|
9
|
+
RuntimeConfigContext.set(merge.apply(void 0, [
|
|
10
|
+
{}
|
|
11
|
+
].concat(_to_consumable_array(configs))));
|
|
12
|
+
}
|
|
6
13
|
function registerPlugin(internalPlugins, runtimeConfig, customRuntime) {
|
|
7
14
|
var _instance;
|
|
8
15
|
var _ref = runtimeConfig || {}, _ref_plugins = _ref.plugins, plugins = _ref_plugins === void 0 ? [] : _ref_plugins;
|
|
9
16
|
(_instance = customRuntime || runtime).usePlugin.apply(_instance, _to_consumable_array(internalPlugins).concat(_to_consumable_array(plugins)));
|
|
10
17
|
var runner = (customRuntime || runtime).init();
|
|
11
18
|
setGlobalRunner(runner);
|
|
19
|
+
setupConfigContext();
|
|
12
20
|
return runner;
|
|
13
21
|
}
|
|
14
22
|
function mergeConfig(config) {
|
|
@@ -16,6 +24,7 @@ function mergeConfig(config) {
|
|
|
16
24
|
otherConfig[_key - 1] = arguments[_key];
|
|
17
25
|
}
|
|
18
26
|
return merge.apply(void 0, [
|
|
27
|
+
{},
|
|
19
28
|
config
|
|
20
29
|
].concat(_to_consumable_array(otherConfig)));
|
|
21
30
|
}
|
|
@@ -3,28 +3,20 @@ import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_
|
|
|
3
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
4
|
import { RuntimeReactContext, getGlobalApp } from "../context";
|
|
5
5
|
import { getGlobalRunner } from "../plugin/runner";
|
|
6
|
-
function createRoot(UserApp
|
|
6
|
+
function createRoot(UserApp) {
|
|
7
7
|
var App = UserApp || getGlobalApp();
|
|
8
8
|
var runner = getGlobalRunner();
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
value: _internal_context,
|
|
21
|
-
children: /* @__PURE__ */ _jsx(App2, _object_spread({}, props))
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
return WrapComponent;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
return HOCApp;
|
|
9
|
+
var WrapperApp = runner.wrapRoot(App);
|
|
10
|
+
var WrapComponent = function(_param) {
|
|
11
|
+
var _internal_context = _param._internal_context, props = _object_without_properties(_param, [
|
|
12
|
+
"_internal_context"
|
|
13
|
+
]);
|
|
14
|
+
return /* @__PURE__ */ _jsx(RuntimeReactContext.Provider, {
|
|
15
|
+
value: _internal_context,
|
|
16
|
+
children: /* @__PURE__ */ _jsx(WrapperApp, _object_spread({}, props))
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
return WrapComponent;
|
|
28
20
|
}
|
|
29
21
|
export {
|
|
30
22
|
createRoot
|
|
@@ -13,7 +13,7 @@ import { createLoaderManager } from "../loader/loaderManager";
|
|
|
13
13
|
import { getSSRConfigByEntry, getSSRMode } from "./utils";
|
|
14
14
|
import { CHUNK_CSS_PLACEHOLDER } from "./constants";
|
|
15
15
|
function createSSRContext(request, options) {
|
|
16
|
-
var config = options.config, loaderContext = options.loaderContext, onError = options.onError, onTiming = options.onTiming, locals = options.locals, resource = options.resource, params = options.params, responseProxy = options.responseProxy,
|
|
16
|
+
var config = options.config, loaderContext = options.loaderContext, onError = options.onError, onTiming = options.onTiming, locals = options.locals, resource = options.resource, params = options.params, responseProxy = options.responseProxy, logger = options.logger, metrics = options.metrics, reporter = options.reporter;
|
|
17
17
|
var nonce = config.nonce;
|
|
18
18
|
var entryName = resource.entryName, route = resource.route;
|
|
19
19
|
var cookie = request.headers.get("cookie");
|
|
@@ -22,7 +22,7 @@ function createSSRContext(request, options) {
|
|
|
22
22
|
var query = parseQuery(request);
|
|
23
23
|
var headersData = parseHeaders(request);
|
|
24
24
|
var url = new URL(request.url);
|
|
25
|
-
var ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries
|
|
25
|
+
var ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries);
|
|
26
26
|
var ssrMode = getSSRMode(ssrConfig);
|
|
27
27
|
var loaderFailureMode = typeof ssrConfig === "object" ? ssrConfig.loaderFailureMode : void 0;
|
|
28
28
|
return {
|
|
@@ -66,7 +66,7 @@ var createRequestHandler = function() {
|
|
|
66
66
|
return _ts_generator(this, function(_state) {
|
|
67
67
|
requestHandler = function() {
|
|
68
68
|
var _ref2 = _async_to_generator(function(request, options) {
|
|
69
|
-
var Root, runner, routeManifest, context,
|
|
69
|
+
var Root, runner, routeManifest, context, runBeforeRender, responseProxy, ssrContext, getRedirectResponse, initialData, redirectResponse, htmlTemplate, response;
|
|
70
70
|
return _ts_generator(this, function(_state2) {
|
|
71
71
|
switch (_state2.label) {
|
|
72
72
|
case 0:
|
|
@@ -74,17 +74,36 @@ var createRequestHandler = function() {
|
|
|
74
74
|
runner = getGlobalRunner();
|
|
75
75
|
routeManifest = options.resource.routeManifest;
|
|
76
76
|
context = getInitialContext(runner, false, routeManifest);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
77
|
+
runBeforeRender = function() {
|
|
78
|
+
var _ref3 = _async_to_generator(function(context2) {
|
|
79
|
+
var result, init;
|
|
80
|
+
return _ts_generator(this, function(_state3) {
|
|
81
|
+
switch (_state3.label) {
|
|
82
|
+
case 0:
|
|
83
|
+
return [
|
|
84
|
+
4,
|
|
85
|
+
runner.beforeRender(context2)
|
|
86
|
+
];
|
|
87
|
+
case 1:
|
|
88
|
+
result = _state3.sent();
|
|
89
|
+
if (typeof Response !== "undefined" && _instanceof(result, Response)) {
|
|
90
|
+
return [
|
|
91
|
+
2,
|
|
92
|
+
result
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
init = getGlobalAppInit();
|
|
96
|
+
return [
|
|
97
|
+
2,
|
|
98
|
+
init === null || init === void 0 ? void 0 : init(context2)
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
});
|
|
86
102
|
});
|
|
87
|
-
|
|
103
|
+
return function runBeforeRender2(context2) {
|
|
104
|
+
return _ref3.apply(this, arguments);
|
|
105
|
+
};
|
|
106
|
+
}();
|
|
88
107
|
responseProxy = {
|
|
89
108
|
headers: {},
|
|
90
109
|
code: -1
|
|
@@ -120,7 +139,7 @@ var createRequestHandler = function() {
|
|
|
120
139
|
};
|
|
121
140
|
return [
|
|
122
141
|
4,
|
|
123
|
-
|
|
142
|
+
runBeforeRender(context)
|
|
124
143
|
];
|
|
125
144
|
case 1:
|
|
126
145
|
initialData = _state2.sent();
|
|
@@ -39,16 +39,16 @@ function createRenderStreaming(createReadableStreamFromElement) {
|
|
|
39
39
|
return [
|
|
40
40
|
2,
|
|
41
41
|
run(headersData, /* @__PURE__ */ _async_to_generator(function() {
|
|
42
|
-
var end, runtimeContext, config, resource,
|
|
42
|
+
var end, runtimeContext, config, resource, onError, onTiming, htmlTemplate, entryName, ssrConfig, rootElement, stream;
|
|
43
43
|
return _ts_generator(this, function(_state2) {
|
|
44
44
|
switch (_state2.label) {
|
|
45
45
|
case 0:
|
|
46
46
|
end = time();
|
|
47
|
-
runtimeContext = options.runtimeContext, config = options.config, resource = options.resource
|
|
47
|
+
runtimeContext = options.runtimeContext, config = options.config, resource = options.resource;
|
|
48
48
|
onError = createOnError(options.onError);
|
|
49
49
|
onTiming = createOnTiming(options.onTiming);
|
|
50
50
|
htmlTemplate = resource.htmlTemplate, entryName = resource.entryName;
|
|
51
|
-
ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries
|
|
51
|
+
ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries);
|
|
52
52
|
rootElement = React.cloneElement(serverRoot, {
|
|
53
53
|
_internal_context: Object.assign(runtimeContext, {
|
|
54
54
|
ssr: true
|
|
@@ -25,18 +25,18 @@ var renderString = function() {
|
|
|
25
25
|
return [
|
|
26
26
|
2,
|
|
27
27
|
run(headersData, /* @__PURE__ */ _async_to_generator(function() {
|
|
28
|
-
var _runtimeContext_ssrContext, resource, runtimeContext, config, onError, onTiming,
|
|
28
|
+
var _runtimeContext_ssrContext, resource, runtimeContext, config, onError, onTiming, tracer, routerContext, htmlTemplate, entryName, loadableStats, routeManifest, ssrConfig, chunkSet, prefetchData, e, collectors, rootElement, html;
|
|
29
29
|
return _ts_generator(this, function(_state2) {
|
|
30
30
|
switch (_state2.label) {
|
|
31
31
|
case 0:
|
|
32
|
-
resource = options.resource, runtimeContext = options.runtimeContext, config = options.config, onError = options.onError, onTiming = options.onTiming
|
|
32
|
+
resource = options.resource, runtimeContext = options.runtimeContext, config = options.config, onError = options.onError, onTiming = options.onTiming;
|
|
33
33
|
tracer = {
|
|
34
34
|
onError: createOnError(onError),
|
|
35
35
|
onTiming: createOnTiming(onTiming)
|
|
36
36
|
};
|
|
37
37
|
routerContext = runtimeContext.routerContext;
|
|
38
38
|
htmlTemplate = resource.htmlTemplate, entryName = resource.entryName, loadableStats = resource.loadableStats, routeManifest = resource.routeManifest;
|
|
39
|
-
ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries
|
|
39
|
+
ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries);
|
|
40
40
|
chunkSet = {
|
|
41
41
|
renderLevel: RenderLevel.CLIENT_RENDER,
|
|
42
42
|
ssrScripts: "",
|
|
@@ -66,6 +66,7 @@ var renderString = function() {
|
|
|
66
66
|
case 3:
|
|
67
67
|
e = _state2.sent();
|
|
68
68
|
chunkSet.renderLevel = RenderLevel.CLIENT_RENDER;
|
|
69
|
+
tracer.onError(SSRErrors.PRERENDER, e);
|
|
69
70
|
return [
|
|
70
71
|
3,
|
|
71
72
|
4
|
|
@@ -58,14 +58,11 @@ function serializeErrors(errors) {
|
|
|
58
58
|
}
|
|
59
59
|
return serialized;
|
|
60
60
|
}
|
|
61
|
-
function getSSRConfigByEntry(entryName, ssr, ssrByEntries
|
|
62
|
-
if (staticGenerate) {
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
61
|
+
function getSSRConfigByEntry(entryName, ssr, ssrByEntries) {
|
|
65
62
|
if (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[entryName]) {
|
|
66
63
|
return ssrByEntries[entryName];
|
|
67
64
|
}
|
|
68
|
-
return ssr;
|
|
65
|
+
return ssr || true;
|
|
69
66
|
}
|
|
70
67
|
function getSSRMode(ssrConfig) {
|
|
71
68
|
if (typeof ssrConfig === "boolean") {
|