@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
|
@@ -28,6 +28,7 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
|
28
28
|
var import_react = require("react");
|
|
29
29
|
var import_router = require("@modern-js/runtime-utils/router");
|
|
30
30
|
var import_parsed = require("@modern-js/runtime-utils/parsed");
|
|
31
|
+
var import_merge = require("@modern-js/runtime-utils/merge");
|
|
31
32
|
var import_context = require("../../core/context");
|
|
32
33
|
var import_core = require("../../core");
|
|
33
34
|
var import_hooks = require("./hooks");
|
|
@@ -45,23 +46,17 @@ function modifyRoutes(modifyFunction) {
|
|
|
45
46
|
console.error("It is not allowed to modify routes config after create router.");
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
|
-
const routerPlugin = (
|
|
49
|
-
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
|
50
|
-
let routes = [];
|
|
51
|
-
finalRouteConfig = {
|
|
52
|
-
routes: (0, import_context.getGlobalRoutes)(),
|
|
53
|
-
globalApp: (0, import_context.getGlobalLayoutApp)(),
|
|
54
|
-
...routesConfig
|
|
55
|
-
};
|
|
56
|
-
window._SERVER_DATA = (0, import_parsed.parsedJSONFromElement)("__MODERN_SERVER_DATA__");
|
|
49
|
+
const routerPlugin = (userConfig = {}) => {
|
|
57
50
|
return {
|
|
58
51
|
name: "@modern-js/plugin-router",
|
|
59
52
|
registerHook: {
|
|
60
53
|
modifyRoutes: import_hooks.modifyRoutes
|
|
61
54
|
},
|
|
62
55
|
setup: (api) => {
|
|
56
|
+
let routes = [];
|
|
57
|
+
window._SERVER_DATA = (0, import_parsed.parsedJSONFromElement)("__MODERN_SERVER_DATA__");
|
|
63
58
|
return {
|
|
64
|
-
|
|
59
|
+
beforeRender(context) {
|
|
65
60
|
context.router = {
|
|
66
61
|
useMatches: import_router.useMatches,
|
|
67
62
|
useLocation: import_router.useLocation,
|
|
@@ -72,24 +67,26 @@ const routerPlugin = ({ serverBase = [], supportHtml5History = true, basename =
|
|
|
72
67
|
return routes;
|
|
73
68
|
}
|
|
74
69
|
});
|
|
75
|
-
return next({
|
|
76
|
-
context
|
|
77
|
-
});
|
|
78
70
|
},
|
|
79
|
-
|
|
71
|
+
wrapRoot: (App) => {
|
|
72
|
+
const pluginConfig = api.useRuntimeConfigContext();
|
|
73
|
+
const { serverBase = [], supportHtml5History = true, basename = "", routesConfig, createRoutes } = (0, import_merge.merge)(pluginConfig.router || {}, userConfig);
|
|
74
|
+
const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
|
|
75
|
+
finalRouteConfig = {
|
|
76
|
+
routes: (0, import_context.getGlobalRoutes)(),
|
|
77
|
+
globalApp: (0, import_context.getGlobalLayoutApp)(),
|
|
78
|
+
...routesConfig
|
|
79
|
+
};
|
|
80
80
|
if (!finalRouteConfig.routes && !createRoutes) {
|
|
81
|
-
return
|
|
82
|
-
App,
|
|
83
|
-
config
|
|
84
|
-
});
|
|
81
|
+
return App;
|
|
85
82
|
}
|
|
86
83
|
const getRouteApp = () => {
|
|
87
84
|
const useCreateRouter = (props) => {
|
|
88
|
-
var
|
|
89
|
-
const
|
|
85
|
+
var _window__SERVER_DATA;
|
|
86
|
+
const runtimeContext = (0, import_react.useContext)(import_core.RuntimeReactContext);
|
|
87
|
+
const 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(/^\/*/, "/");
|
|
90
88
|
const _basename = baseUrl === "/" ? (0, import_utils.urlJoin)(baseUrl, basename) : baseUrl;
|
|
91
89
|
let hydrationData = window._ROUTER_DATA;
|
|
92
|
-
const runtimeContext = (0, import_react.useContext)(import_core.RuntimeReactContext);
|
|
93
90
|
const { unstable_getBlockNavState: getBlockNavState } = runtimeContext;
|
|
94
91
|
return (0, import_react.useMemo)(() => {
|
|
95
92
|
if (hydrationData === null || hydrationData === void 0 ? void 0 : hydrationData.errors) {
|
|
@@ -126,7 +123,8 @@ const routerPlugin = ({ serverBase = [], supportHtml5History = true, basename =
|
|
|
126
123
|
get() {
|
|
127
124
|
return router;
|
|
128
125
|
},
|
|
129
|
-
configurable: true
|
|
126
|
+
configurable: true,
|
|
127
|
+
enumerable: true
|
|
130
128
|
});
|
|
131
129
|
return router;
|
|
132
130
|
}, [
|
|
@@ -145,33 +143,24 @@ const routerPlugin = ({ serverBase = [], supportHtml5History = true, basename =
|
|
|
145
143
|
});
|
|
146
144
|
};
|
|
147
145
|
};
|
|
148
|
-
|
|
149
|
-
return next({
|
|
150
|
-
App: RouteApp,
|
|
151
|
-
config
|
|
152
|
-
});
|
|
146
|
+
return getRouteApp();
|
|
153
147
|
},
|
|
154
|
-
pickContext: (
|
|
155
|
-
const { remixRouter } =
|
|
148
|
+
pickContext: (pickedContext) => {
|
|
149
|
+
const { remixRouter } = pickedContext;
|
|
156
150
|
if (!remixRouter) {
|
|
157
|
-
return
|
|
158
|
-
context,
|
|
159
|
-
pickedContext
|
|
160
|
-
});
|
|
151
|
+
return pickedContext;
|
|
161
152
|
}
|
|
162
153
|
const router = {
|
|
154
|
+
...pickedContext.router,
|
|
163
155
|
navigate: remixRouter.navigate,
|
|
164
156
|
get location() {
|
|
165
157
|
return remixRouter.state.location;
|
|
166
158
|
}
|
|
167
159
|
};
|
|
168
|
-
return
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
router
|
|
173
|
-
}
|
|
174
|
-
});
|
|
160
|
+
return {
|
|
161
|
+
...pickedContext,
|
|
162
|
+
router
|
|
163
|
+
};
|
|
175
164
|
}
|
|
176
165
|
};
|
|
177
166
|
}
|
|
@@ -40,6 +40,7 @@ var import_router2 = require("@modern-js/runtime-utils/router");
|
|
|
40
40
|
var import_node = require("@modern-js/runtime-utils/node");
|
|
41
41
|
var import_time = require("@modern-js/runtime-utils/time");
|
|
42
42
|
var import_constants = require("@modern-js/utils/universal/constants");
|
|
43
|
+
var import_merge = require("@modern-js/runtime-utils/merge");
|
|
43
44
|
var import_common = require("../../common");
|
|
44
45
|
var import_core = require("../../core");
|
|
45
46
|
var import_context = require("../../core/context");
|
|
@@ -56,25 +57,26 @@ function createRemixReuqest(request) {
|
|
|
56
57
|
signal: controller.signal
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
|
-
const routerPlugin = (
|
|
60
|
+
const routerPlugin = (userConfig = {}) => {
|
|
60
61
|
return {
|
|
61
62
|
name: "@modern-js/plugin-router",
|
|
62
63
|
registerHook: {
|
|
63
64
|
modifyRoutes: import_hooks.modifyRoutes
|
|
64
65
|
},
|
|
65
66
|
setup: (api) => {
|
|
66
|
-
|
|
67
|
-
routes: (0, import_context.getGlobalRoutes)(),
|
|
68
|
-
globalApp: (0, import_context.getGlobalLayoutApp)(),
|
|
69
|
-
...routesConfig
|
|
70
|
-
};
|
|
67
|
+
let finalRouteConfig = {};
|
|
71
68
|
return {
|
|
72
|
-
async
|
|
69
|
+
async beforeRender(context, interrupt) {
|
|
73
70
|
var _context_ssrContext, _context_ssrContext_onTiming, _context_ssrContext1;
|
|
71
|
+
const pluginConfig = api.useRuntimeConfigContext();
|
|
72
|
+
const { basename = "", routesConfig, createRoutes } = (0, import_merge.merge)(pluginConfig.router || {}, userConfig);
|
|
73
|
+
finalRouteConfig = {
|
|
74
|
+
routes: (0, import_context.getGlobalRoutes)(),
|
|
75
|
+
globalApp: (0, import_context.getGlobalLayoutApp)(),
|
|
76
|
+
...routesConfig
|
|
77
|
+
};
|
|
74
78
|
if (!finalRouteConfig.routes && !createRoutes) {
|
|
75
|
-
return
|
|
76
|
-
context
|
|
77
|
-
});
|
|
79
|
+
return;
|
|
78
80
|
}
|
|
79
81
|
const { request, mode: ssrMode, nonce, loaderFailureMode = "errorBoundary" } = context.ssrContext;
|
|
80
82
|
const { baseUrl } = request;
|
|
@@ -103,7 +105,7 @@ const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
|
|
|
103
105
|
const cost = end();
|
|
104
106
|
(_context_ssrContext1 = context.ssrContext) === null || _context_ssrContext1 === void 0 ? void 0 : (_context_ssrContext_onTiming = _context_ssrContext1.onTiming) === null || _context_ssrContext_onTiming === void 0 ? void 0 : _context_ssrContext_onTiming.call(_context_ssrContext1, import_constants.LOADER_REPORTER_NAME, cost);
|
|
105
107
|
if (routerContext instanceof Response) {
|
|
106
|
-
return routerContext;
|
|
108
|
+
return interrupt(routerContext);
|
|
107
109
|
}
|
|
108
110
|
if (routerContext.statusCode >= 500 && routerContext.statusCode < 600 && loaderFailureMode === "clientRender") {
|
|
109
111
|
routerContext.statusCode = 200;
|
|
@@ -113,20 +115,15 @@ const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
|
|
|
113
115
|
context.remixRouter = router;
|
|
114
116
|
context.routerContext = routerContext;
|
|
115
117
|
context.routes = routes;
|
|
116
|
-
return next({
|
|
117
|
-
context
|
|
118
|
-
});
|
|
119
118
|
},
|
|
120
|
-
|
|
119
|
+
wrapRoot: (App) => {
|
|
121
120
|
if (!finalRouteConfig) {
|
|
122
|
-
return
|
|
123
|
-
App,
|
|
124
|
-
config
|
|
125
|
-
});
|
|
121
|
+
return App;
|
|
126
122
|
}
|
|
127
123
|
const getRouteApp = () => {
|
|
128
124
|
return () => {
|
|
129
|
-
const
|
|
125
|
+
const context = (0, import_react.useContext)(import_core.RuntimeReactContext);
|
|
126
|
+
const { remixRouter, routerContext, ssrContext } = context;
|
|
130
127
|
const { nonce, mode } = ssrContext;
|
|
131
128
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
132
129
|
children: [
|
|
@@ -135,6 +132,8 @@ const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
|
|
|
135
132
|
context: routerContext,
|
|
136
133
|
hydrate: false
|
|
137
134
|
}),
|
|
135
|
+
mode === "stream" && // ROUTER_DATA will inject in `packages/runtime/plugin-runtime/src/core/server/string/ssrData.ts` in string ssr
|
|
136
|
+
// So we can inject it only when streaming ssr
|
|
138
137
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_DeferredDataScripts.default, {
|
|
139
138
|
nonce,
|
|
140
139
|
context: routerContext
|
|
@@ -144,19 +143,12 @@ const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
|
|
|
144
143
|
});
|
|
145
144
|
};
|
|
146
145
|
};
|
|
147
|
-
|
|
148
|
-
return next({
|
|
149
|
-
App: RouteApp,
|
|
150
|
-
config
|
|
151
|
-
});
|
|
146
|
+
return getRouteApp();
|
|
152
147
|
},
|
|
153
|
-
pickContext: (
|
|
154
|
-
const { remixRouter } =
|
|
148
|
+
pickContext: (pickedContext) => {
|
|
149
|
+
const { remixRouter } = pickedContext;
|
|
155
150
|
if (!remixRouter) {
|
|
156
|
-
return
|
|
157
|
-
context,
|
|
158
|
-
pickedContext
|
|
159
|
-
});
|
|
151
|
+
return pickedContext;
|
|
160
152
|
}
|
|
161
153
|
const router = {
|
|
162
154
|
navigate: remixRouter.navigate,
|
|
@@ -164,13 +156,10 @@ const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
|
|
|
164
156
|
return remixRouter.state.location;
|
|
165
157
|
}
|
|
166
158
|
};
|
|
167
|
-
return
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
router
|
|
172
|
-
}
|
|
173
|
-
});
|
|
159
|
+
return {
|
|
160
|
+
...pickedContext,
|
|
161
|
+
router
|
|
162
|
+
};
|
|
174
163
|
}
|
|
175
164
|
};
|
|
176
165
|
}
|
|
@@ -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
|
}
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -94,23 +94,22 @@ var runtimePlugin = function(params) {
|
|
|
94
94
|
var isReact18 = checkIsReact18(appDirectory);
|
|
95
95
|
process.env.IS_REACT18 = isReact18.toString();
|
|
96
96
|
var pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
|
|
97
|
+
var _obj;
|
|
97
98
|
return {
|
|
98
99
|
runtime: {},
|
|
99
100
|
runtimeByEntries: {},
|
|
100
101
|
source: {
|
|
101
|
-
alias: (
|
|
102
|
+
alias: (_obj = {
|
|
102
103
|
/**
|
|
103
|
-
*
|
|
104
|
+
* twin.macro inserts styled-components into the code during the compilation process
|
|
105
|
+
* But it will not be installed under the user project.
|
|
106
|
+
* So need to add alias
|
|
104
107
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
*/
|
|
111
|
-
"styled-components": require.resolve("styled-components")
|
|
112
|
-
}, "@".concat(metaName, "/runtime/plugins"), pluginsExportsUtils.getPath())
|
|
113
|
-
),
|
|
108
|
+
"styled-components": require.resolve("styled-components")
|
|
109
|
+
}, /**
|
|
110
|
+
* Compatible with the reference path of the old version of the plugin.
|
|
111
|
+
*/
|
|
112
|
+
_define_property(_obj, "@".concat(metaName, "/runtime/plugins"), pluginsExportsUtils.getPath()), _define_property(_obj, "@meta/runtime/browser", "@modern-js/runtime/browser"), _define_property(_obj, "@meta/runtime/react", "@modern-js/runtime/react"), _define_property(_obj, "@meta/runtime/context", "@modern-js/runtime/context"), _define_property(_obj, "@meta/runtime", "@modern-js/runtime"), _obj),
|
|
114
113
|
globalVars: {
|
|
115
114
|
"process.env.IS_REACT18": process.env.IS_REACT18
|
|
116
115
|
}
|
|
@@ -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
|
}
|