@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
|
@@ -5,6 +5,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
5
5
|
import { useContext, useMemo } from "react";
|
|
6
6
|
import { createBrowserRouter, createHashRouter, RouterProvider, createRoutesFromElements, useMatches, useLocation, useHref } from "@modern-js/runtime-utils/router";
|
|
7
7
|
import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
|
|
8
|
+
import { merge } from "@modern-js/runtime-utils/merge";
|
|
8
9
|
import { getGlobalLayoutApp, getGlobalRoutes } from "../../core/context";
|
|
9
10
|
import { RuntimeReactContext } from "../../core";
|
|
10
11
|
import { modifyRoutes as modifyRoutesHook } from "./hooks";
|
|
@@ -22,28 +23,18 @@ function modifyRoutes(modifyFunction) {
|
|
|
22
23
|
console.error("It is not allowed to modify routes config after create router.");
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
var routerPlugin = function(
|
|
26
|
-
var
|
|
27
|
-
var select = function(pathname) {
|
|
28
|
-
return serverBase.find(function(baseUrl) {
|
|
29
|
-
return pathname.search(baseUrl) === 0;
|
|
30
|
-
}) || "/";
|
|
31
|
-
};
|
|
32
|
-
var routes = [];
|
|
33
|
-
finalRouteConfig = _object_spread({
|
|
34
|
-
routes: getGlobalRoutes(),
|
|
35
|
-
globalApp: getGlobalLayoutApp()
|
|
36
|
-
}, routesConfig);
|
|
37
|
-
window._SERVER_DATA = parsedJSONFromElement("__MODERN_SERVER_DATA__");
|
|
26
|
+
var routerPlugin = function() {
|
|
27
|
+
var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
38
28
|
return {
|
|
39
29
|
name: "@modern-js/plugin-router",
|
|
40
30
|
registerHook: {
|
|
41
31
|
modifyRoutes: modifyRoutesHook
|
|
42
32
|
},
|
|
43
33
|
setup: function(api) {
|
|
34
|
+
var routes = [];
|
|
35
|
+
window._SERVER_DATA = parsedJSONFromElement("__MODERN_SERVER_DATA__");
|
|
44
36
|
return {
|
|
45
|
-
|
|
46
|
-
var context = param2.context;
|
|
37
|
+
beforeRender: function beforeRender(context) {
|
|
47
38
|
context.router = {
|
|
48
39
|
useMatches,
|
|
49
40
|
useLocation,
|
|
@@ -54,25 +45,29 @@ var routerPlugin = function(param) {
|
|
|
54
45
|
return routes;
|
|
55
46
|
}
|
|
56
47
|
});
|
|
57
|
-
return next({
|
|
58
|
-
context
|
|
59
|
-
});
|
|
60
48
|
},
|
|
61
|
-
|
|
62
|
-
var
|
|
49
|
+
wrapRoot: function(App) {
|
|
50
|
+
var pluginConfig = api.useRuntimeConfigContext();
|
|
51
|
+
var _merge = merge(pluginConfig.router || {}, userConfig), _merge_serverBase = _merge.serverBase, serverBase = _merge_serverBase === void 0 ? [] : _merge_serverBase, _merge_supportHtml5History = _merge.supportHtml5History, supportHtml5History = _merge_supportHtml5History === void 0 ? true : _merge_supportHtml5History, _merge_basename = _merge.basename, basename = _merge_basename === void 0 ? "" : _merge_basename, routesConfig = _merge.routesConfig, createRoutes = _merge.createRoutes;
|
|
52
|
+
var select = function(pathname) {
|
|
53
|
+
return serverBase.find(function(baseUrl) {
|
|
54
|
+
return pathname.search(baseUrl) === 0;
|
|
55
|
+
}) || "/";
|
|
56
|
+
};
|
|
57
|
+
finalRouteConfig = _object_spread({
|
|
58
|
+
routes: getGlobalRoutes(),
|
|
59
|
+
globalApp: getGlobalLayoutApp()
|
|
60
|
+
}, routesConfig);
|
|
63
61
|
if (!finalRouteConfig.routes && !createRoutes) {
|
|
64
|
-
return
|
|
65
|
-
App,
|
|
66
|
-
config
|
|
67
|
-
});
|
|
62
|
+
return App;
|
|
68
63
|
}
|
|
69
64
|
var getRouteApp = function() {
|
|
70
65
|
var useCreateRouter = function(props) {
|
|
71
|
-
var
|
|
72
|
-
var
|
|
66
|
+
var _window__SERVER_DATA;
|
|
67
|
+
var runtimeContext = useContext(RuntimeReactContext);
|
|
68
|
+
var baseUrl = (runtimeContext._internalRouterBaseName || ((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname)).replace(/^\/*/, "/");
|
|
73
69
|
var _basename = baseUrl === "/" ? urlJoin(baseUrl, basename) : baseUrl;
|
|
74
70
|
var hydrationData = window._ROUTER_DATA;
|
|
75
|
-
var runtimeContext = useContext(RuntimeReactContext);
|
|
76
71
|
var getBlockNavState = runtimeContext.unstable_getBlockNavState;
|
|
77
72
|
return useMemo(function() {
|
|
78
73
|
if (hydrationData === null || hydrationData === void 0 ? void 0 : hydrationData.errors) {
|
|
@@ -111,7 +106,8 @@ var routerPlugin = function(param) {
|
|
|
111
106
|
get: function get() {
|
|
112
107
|
return router;
|
|
113
108
|
},
|
|
114
|
-
configurable: true
|
|
109
|
+
configurable: true,
|
|
110
|
+
enumerable: true
|
|
115
111
|
});
|
|
116
112
|
return router;
|
|
117
113
|
}, [
|
|
@@ -130,32 +126,21 @@ var routerPlugin = function(param) {
|
|
|
130
126
|
});
|
|
131
127
|
};
|
|
132
128
|
};
|
|
133
|
-
|
|
134
|
-
return next({
|
|
135
|
-
App: RouteApp,
|
|
136
|
-
config
|
|
137
|
-
});
|
|
129
|
+
return getRouteApp();
|
|
138
130
|
},
|
|
139
|
-
pickContext: function(
|
|
140
|
-
var
|
|
141
|
-
var remixRouter = context.remixRouter;
|
|
131
|
+
pickContext: function(pickedContext) {
|
|
132
|
+
var remixRouter = pickedContext.remixRouter;
|
|
142
133
|
if (!remixRouter) {
|
|
143
|
-
return
|
|
144
|
-
context,
|
|
145
|
-
pickedContext
|
|
146
|
-
});
|
|
134
|
+
return pickedContext;
|
|
147
135
|
}
|
|
148
|
-
var router = {
|
|
136
|
+
var router = _object_spread_props(_object_spread({}, pickedContext.router), {
|
|
149
137
|
navigate: remixRouter.navigate,
|
|
150
138
|
get location() {
|
|
151
139
|
return remixRouter.state.location;
|
|
152
140
|
}
|
|
153
|
-
};
|
|
154
|
-
return
|
|
155
|
-
|
|
156
|
-
pickedContext: _object_spread_props(_object_spread({}, pickedContext), {
|
|
157
|
-
router
|
|
158
|
-
})
|
|
141
|
+
});
|
|
142
|
+
return _object_spread_props(_object_spread({}, pickedContext), {
|
|
143
|
+
router
|
|
159
144
|
});
|
|
160
145
|
}
|
|
161
146
|
};
|
|
@@ -11,6 +11,7 @@ import { createRoutesFromElements } from "@modern-js/runtime-utils/router";
|
|
|
11
11
|
import { reporterCtx, createRequestContext } from "@modern-js/runtime-utils/node";
|
|
12
12
|
import { time } from "@modern-js/runtime-utils/time";
|
|
13
13
|
import { LOADER_REPORTER_NAME } from "@modern-js/utils/universal/constants";
|
|
14
|
+
import { merge } from "@modern-js/runtime-utils/merge";
|
|
14
15
|
import { JSX_SHELL_STREAM_END_MARK } from "../../common";
|
|
15
16
|
import { RuntimeReactContext } from "../../core";
|
|
16
17
|
import { getGlobalLayoutApp, getGlobalRoutes } from "../../core/context";
|
|
@@ -27,32 +28,31 @@ function createRemixReuqest(request) {
|
|
|
27
28
|
signal: controller.signal
|
|
28
29
|
});
|
|
29
30
|
}
|
|
30
|
-
var routerPlugin = function(
|
|
31
|
-
var
|
|
31
|
+
var routerPlugin = function() {
|
|
32
|
+
var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
32
33
|
return {
|
|
33
34
|
name: "@modern-js/plugin-router",
|
|
34
35
|
registerHook: {
|
|
35
36
|
modifyRoutes: modifyRoutesHook
|
|
36
37
|
},
|
|
37
38
|
setup: function(api) {
|
|
38
|
-
var finalRouteConfig =
|
|
39
|
-
routes: getGlobalRoutes(),
|
|
40
|
-
globalApp: getGlobalLayoutApp()
|
|
41
|
-
}, routesConfig);
|
|
39
|
+
var finalRouteConfig = {};
|
|
42
40
|
return {
|
|
43
|
-
|
|
44
|
-
var context = param2.context;
|
|
41
|
+
beforeRender: function beforeRender(context, interrupt) {
|
|
45
42
|
return _async_to_generator(function() {
|
|
46
|
-
var _context_ssrContext, _context_ssrContext_onTiming, _context_ssrContext1, _context_ssrContext2, request, ssrMode, nonce, _context_ssrContext_loaderFailureMode, loaderFailureMode, baseUrl, _basename, reporter, requestContext, routes, runner, query, remixRequest, end, routerContext, cost, router;
|
|
43
|
+
var _context_ssrContext, _context_ssrContext_onTiming, _context_ssrContext1, pluginConfig, _merge, _merge_basename, basename, routesConfig, createRoutes, _context_ssrContext2, request, ssrMode, nonce, _context_ssrContext_loaderFailureMode, loaderFailureMode, baseUrl, _basename, reporter, requestContext, routes, runner, query, remixRequest, end, routerContext, cost, router;
|
|
47
44
|
return _ts_generator(this, function(_state) {
|
|
48
45
|
switch (_state.label) {
|
|
49
46
|
case 0:
|
|
47
|
+
pluginConfig = api.useRuntimeConfigContext();
|
|
48
|
+
_merge = merge(pluginConfig.router || {}, userConfig), _merge_basename = _merge.basename, basename = _merge_basename === void 0 ? "" : _merge_basename, routesConfig = _merge.routesConfig, createRoutes = _merge.createRoutes;
|
|
49
|
+
finalRouteConfig = _object_spread({
|
|
50
|
+
routes: getGlobalRoutes(),
|
|
51
|
+
globalApp: getGlobalLayoutApp()
|
|
52
|
+
}, routesConfig);
|
|
50
53
|
if (!finalRouteConfig.routes && !createRoutes) {
|
|
51
54
|
return [
|
|
52
|
-
2
|
|
53
|
-
next({
|
|
54
|
-
context
|
|
55
|
-
})
|
|
55
|
+
2
|
|
56
56
|
];
|
|
57
57
|
}
|
|
58
58
|
_context_ssrContext2 = context.ssrContext, request = _context_ssrContext2.request, ssrMode = _context_ssrContext2.mode, nonce = _context_ssrContext2.nonce, _context_ssrContext_loaderFailureMode = _context_ssrContext2.loaderFailureMode, loaderFailureMode = _context_ssrContext_loaderFailureMode === void 0 ? "errorBoundary" : _context_ssrContext_loaderFailureMode;
|
|
@@ -89,7 +89,7 @@ var routerPlugin = function(param) {
|
|
|
89
89
|
if (_instanceof(routerContext, Response)) {
|
|
90
90
|
return [
|
|
91
91
|
2,
|
|
92
|
-
routerContext
|
|
92
|
+
interrupt(routerContext)
|
|
93
93
|
];
|
|
94
94
|
}
|
|
95
95
|
if (routerContext.statusCode >= 500 && routerContext.statusCode < 600 && loaderFailureMode === "clientRender") {
|
|
@@ -101,26 +101,20 @@ var routerPlugin = function(param) {
|
|
|
101
101
|
context.routerContext = routerContext;
|
|
102
102
|
context.routes = routes;
|
|
103
103
|
return [
|
|
104
|
-
2
|
|
105
|
-
next({
|
|
106
|
-
context
|
|
107
|
-
})
|
|
104
|
+
2
|
|
108
105
|
];
|
|
109
106
|
}
|
|
110
107
|
});
|
|
111
108
|
})();
|
|
112
109
|
},
|
|
113
|
-
|
|
114
|
-
var App = param2.App, config = param2.config;
|
|
110
|
+
wrapRoot: function(App) {
|
|
115
111
|
if (!finalRouteConfig) {
|
|
116
|
-
return
|
|
117
|
-
App,
|
|
118
|
-
config
|
|
119
|
-
});
|
|
112
|
+
return App;
|
|
120
113
|
}
|
|
121
114
|
var getRouteApp = function() {
|
|
122
115
|
return function() {
|
|
123
|
-
var
|
|
116
|
+
var context = useContext(RuntimeReactContext);
|
|
117
|
+
var remixRouter = context.remixRouter, routerContext = context.routerContext, ssrContext = context.ssrContext;
|
|
124
118
|
var nonce = ssrContext.nonce, mode = ssrContext.mode;
|
|
125
119
|
return /* @__PURE__ */ _jsxs(_Fragment, {
|
|
126
120
|
children: [
|
|
@@ -129,6 +123,8 @@ var routerPlugin = function(param) {
|
|
|
129
123
|
context: routerContext,
|
|
130
124
|
hydrate: false
|
|
131
125
|
}),
|
|
126
|
+
mode === "stream" && // ROUTER_DATA will inject in `packages/runtime/plugin-runtime/src/core/server/string/ssrData.ts` in string ssr
|
|
127
|
+
// So we can inject it only when streaming ssr
|
|
132
128
|
/* @__PURE__ */ _jsx(DeferredDataScripts, {
|
|
133
129
|
nonce,
|
|
134
130
|
context: routerContext
|
|
@@ -138,20 +134,12 @@ var routerPlugin = function(param) {
|
|
|
138
134
|
});
|
|
139
135
|
};
|
|
140
136
|
};
|
|
141
|
-
|
|
142
|
-
return next({
|
|
143
|
-
App: RouteApp,
|
|
144
|
-
config
|
|
145
|
-
});
|
|
137
|
+
return getRouteApp();
|
|
146
138
|
},
|
|
147
|
-
pickContext: function(
|
|
148
|
-
var
|
|
149
|
-
var remixRouter = context.remixRouter;
|
|
139
|
+
pickContext: function(pickedContext) {
|
|
140
|
+
var remixRouter = pickedContext.remixRouter;
|
|
150
141
|
if (!remixRouter) {
|
|
151
|
-
return
|
|
152
|
-
context,
|
|
153
|
-
pickedContext
|
|
154
|
-
});
|
|
142
|
+
return pickedContext;
|
|
155
143
|
}
|
|
156
144
|
var router = {
|
|
157
145
|
navigate: remixRouter.navigate,
|
|
@@ -159,11 +147,8 @@ var routerPlugin = function(param) {
|
|
|
159
147
|
return remixRouter.state.location;
|
|
160
148
|
}
|
|
161
149
|
};
|
|
162
|
-
return
|
|
163
|
-
|
|
164
|
-
pickedContext: _object_spread_props(_object_spread({}, pickedContext), {
|
|
165
|
-
router
|
|
166
|
-
})
|
|
150
|
+
return _object_spread_props(_object_spread({}, pickedContext), {
|
|
151
|
+
router
|
|
167
152
|
});
|
|
168
153
|
}
|
|
169
154
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
3
2
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
4
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
4
|
import { useContext } from "react";
|
|
6
5
|
import { createStore } from "@modern-js-reduck/store";
|
|
7
6
|
import { Provider } from "@modern-js-reduck/react";
|
|
7
|
+
import { merge } from "@modern-js/runtime-utils/merge";
|
|
8
8
|
import { immer, effects, autoActions, devtools } from "../plugins";
|
|
9
9
|
import { RuntimeReactContext } from "../../core";
|
|
10
10
|
import { isBrowser } from "../../common";
|
|
@@ -53,14 +53,14 @@ var getStoreConfig = function(config) {
|
|
|
53
53
|
storeConfig.plugins = plugins;
|
|
54
54
|
return storeConfig;
|
|
55
55
|
};
|
|
56
|
-
var statePlugin = function(
|
|
56
|
+
var statePlugin = function() {
|
|
57
|
+
var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
57
58
|
return {
|
|
58
59
|
name: "@modern-js/plugin-state",
|
|
59
|
-
setup: function() {
|
|
60
|
-
var storeConfig
|
|
60
|
+
setup: function(api) {
|
|
61
|
+
var storeConfig;
|
|
61
62
|
return {
|
|
62
|
-
|
|
63
|
-
var App = param.App, _$config = param.config;
|
|
63
|
+
wrapRoot: function wrapRoot(App) {
|
|
64
64
|
var getStateApp = function(props) {
|
|
65
65
|
var context = useContext(RuntimeReactContext);
|
|
66
66
|
return /* @__PURE__ */ _jsx(Provider, {
|
|
@@ -69,30 +69,17 @@ var statePlugin = function(config) {
|
|
|
69
69
|
children: /* @__PURE__ */ _jsx(App, _object_spread({}, props))
|
|
70
70
|
});
|
|
71
71
|
};
|
|
72
|
-
return
|
|
73
|
-
App: getStateApp,
|
|
74
|
-
config: _$config
|
|
75
|
-
});
|
|
72
|
+
return getStateApp;
|
|
76
73
|
},
|
|
77
|
-
|
|
78
|
-
var
|
|
74
|
+
beforeRender: function beforeRender(context) {
|
|
75
|
+
var pluginConfig = api.useRuntimeConfigContext();
|
|
76
|
+
var config = merge(pluginConfig.state || {}, userConfig);
|
|
77
|
+
storeConfig = getStoreConfig(config);
|
|
79
78
|
if (isBrowser()) {
|
|
80
79
|
var _window__SSR_DATA_data, _window__SSR_DATA, _window;
|
|
81
80
|
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) || {};
|
|
82
81
|
}
|
|
83
82
|
context.store = createStore(storeConfig);
|
|
84
|
-
return next({
|
|
85
|
-
context
|
|
86
|
-
});
|
|
87
|
-
},
|
|
88
|
-
pickContext: function pickContext(param, next) {
|
|
89
|
-
var context = param.context, pickedContext = param.pickedContext;
|
|
90
|
-
return next({
|
|
91
|
-
context,
|
|
92
|
-
pickedContext: _object_spread_props(_object_spread({}, pickedContext), {
|
|
93
|
-
store: context.store
|
|
94
|
-
})
|
|
95
|
-
});
|
|
96
83
|
}
|
|
97
84
|
};
|
|
98
85
|
}
|
|
@@ -63,7 +63,9 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
63
63
|
});
|
|
64
64
|
} else {
|
|
65
65
|
loadableReady(() => {
|
|
66
|
-
ModernHydrate(
|
|
66
|
+
ModernHydrate(/* @__PURE__ */ React.cloneElement(App, {
|
|
67
|
+
_internal_context: hydrateContext
|
|
68
|
+
}), callback).then((root) => {
|
|
67
69
|
resolve(root);
|
|
68
70
|
});
|
|
69
71
|
});
|
|
@@ -31,14 +31,11 @@ function isClientArgs(id) {
|
|
|
31
31
|
async function render(App, id) {
|
|
32
32
|
const runner = getGlobalRunner();
|
|
33
33
|
const context = getInitialContext(runner);
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return init === null || init === void 0 ? void 0 : init(context1);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
34
|
+
const runBeforeRender = async (context2) => {
|
|
35
|
+
await runner.beforeRender(context2);
|
|
36
|
+
const init = getGlobalAppInit();
|
|
37
|
+
return init === null || init === void 0 ? void 0 : init(context2);
|
|
38
|
+
};
|
|
42
39
|
if (isClientArgs(id)) {
|
|
43
40
|
var _ssrData_data, _ssrData_data1;
|
|
44
41
|
const ssrData = getSSRData();
|
|
@@ -55,12 +52,14 @@ async function render(App, id) {
|
|
|
55
52
|
loaderManager: createLoaderManager(initialLoadersState, {
|
|
56
53
|
skipStatic: true
|
|
57
54
|
}),
|
|
55
|
+
// garfish plugin params
|
|
56
|
+
_internalRouterBaseName: App.props.basename,
|
|
58
57
|
...ssrData ? {
|
|
59
58
|
ssrContext: ssrData === null || ssrData === void 0 ? void 0 : ssrData.context
|
|
60
59
|
} : {}
|
|
61
60
|
});
|
|
62
61
|
context.initialData = ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_data1 = ssrData.data) === null || _ssrData_data1 === void 0 ? void 0 : _ssrData_data1.initialData;
|
|
63
|
-
const initialData = await
|
|
62
|
+
const initialData = await runBeforeRender(context);
|
|
64
63
|
if (initialData) {
|
|
65
64
|
context.initialData = initialData;
|
|
66
65
|
}
|
|
@@ -30,53 +30,38 @@ const createApp = ({ plugins, runtime, props: globalProps }) => {
|
|
|
30
30
|
...props
|
|
31
31
|
}) : child));
|
|
32
32
|
};
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
contextValue = getInitialContext(runner);
|
|
42
|
-
runner.init({
|
|
43
|
-
context: contextValue
|
|
44
|
-
}, {
|
|
45
|
-
onLast: ({ context: context1 }) => {
|
|
46
|
-
var _getGlobalAppInit;
|
|
47
|
-
return (_getGlobalAppInit = getGlobalAppInit()) === null || _getGlobalAppInit === void 0 ? void 0 : _getGlobalAppInit(context1);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
const mergedProps = {
|
|
52
|
-
...props,
|
|
53
|
-
...globalProps
|
|
54
|
-
};
|
|
55
|
-
return /* @__PURE__ */ _jsx(RuntimeReactContext.Provider, {
|
|
56
|
-
value: contextValue,
|
|
57
|
-
children: /* @__PURE__ */ _jsx(App2, {
|
|
58
|
-
...mergedProps
|
|
59
|
-
})
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
return WrapComponent;
|
|
33
|
+
const WrapperApp = runner.wrapRoot(WrapperComponent);
|
|
34
|
+
const WrapComponent = ({ _internal_context, ...props }) => {
|
|
35
|
+
let contextValue = _internal_context;
|
|
36
|
+
if (!(contextValue === null || contextValue === void 0 ? void 0 : contextValue.runner)) {
|
|
37
|
+
var _getGlobalAppInit;
|
|
38
|
+
contextValue = getInitialContext(runner);
|
|
39
|
+
runner === null || runner === void 0 ? void 0 : runner.beforeRender(contextValue);
|
|
40
|
+
(_getGlobalAppInit = getGlobalAppInit()) === null || _getGlobalAppInit === void 0 ? void 0 : _getGlobalAppInit(contextValue);
|
|
63
41
|
}
|
|
64
|
-
|
|
65
|
-
|
|
42
|
+
const mergedProps = {
|
|
43
|
+
...props,
|
|
44
|
+
...globalProps
|
|
45
|
+
};
|
|
46
|
+
return /* @__PURE__ */ _jsx(RuntimeReactContext.Provider, {
|
|
47
|
+
value: contextValue,
|
|
48
|
+
children: /* @__PURE__ */ _jsx(WrapperApp, {
|
|
49
|
+
...mergedProps
|
|
50
|
+
})
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
return WrapComponent;
|
|
66
54
|
};
|
|
67
55
|
};
|
|
68
56
|
const bootstrap = async (BootApp, id, root, ReactDOM) => {
|
|
69
57
|
const App = BootApp;
|
|
70
58
|
const runner = getGlobalRunner();
|
|
71
59
|
const context = getInitialContext(runner);
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return init === null || init === void 0 ? void 0 : init(context1);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
60
|
+
const runBeforeRender = async (context2) => {
|
|
61
|
+
await runner.beforeRender(context2);
|
|
62
|
+
const init = getGlobalAppInit();
|
|
63
|
+
return init === null || init === void 0 ? void 0 : init(context2);
|
|
64
|
+
};
|
|
80
65
|
if (!id) {
|
|
81
66
|
return /* @__PURE__ */ React.createElement(App, {
|
|
82
67
|
_internal_context: context
|
|
@@ -105,7 +90,7 @@ const bootstrap = async (BootApp, id, root, ReactDOM) => {
|
|
|
105
90
|
} : {}
|
|
106
91
|
});
|
|
107
92
|
context.initialData = ssrData === null || ssrData === void 0 ? void 0 : (_ssrData_data1 = ssrData.data) === null || _ssrData_data1 === void 0 ? void 0 : _ssrData_data1.initialData;
|
|
108
|
-
const initialData = await
|
|
93
|
+
const initialData = await runBeforeRender(context);
|
|
109
94
|
if (initialData) {
|
|
110
95
|
context.initialData = initialData;
|
|
111
96
|
}
|
|
@@ -165,16 +150,11 @@ const useRuntimeContext = () => {
|
|
|
165
150
|
var _context_ssrContext, _context_ssrContext1;
|
|
166
151
|
const context = useContext(RuntimeReactContext);
|
|
167
152
|
const pickedContext = {
|
|
168
|
-
|
|
153
|
+
...context,
|
|
169
154
|
request: (_context_ssrContext = context.ssrContext) === null || _context_ssrContext === void 0 ? void 0 : _context_ssrContext.request,
|
|
170
155
|
response: (_context_ssrContext1 = context.ssrContext) === null || _context_ssrContext1 === void 0 ? void 0 : _context_ssrContext1.response
|
|
171
156
|
};
|
|
172
|
-
const memoizedContext = useMemo(() => context.runner.pickContext(
|
|
173
|
-
context,
|
|
174
|
-
pickedContext
|
|
175
|
-
}, {
|
|
176
|
-
onLast: ({ pickedContext: pickedContext2 }) => pickedContext2
|
|
177
|
-
}), [
|
|
157
|
+
const memoizedContext = useMemo(() => context.runner.pickContext(pickedContext), [
|
|
178
158
|
context
|
|
179
159
|
]);
|
|
180
160
|
return memoizedContext;
|
|
@@ -1,15 +1,24 @@
|
|
|
1
|
-
import { createManager,
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
1
|
+
import { createManager, createWaterfall, createAsyncInterruptWorkflow, createSyncParallelWorkflow, createContext } from "@modern-js/plugin";
|
|
2
|
+
const RuntimeConfigContext = createContext({});
|
|
3
|
+
const useRuntimeConfigContext = () => RuntimeConfigContext.use().value;
|
|
4
|
+
const wrapRoot = createWaterfall();
|
|
5
|
+
const beforeRender = createAsyncInterruptWorkflow();
|
|
6
|
+
const pickContext = createWaterfall();
|
|
7
|
+
const modifyRuntimeConfig = createSyncParallelWorkflow();
|
|
5
8
|
const runtimeHooks = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
pickContext
|
|
9
|
+
beforeRender,
|
|
10
|
+
wrapRoot,
|
|
11
|
+
pickContext,
|
|
12
|
+
modifyRuntimeConfig
|
|
9
13
|
};
|
|
10
|
-
const
|
|
14
|
+
const runtimePluginAPI = {
|
|
15
|
+
useRuntimeConfigContext
|
|
16
|
+
};
|
|
17
|
+
const createRuntime = () => createManager(runtimeHooks, runtimePluginAPI);
|
|
11
18
|
const runtime = createRuntime();
|
|
12
19
|
export {
|
|
20
|
+
RuntimeConfigContext,
|
|
13
21
|
createRuntime,
|
|
14
|
-
runtime
|
|
22
|
+
runtime,
|
|
23
|
+
useRuntimeConfigContext
|
|
15
24
|
};
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import { merge } from "
|
|
2
|
-
import { runtime } from "./base";
|
|
3
|
-
import { setGlobalRunner } from "./runner";
|
|
1
|
+
import { merge } from "@modern-js/runtime-utils/merge";
|
|
2
|
+
import { runtime, RuntimeConfigContext } from "./base";
|
|
3
|
+
import { getGlobalRunner, setGlobalRunner } from "./runner";
|
|
4
4
|
export * from "./base";
|
|
5
|
+
function setupConfigContext() {
|
|
6
|
+
const runner = getGlobalRunner();
|
|
7
|
+
const configs = runner.modifyRuntimeConfig();
|
|
8
|
+
RuntimeConfigContext.set(merge({}, ...configs));
|
|
9
|
+
}
|
|
5
10
|
function registerPlugin(internalPlugins, runtimeConfig, customRuntime) {
|
|
6
11
|
const { plugins = [] } = runtimeConfig || {};
|
|
7
12
|
(customRuntime || runtime).usePlugin(...internalPlugins, ...plugins);
|
|
8
13
|
const runner = (customRuntime || runtime).init();
|
|
9
14
|
setGlobalRunner(runner);
|
|
15
|
+
setupConfigContext();
|
|
10
16
|
return runner;
|
|
11
17
|
}
|
|
12
18
|
function mergeConfig(config, ...otherConfig) {
|
|
13
|
-
return merge(config, ...otherConfig);
|
|
19
|
+
return merge({}, config, ...otherConfig);
|
|
14
20
|
}
|
|
15
21
|
export {
|
|
16
22
|
mergeConfig,
|
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { RuntimeReactContext, getGlobalApp } from "../context";
|
|
3
3
|
import { getGlobalRunner } from "../plugin/runner";
|
|
4
|
-
function createRoot(UserApp
|
|
4
|
+
function createRoot(UserApp) {
|
|
5
5
|
const App = UserApp || getGlobalApp();
|
|
6
6
|
const runner = getGlobalRunner();
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
})
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
return WrapComponent;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
return HOCApp;
|
|
7
|
+
const WrapperApp = runner.wrapRoot(App);
|
|
8
|
+
const WrapComponent = ({ _internal_context, ...props }) => {
|
|
9
|
+
return /* @__PURE__ */ _jsx(RuntimeReactContext.Provider, {
|
|
10
|
+
value: _internal_context,
|
|
11
|
+
children: /* @__PURE__ */ _jsx(WrapperApp, {
|
|
12
|
+
...props
|
|
13
|
+
})
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
return WrapComponent;
|
|
24
17
|
}
|
|
25
18
|
export {
|
|
26
19
|
createRoot
|
|
@@ -7,7 +7,7 @@ import { createLoaderManager } from "../loader/loaderManager";
|
|
|
7
7
|
import { getSSRConfigByEntry, getSSRMode } from "./utils";
|
|
8
8
|
import { CHUNK_CSS_PLACEHOLDER } from "./constants";
|
|
9
9
|
function createSSRContext(request, options) {
|
|
10
|
-
const { config, loaderContext, onError, onTiming, locals, resource, params, responseProxy,
|
|
10
|
+
const { config, loaderContext, onError, onTiming, locals, resource, params, responseProxy, logger, metrics, reporter } = options;
|
|
11
11
|
const { nonce } = config;
|
|
12
12
|
const { entryName, route } = resource;
|
|
13
13
|
const cookie = request.headers.get("cookie");
|
|
@@ -16,7 +16,7 @@ function createSSRContext(request, options) {
|
|
|
16
16
|
const query = parseQuery(request);
|
|
17
17
|
const headersData = parseHeaders(request);
|
|
18
18
|
const url = new URL(request.url);
|
|
19
|
-
const ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries
|
|
19
|
+
const ssrConfig = getSSRConfigByEntry(entryName, config.ssr, config.ssrByEntries);
|
|
20
20
|
const ssrMode = getSSRMode(ssrConfig);
|
|
21
21
|
const loaderFailureMode = typeof ssrConfig === "object" ? ssrConfig.loaderFailureMode : void 0;
|
|
22
22
|
return {
|
|
@@ -60,14 +60,14 @@ const createRequestHandler = async (handleRequest) => {
|
|
|
60
60
|
const runner = getGlobalRunner();
|
|
61
61
|
const { routeManifest } = options.resource;
|
|
62
62
|
const context = getInitialContext(runner, false, routeManifest);
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const init = getGlobalAppInit();
|
|
68
|
-
return init === null || init === void 0 ? void 0 : init(context1);
|
|
63
|
+
const runBeforeRender = async (context2) => {
|
|
64
|
+
const result = await runner.beforeRender(context2);
|
|
65
|
+
if (typeof Response !== "undefined" && result instanceof Response) {
|
|
66
|
+
return result;
|
|
69
67
|
}
|
|
70
|
-
|
|
68
|
+
const init = getGlobalAppInit();
|
|
69
|
+
return init === null || init === void 0 ? void 0 : init(context2);
|
|
70
|
+
};
|
|
71
71
|
const responseProxy = {
|
|
72
72
|
headers: {},
|
|
73
73
|
code: -1
|
|
@@ -102,7 +102,7 @@ const createRequestHandler = async (handleRequest) => {
|
|
|
102
102
|
}
|
|
103
103
|
return void 0;
|
|
104
104
|
};
|
|
105
|
-
const initialData = await
|
|
105
|
+
const initialData = await runBeforeRender(context);
|
|
106
106
|
context.initialData = initialData;
|
|
107
107
|
const redirectResponse = getRedirectResponse(initialData);
|
|
108
108
|
if (redirectResponse) {
|