@modern-js/runtime 3.5.0 → 3.7.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 +1 -11
- package/dist/cjs/cli/ssr/index.js +3 -1
- package/dist/cjs/core/browser/hydrate.js +12 -11
- package/dist/cjs/core/browser/index.js +15 -40
- package/dist/cjs/router/runtime/plugin.js +6 -7
- package/dist/esm/cli/index.mjs +2 -12
- package/dist/esm/cli/ssr/index.mjs +3 -1
- package/dist/esm/core/browser/hydrate.mjs +11 -9
- package/dist/esm/core/browser/index.mjs +11 -30
- package/dist/esm/router/runtime/plugin.mjs +6 -7
- package/dist/esm-node/cli/index.mjs +2 -12
- package/dist/esm-node/cli/ssr/index.mjs +3 -1
- package/dist/esm-node/core/browser/hydrate.mjs +11 -9
- package/dist/esm-node/core/browser/index.mjs +11 -30
- package/dist/esm-node/core/server/stream/beforeTemplate.mjs +2 -2
- package/dist/esm-node/core/server/string/loadable.mjs +2 -2
- package/dist/esm-node/router/cli/index.mjs +2 -2
- package/dist/esm-node/router/runtime/plugin.mjs +6 -7
- package/dist/types/core/browser/hydrate.d.ts +3 -3
- package/dist/types/core/browser/index.d.ts +3 -4
- package/package.json +11 -11
package/dist/cjs/cli/index.js
CHANGED
|
@@ -101,12 +101,10 @@ const runtimePlugin = (params)=>({
|
|
|
101
101
|
});
|
|
102
102
|
api.config(()=>{
|
|
103
103
|
const { appDirectory, metaName } = api.getAppContext();
|
|
104
|
-
const isReact18 = (0, utils_namespaceObject.isReact18)(appDirectory);
|
|
105
|
-
process.env.IS_REACT18 = isReact18.toString();
|
|
106
104
|
return {
|
|
107
105
|
source: {
|
|
108
106
|
globalVars: {
|
|
109
|
-
'process.env.IS_REACT18':
|
|
107
|
+
'process.env.IS_REACT18': 'true'
|
|
110
108
|
},
|
|
111
109
|
include: [
|
|
112
110
|
new RegExp(`[\\\\/]node_modules[\\\\/]@${metaName}[\\\\/]runtime[\\\\/].*[\\\\/]head\\.`)
|
|
@@ -115,14 +113,6 @@ const runtimePlugin = (params)=>({
|
|
|
115
113
|
tools: {
|
|
116
114
|
bundlerChain: (chain)=>{
|
|
117
115
|
chain.module.rule('modern-entry').test(/\.jsx?$/).include.add(external_path_default().resolve(appDirectory, 'node_modules', `.${metaName}`)).end().sideEffects(true);
|
|
118
|
-
},
|
|
119
|
-
rspack: (_config, { appendPlugins, rspack })=>{
|
|
120
|
-
if (!isReact18) appendPlugins([
|
|
121
|
-
new rspack.IgnorePlugin({
|
|
122
|
-
resourceRegExp: /^react-dom\/client$/,
|
|
123
|
-
contextRegExp: /@modern-js\/runtime/
|
|
124
|
-
})
|
|
125
|
-
]);
|
|
126
116
|
}
|
|
127
117
|
}
|
|
128
118
|
};
|
|
@@ -76,7 +76,9 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
76
76
|
source: {
|
|
77
77
|
define: {
|
|
78
78
|
'process.env.MODERN_TARGET': isServerEnvironment ? JSON.stringify('node') : JSON.stringify('browser'),
|
|
79
|
-
'process.env.MODERN_SSR_ENV': JSON.stringify(ssrEnv)
|
|
79
|
+
'process.env.MODERN_SSR_ENV': JSON.stringify(ssrEnv),
|
|
80
|
+
'process.env.MODERN_ENABLE_HYDRATION': JSON.stringify((0, utils_namespaceObject.isUseSSRBundle)(userConfig)),
|
|
81
|
+
'process.env.MODERN_ENABLE_RSC': JSON.stringify(Boolean(userConfig.server?.rsc))
|
|
80
82
|
}
|
|
81
83
|
},
|
|
82
84
|
output: {
|
|
@@ -29,14 +29,20 @@ var __webpack_exports__ = {};
|
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
31
|
hydrateRoot: ()=>hydrateRoot,
|
|
32
|
-
|
|
32
|
+
hydrateWithReact: ()=>hydrateWithReact
|
|
33
33
|
});
|
|
34
34
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
35
35
|
const component_namespaceObject = require("@loadable/component");
|
|
36
|
+
const constants_namespaceObject = require("@modern-js/utils/universal/constants");
|
|
37
|
+
const client_namespaceObject = require("react-dom/client");
|
|
36
38
|
const external_constants_js_namespaceObject = require("../constants.js");
|
|
37
39
|
const wrapper_js_namespaceObject = require("../react/wrapper.js");
|
|
38
40
|
const external_withCallback_js_namespaceObject = require("./withCallback.js");
|
|
39
|
-
|
|
41
|
+
async function hydrateWithReact(App, rootElement) {
|
|
42
|
+
return (0, client_namespaceObject.hydrateRoot)(rootElement, App, {
|
|
43
|
+
identifierPrefix: constants_namespaceObject.SSR_HYDRATION_ID_PREFIX
|
|
44
|
+
});
|
|
45
|
+
}
|
|
40
46
|
function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
41
47
|
const hydrateContext = {
|
|
42
48
|
...context,
|
|
@@ -50,7 +56,7 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
50
56
|
};
|
|
51
57
|
const renderLevel = window?._SSR_DATA?.renderLevel || external_constants_js_namespaceObject.RenderLevel.CLIENT_RENDER;
|
|
52
58
|
const renderMode = window?._SSR_DATA?.mode || 'string';
|
|
53
|
-
if (
|
|
59
|
+
if ('stream' === renderMode) return streamSSRHydrate();
|
|
54
60
|
function streamSSRHydrate() {
|
|
55
61
|
if (renderLevel !== external_constants_js_namespaceObject.RenderLevel.SERVER_RENDER) return ModernRender((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, context));
|
|
56
62
|
{
|
|
@@ -65,7 +71,7 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
65
71
|
function stringSSRHydrate() {
|
|
66
72
|
if (renderLevel === external_constants_js_namespaceObject.RenderLevel.CLIENT_RENDER) return ModernRender((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, context));
|
|
67
73
|
if (renderLevel === external_constants_js_namespaceObject.RenderLevel.SERVER_RENDER) return new Promise((resolve)=>{
|
|
68
|
-
|
|
74
|
+
(0, component_namespaceObject.loadableReady)(()=>{
|
|
69
75
|
const SSRApp = ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_withCallback_js_namespaceObject.WithCallback, {
|
|
70
76
|
callback: callback,
|
|
71
77
|
children: App
|
|
@@ -74,21 +80,16 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
74
80
|
resolve(root);
|
|
75
81
|
});
|
|
76
82
|
});
|
|
77
|
-
else (0, component_namespaceObject.loadableReady)(()=>{
|
|
78
|
-
ModernHydrate((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, hydrateContext), callback).then((root)=>{
|
|
79
|
-
resolve(root);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
83
|
});
|
|
83
84
|
console.warn(`unknow render level: ${renderLevel}, execute render()`);
|
|
84
85
|
return ModernRender((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, context));
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
exports.hydrateRoot = __webpack_exports__.hydrateRoot;
|
|
88
|
-
exports.
|
|
89
|
+
exports.hydrateWithReact = __webpack_exports__.hydrateWithReact;
|
|
89
90
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
90
91
|
"hydrateRoot",
|
|
91
|
-
"
|
|
92
|
+
"hydrateWithReact"
|
|
92
93
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
93
94
|
Object.defineProperty(exports, '__esModule', {
|
|
94
95
|
value: true
|
|
@@ -37,20 +37,17 @@ var __webpack_require__ = {};
|
|
|
37
37
|
var __webpack_exports__ = {};
|
|
38
38
|
__webpack_require__.r(__webpack_exports__);
|
|
39
39
|
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
-
|
|
41
|
-
hydrateWithReact18: ()=>hydrateWithReact18,
|
|
40
|
+
hydrateWithReact: ()=>external_hydrate_js_namespaceObject.hydrateWithReact,
|
|
42
41
|
render: ()=>render,
|
|
43
|
-
|
|
44
|
-
renderWithReact18: ()=>renderWithReact18
|
|
42
|
+
renderWithReact: ()=>renderWithReact
|
|
45
43
|
});
|
|
46
|
-
const constants_namespaceObject = require("@modern-js/utils/universal/constants");
|
|
47
44
|
const external_cookie_namespaceObject = require("cookie");
|
|
48
45
|
var external_cookie_default = /*#__PURE__*/ __webpack_require__.n(external_cookie_namespaceObject);
|
|
46
|
+
const client_namespaceObject = require("react-dom/client");
|
|
49
47
|
const index_js_namespaceObject = require("../context/index.js");
|
|
50
48
|
const runtime_js_namespaceObject = require("../context/runtime.js");
|
|
51
49
|
const wrapper_js_namespaceObject = require("../react/wrapper.js");
|
|
52
50
|
const external_hydrate_js_namespaceObject = require("./hydrate.js");
|
|
53
|
-
const IS_REACT18 = 'true' === process.env.IS_REACT18;
|
|
54
51
|
const getQuery = ()=>window.location.search.substring(1).split('&').reduce((res, item)=>{
|
|
55
52
|
const [key, value] = item.split('=');
|
|
56
53
|
if (key) res[key] = value;
|
|
@@ -108,52 +105,30 @@ async function render(App, id) {
|
|
|
108
105
|
await runBeforeRender(context);
|
|
109
106
|
const rootElement = id && 'string' != typeof id ? id : document.getElementById(id || 'root');
|
|
110
107
|
async function ModernRender(App) {
|
|
111
|
-
|
|
112
|
-
return renderFunc(App, rootElement);
|
|
108
|
+
return renderWithReact(App, rootElement);
|
|
113
109
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
110
|
+
if (process.env.MODERN_ENABLE_HYDRATION && window._SSR_DATA) {
|
|
111
|
+
async function ModernHydrate(App) {
|
|
112
|
+
return (0, external_hydrate_js_namespaceObject.hydrateWithReact)(App, rootElement);
|
|
113
|
+
}
|
|
114
|
+
return (0, external_hydrate_js_namespaceObject.hydrateRoot)(App, context, ModernRender, ModernHydrate);
|
|
117
115
|
}
|
|
118
|
-
if (window._SSR_DATA) return (0, external_hydrate_js_namespaceObject.hydrateRoot)(App, context, ModernRender, ModernHydrate);
|
|
119
116
|
return ModernRender((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, context));
|
|
120
117
|
}
|
|
121
118
|
throw Error('`render` function needs id in browser environment, it needs to be string or element');
|
|
122
119
|
}
|
|
123
|
-
async function
|
|
124
|
-
const
|
|
125
|
-
const root = ReactDOM.createRoot(rootElement);
|
|
120
|
+
async function renderWithReact(App, rootElement) {
|
|
121
|
+
const root = (0, client_namespaceObject.createRoot)(rootElement);
|
|
126
122
|
root.render(App);
|
|
127
123
|
return root;
|
|
128
124
|
}
|
|
129
|
-
|
|
130
|
-
const ReactDOM = await import("react-dom");
|
|
131
|
-
ReactDOM.render(App, rootElement);
|
|
132
|
-
return rootElement;
|
|
133
|
-
}
|
|
134
|
-
async function hydrateWithReact18(App, rootElement) {
|
|
135
|
-
const ReactDOM = await import("react-dom/client");
|
|
136
|
-
const root = ReactDOM.hydrateRoot(rootElement, App, {
|
|
137
|
-
identifierPrefix: constants_namespaceObject.SSR_HYDRATION_ID_PREFIX
|
|
138
|
-
});
|
|
139
|
-
return root;
|
|
140
|
-
}
|
|
141
|
-
async function hydrateWithReact17(App, rootElement, callback) {
|
|
142
|
-
const ReactDOM = await import("react-dom");
|
|
143
|
-
const root = ReactDOM.hydrate(App, rootElement, callback);
|
|
144
|
-
return root;
|
|
145
|
-
}
|
|
146
|
-
exports.hydrateWithReact17 = __webpack_exports__.hydrateWithReact17;
|
|
147
|
-
exports.hydrateWithReact18 = __webpack_exports__.hydrateWithReact18;
|
|
125
|
+
exports.hydrateWithReact = __webpack_exports__.hydrateWithReact;
|
|
148
126
|
exports.render = __webpack_exports__.render;
|
|
149
|
-
exports.
|
|
150
|
-
exports.renderWithReact18 = __webpack_exports__.renderWithReact18;
|
|
127
|
+
exports.renderWithReact = __webpack_exports__.renderWithReact;
|
|
151
128
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
152
|
-
"
|
|
153
|
-
"hydrateWithReact18",
|
|
129
|
+
"hydrateWithReact",
|
|
154
130
|
"render",
|
|
155
|
-
"
|
|
156
|
-
"renderWithReact18"
|
|
131
|
+
"renderWithReact"
|
|
157
132
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
158
133
|
Object.defineProperty(exports, '__esModule', {
|
|
159
134
|
value: true
|
|
@@ -101,10 +101,10 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
101
101
|
};
|
|
102
102
|
let cachedRouter = null;
|
|
103
103
|
const RouterWrapper = (props)=>{
|
|
104
|
-
const routerResult = useRouterCreation({
|
|
104
|
+
const routerResult = useRouterCreation(process.env.MODERN_ENABLE_RSC ? {
|
|
105
105
|
...props,
|
|
106
106
|
rscPayload: props?.rscPayload
|
|
107
|
-
}, {
|
|
107
|
+
} : props, {
|
|
108
108
|
api: api,
|
|
109
109
|
createRoutes,
|
|
110
110
|
supportHtml5History,
|
|
@@ -158,16 +158,15 @@ function useRouterCreation(props, options) {
|
|
|
158
158
|
const baseUrl = selectBasePath(location.pathname).replace(/^\/*/, '/');
|
|
159
159
|
const _basename = '/' === baseUrl ? (0, external_utils_js_namespaceObject.urlJoin)(baseUrl, runtimeContext._internalRouterBaseName || basename || '') : baseUrl;
|
|
160
160
|
const { unstable_getBlockNavState: getBlockNavState } = runtimeContext;
|
|
161
|
-
const rscPayload = props?.rscPayload ? safeUse(props.rscPayload) : null;
|
|
162
|
-
let hydrationData = window._ROUTER_DATA || rscPayload;
|
|
161
|
+
const rscPayload = process.env.MODERN_ENABLE_RSC && props?.rscPayload ? safeUse(props.rscPayload) : null;
|
|
162
|
+
let hydrationData = process.env.MODERN_ENABLE_RSC ? window._ROUTER_DATA || rscPayload : window._ROUTER_DATA;
|
|
163
163
|
return (0, external_react_namespaceObject.useMemo)(()=>{
|
|
164
164
|
if (hydrationData?.errors) hydrationData = {
|
|
165
165
|
...hydrationData,
|
|
166
166
|
errors: (0, external_utils_js_namespaceObject.deserializeErrors)(hydrationData.errors)
|
|
167
167
|
};
|
|
168
|
-
const isRscClient = (0, index_js_namespaceObject.getGlobalIsRscClient)();
|
|
169
168
|
let routes = null;
|
|
170
|
-
routes =
|
|
169
|
+
routes = process.env.MODERN_ENABLE_RSC && (0, index_js_namespaceObject.getGlobalIsRscClient)() ? createRoutes ? createRoutes() : (0, external_utils_js_namespaceObject.createRouteObjectsFromConfig)({
|
|
171
170
|
routesConfig: finalRouteConfig
|
|
172
171
|
}) : createRoutes ? createRoutes() : (0, router_namespaceObject.createRoutesFromElements)((0, external_utils_js_namespaceObject.renderRoutes)({
|
|
173
172
|
routesConfig: finalRouteConfig,
|
|
@@ -175,7 +174,7 @@ function useRouterCreation(props, options) {
|
|
|
175
174
|
}));
|
|
176
175
|
if (!routes) routes = [];
|
|
177
176
|
const hooks = api.getHooks();
|
|
178
|
-
if (rscPayload) try {
|
|
177
|
+
if (process.env.MODERN_ENABLE_RSC && rscPayload) try {
|
|
179
178
|
const router = (0, external_rsc_router_js_namespaceObject.createClientRouterFromPayload)(rscPayload, routes, _basename);
|
|
180
179
|
return {
|
|
181
180
|
router,
|
package/dist/esm/cli/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path_0 from "path";
|
|
2
|
-
import { cleanRequireCache
|
|
2
|
+
import { cleanRequireCache } from "@modern-js/utils";
|
|
3
3
|
import { documentPlugin } from "../document/cli/index.mjs";
|
|
4
4
|
import { routerPlugin } from "../router/cli/index.mjs";
|
|
5
5
|
import { builderPluginAlias } from "./alias.mjs";
|
|
@@ -54,12 +54,10 @@ const runtimePlugin = (params)=>({
|
|
|
54
54
|
});
|
|
55
55
|
api.config(()=>{
|
|
56
56
|
const { appDirectory, metaName } = api.getAppContext();
|
|
57
|
-
const isReact18 = utils_isReact18(appDirectory);
|
|
58
|
-
process.env.IS_REACT18 = isReact18.toString();
|
|
59
57
|
return {
|
|
60
58
|
source: {
|
|
61
59
|
globalVars: {
|
|
62
|
-
'process.env.IS_REACT18':
|
|
60
|
+
'process.env.IS_REACT18': 'true'
|
|
63
61
|
},
|
|
64
62
|
include: [
|
|
65
63
|
new RegExp(`[\\\\/]node_modules[\\\\/]@${metaName}[\\\\/]runtime[\\\\/].*[\\\\/]head\\.`)
|
|
@@ -68,14 +66,6 @@ const runtimePlugin = (params)=>({
|
|
|
68
66
|
tools: {
|
|
69
67
|
bundlerChain: (chain)=>{
|
|
70
68
|
chain.module.rule('modern-entry').test(/\.jsx?$/).include.add(path_0.resolve(appDirectory, 'node_modules', `.${metaName}`)).end().sideEffects(true);
|
|
71
|
-
},
|
|
72
|
-
rspack: (_config, { appendPlugins, rspack })=>{
|
|
73
|
-
if (!isReact18) appendPlugins([
|
|
74
|
-
new rspack.IgnorePlugin({
|
|
75
|
-
resourceRegExp: /^react-dom\/client$/,
|
|
76
|
-
contextRegExp: /@modern-js\/runtime/
|
|
77
|
-
})
|
|
78
|
-
]);
|
|
79
69
|
}
|
|
80
70
|
}
|
|
81
71
|
};
|
|
@@ -32,7 +32,9 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
32
32
|
source: {
|
|
33
33
|
define: {
|
|
34
34
|
'process.env.MODERN_TARGET': isServerEnvironment ? JSON.stringify('node') : JSON.stringify('browser'),
|
|
35
|
-
'process.env.MODERN_SSR_ENV': JSON.stringify(ssrEnv)
|
|
35
|
+
'process.env.MODERN_SSR_ENV': JSON.stringify(ssrEnv),
|
|
36
|
+
'process.env.MODERN_ENABLE_HYDRATION': JSON.stringify(isUseSSRBundle(userConfig)),
|
|
37
|
+
'process.env.MODERN_ENABLE_RSC': JSON.stringify(Boolean(userConfig.server?.rsc))
|
|
36
38
|
}
|
|
37
39
|
},
|
|
38
40
|
output: {
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { loadableReady } from "@loadable/component";
|
|
3
|
+
import { SSR_HYDRATION_ID_PREFIX } from "@modern-js/utils/universal/constants";
|
|
4
|
+
import { hydrateRoot } from "react-dom/client";
|
|
3
5
|
import { RenderLevel } from "../constants.mjs";
|
|
4
6
|
import { wrapRuntimeContextProvider } from "../react/wrapper.mjs";
|
|
5
7
|
import { WithCallback } from "./withCallback.mjs";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
async function hydrateWithReact(App, rootElement) {
|
|
9
|
+
return hydrateRoot(rootElement, App, {
|
|
10
|
+
identifierPrefix: SSR_HYDRATION_ID_PREFIX
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
8
14
|
const hydrateContext = {
|
|
9
15
|
...context,
|
|
10
16
|
get routes () {
|
|
@@ -17,7 +23,7 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
17
23
|
};
|
|
18
24
|
const renderLevel = window?._SSR_DATA?.renderLevel || RenderLevel.CLIENT_RENDER;
|
|
19
25
|
const renderMode = window?._SSR_DATA?.mode || 'string';
|
|
20
|
-
if (
|
|
26
|
+
if ('stream' === renderMode) return streamSSRHydrate();
|
|
21
27
|
function streamSSRHydrate() {
|
|
22
28
|
if (renderLevel !== RenderLevel.SERVER_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
23
29
|
{
|
|
@@ -32,7 +38,7 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
32
38
|
function stringSSRHydrate() {
|
|
33
39
|
if (renderLevel === RenderLevel.CLIENT_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
34
40
|
if (renderLevel === RenderLevel.SERVER_RENDER) return new Promise((resolve)=>{
|
|
35
|
-
|
|
41
|
+
loadableReady(()=>{
|
|
36
42
|
const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
|
|
37
43
|
callback: callback,
|
|
38
44
|
children: App
|
|
@@ -40,14 +46,10 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
40
46
|
ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext)).then((root)=>{
|
|
41
47
|
resolve(root);
|
|
42
48
|
});
|
|
43
|
-
}) : loadableReady(()=>{
|
|
44
|
-
ModernHydrate(wrapRuntimeContextProvider(App, hydrateContext), callback).then((root)=>{
|
|
45
|
-
resolve(root);
|
|
46
|
-
});
|
|
47
49
|
});
|
|
48
50
|
});
|
|
49
51
|
console.warn(`unknow render level: ${renderLevel}, execute render()`);
|
|
50
52
|
return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
|
-
export {
|
|
55
|
+
export { hydrateWithReact, hydrate_hydrateRoot as hydrateRoot };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { SSR_HYDRATION_ID_PREFIX } from "@modern-js/utils/universal/constants";
|
|
2
1
|
import cookie from "cookie";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
3
|
import { getGlobalInternalRuntimeContext } from "../context/index.mjs";
|
|
4
4
|
import { getInitialContext } from "../context/runtime.mjs";
|
|
5
5
|
import { wrapRuntimeContextProvider } from "../react/wrapper.mjs";
|
|
6
|
-
import { hydrateRoot } from "./hydrate.mjs";
|
|
7
|
-
const IS_REACT18 = 'true' === process.env.IS_REACT18;
|
|
6
|
+
import { hydrateRoot, hydrateWithReact } from "./hydrate.mjs";
|
|
8
7
|
const getQuery = ()=>window.location.search.substring(1).split('&').reduce((res, item)=>{
|
|
9
8
|
const [key, value] = item.split('=');
|
|
10
9
|
if (key) res[key] = value;
|
|
@@ -62,39 +61,21 @@ async function render(App, id) {
|
|
|
62
61
|
await runBeforeRender(context);
|
|
63
62
|
const rootElement = id && 'string' != typeof id ? id : document.getElementById(id || 'root');
|
|
64
63
|
async function ModernRender(App) {
|
|
65
|
-
|
|
66
|
-
return renderFunc(App, rootElement);
|
|
64
|
+
return renderWithReact(App, rootElement);
|
|
67
65
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
if (process.env.MODERN_ENABLE_HYDRATION && window._SSR_DATA) {
|
|
67
|
+
async function ModernHydrate(App) {
|
|
68
|
+
return hydrateWithReact(App, rootElement);
|
|
69
|
+
}
|
|
70
|
+
return hydrateRoot(App, context, ModernRender, ModernHydrate);
|
|
71
71
|
}
|
|
72
|
-
if (window._SSR_DATA) return hydrateRoot(App, context, ModernRender, ModernHydrate);
|
|
73
72
|
return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
74
73
|
}
|
|
75
74
|
throw Error('`render` function needs id in browser environment, it needs to be string or element');
|
|
76
75
|
}
|
|
77
|
-
async function
|
|
78
|
-
const
|
|
79
|
-
const root = ReactDOM.createRoot(rootElement);
|
|
76
|
+
async function renderWithReact(App, rootElement) {
|
|
77
|
+
const root = createRoot(rootElement);
|
|
80
78
|
root.render(App);
|
|
81
79
|
return root;
|
|
82
80
|
}
|
|
83
|
-
|
|
84
|
-
const ReactDOM = await import("react-dom");
|
|
85
|
-
ReactDOM.render(App, rootElement);
|
|
86
|
-
return rootElement;
|
|
87
|
-
}
|
|
88
|
-
async function hydrateWithReact18(App, rootElement) {
|
|
89
|
-
const ReactDOM = await import("react-dom/client");
|
|
90
|
-
const root = ReactDOM.hydrateRoot(rootElement, App, {
|
|
91
|
-
identifierPrefix: SSR_HYDRATION_ID_PREFIX
|
|
92
|
-
});
|
|
93
|
-
return root;
|
|
94
|
-
}
|
|
95
|
-
async function hydrateWithReact17(App, rootElement, callback) {
|
|
96
|
-
const ReactDOM = await import("react-dom");
|
|
97
|
-
const root = ReactDOM.hydrate(App, rootElement, callback);
|
|
98
|
-
return root;
|
|
99
|
-
}
|
|
100
|
-
export { hydrateWithReact17, hydrateWithReact18, render, renderWithReact17, renderWithReact18 };
|
|
81
|
+
export { hydrateWithReact, render, renderWithReact };
|
|
@@ -66,10 +66,10 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
66
66
|
};
|
|
67
67
|
let cachedRouter = null;
|
|
68
68
|
const RouterWrapper = (props)=>{
|
|
69
|
-
const routerResult = useRouterCreation({
|
|
69
|
+
const routerResult = useRouterCreation(process.env.MODERN_ENABLE_RSC ? {
|
|
70
70
|
...props,
|
|
71
71
|
rscPayload: props?.rscPayload
|
|
72
|
-
}, {
|
|
72
|
+
} : props, {
|
|
73
73
|
api: api,
|
|
74
74
|
createRoutes,
|
|
75
75
|
supportHtml5History,
|
|
@@ -123,16 +123,15 @@ function useRouterCreation(props, options) {
|
|
|
123
123
|
const baseUrl = selectBasePath(location.pathname).replace(/^\/*/, '/');
|
|
124
124
|
const _basename = '/' === baseUrl ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || basename || '') : baseUrl;
|
|
125
125
|
const { unstable_getBlockNavState: getBlockNavState } = runtimeContext;
|
|
126
|
-
const rscPayload = props?.rscPayload ? safeUse(props.rscPayload) : null;
|
|
127
|
-
let hydrationData = window._ROUTER_DATA || rscPayload;
|
|
126
|
+
const rscPayload = process.env.MODERN_ENABLE_RSC && props?.rscPayload ? safeUse(props.rscPayload) : null;
|
|
127
|
+
let hydrationData = process.env.MODERN_ENABLE_RSC ? window._ROUTER_DATA || rscPayload : window._ROUTER_DATA;
|
|
128
128
|
return (0, __rspack_external_react.useMemo)(()=>{
|
|
129
129
|
if (hydrationData?.errors) hydrationData = {
|
|
130
130
|
...hydrationData,
|
|
131
131
|
errors: deserializeErrors(hydrationData.errors)
|
|
132
132
|
};
|
|
133
|
-
const isRscClient = getGlobalIsRscClient();
|
|
134
133
|
let routes = null;
|
|
135
|
-
routes =
|
|
134
|
+
routes = process.env.MODERN_ENABLE_RSC && getGlobalIsRscClient() ? createRoutes ? createRoutes() : createRouteObjectsFromConfig({
|
|
136
135
|
routesConfig: finalRouteConfig
|
|
137
136
|
}) : createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
|
|
138
137
|
routesConfig: finalRouteConfig,
|
|
@@ -140,7 +139,7 @@ function useRouterCreation(props, options) {
|
|
|
140
139
|
}));
|
|
141
140
|
if (!routes) routes = [];
|
|
142
141
|
const hooks = api.getHooks();
|
|
143
|
-
if (rscPayload) try {
|
|
142
|
+
if (process.env.MODERN_ENABLE_RSC && rscPayload) try {
|
|
144
143
|
const router = createClientRouterFromPayload(rscPayload, routes, _basename);
|
|
145
144
|
return {
|
|
146
145
|
router,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import __rslib_shim_module__ from "node:module";
|
|
2
2
|
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
|
|
3
3
|
import path_0 from "path";
|
|
4
|
-
import { cleanRequireCache
|
|
4
|
+
import { cleanRequireCache } from "@modern-js/utils";
|
|
5
5
|
import { documentPlugin } from "../document/cli/index.mjs";
|
|
6
6
|
import { routerPlugin } from "../router/cli/index.mjs";
|
|
7
7
|
import { builderPluginAlias } from "./alias.mjs";
|
|
@@ -56,12 +56,10 @@ const runtimePlugin = (params)=>({
|
|
|
56
56
|
});
|
|
57
57
|
api.config(()=>{
|
|
58
58
|
const { appDirectory, metaName } = api.getAppContext();
|
|
59
|
-
const isReact18 = utils_isReact18(appDirectory);
|
|
60
|
-
process.env.IS_REACT18 = isReact18.toString();
|
|
61
59
|
return {
|
|
62
60
|
source: {
|
|
63
61
|
globalVars: {
|
|
64
|
-
'process.env.IS_REACT18':
|
|
62
|
+
'process.env.IS_REACT18': 'true'
|
|
65
63
|
},
|
|
66
64
|
include: [
|
|
67
65
|
new RegExp(`[\\\\/]node_modules[\\\\/]@${metaName}[\\\\/]runtime[\\\\/].*[\\\\/]head\\.`)
|
|
@@ -70,14 +68,6 @@ const runtimePlugin = (params)=>({
|
|
|
70
68
|
tools: {
|
|
71
69
|
bundlerChain: (chain)=>{
|
|
72
70
|
chain.module.rule('modern-entry').test(/\.jsx?$/).include.add(path_0.resolve(appDirectory, 'node_modules', `.${metaName}`)).end().sideEffects(true);
|
|
73
|
-
},
|
|
74
|
-
rspack: (_config, { appendPlugins, rspack })=>{
|
|
75
|
-
if (!isReact18) appendPlugins([
|
|
76
|
-
new rspack.IgnorePlugin({
|
|
77
|
-
resourceRegExp: /^react-dom\/client$/,
|
|
78
|
-
contextRegExp: /@modern-js\/runtime/
|
|
79
|
-
})
|
|
80
|
-
]);
|
|
81
71
|
}
|
|
82
72
|
}
|
|
83
73
|
};
|
|
@@ -34,7 +34,9 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
34
34
|
source: {
|
|
35
35
|
define: {
|
|
36
36
|
'process.env.MODERN_TARGET': isServerEnvironment ? JSON.stringify('node') : JSON.stringify('browser'),
|
|
37
|
-
'process.env.MODERN_SSR_ENV': JSON.stringify(ssrEnv)
|
|
37
|
+
'process.env.MODERN_SSR_ENV': JSON.stringify(ssrEnv),
|
|
38
|
+
'process.env.MODERN_ENABLE_HYDRATION': JSON.stringify(isUseSSRBundle(userConfig)),
|
|
39
|
+
'process.env.MODERN_ENABLE_RSC': JSON.stringify(Boolean(userConfig.server?.rsc))
|
|
38
40
|
}
|
|
39
41
|
},
|
|
40
42
|
output: {
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { loadableReady } from "@loadable/component";
|
|
4
|
+
import { SSR_HYDRATION_ID_PREFIX } from "@modern-js/utils/universal/constants";
|
|
5
|
+
import { hydrateRoot } from "react-dom/client";
|
|
4
6
|
import { RenderLevel } from "../constants.mjs";
|
|
5
7
|
import { wrapRuntimeContextProvider } from "../react/wrapper.mjs";
|
|
6
8
|
import { WithCallback } from "./withCallback.mjs";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
async function hydrateWithReact(App, rootElement) {
|
|
10
|
+
return hydrateRoot(rootElement, App, {
|
|
11
|
+
identifierPrefix: SSR_HYDRATION_ID_PREFIX
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
9
15
|
const hydrateContext = {
|
|
10
16
|
...context,
|
|
11
17
|
get routes () {
|
|
@@ -18,7 +24,7 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
18
24
|
};
|
|
19
25
|
const renderLevel = window?._SSR_DATA?.renderLevel || RenderLevel.CLIENT_RENDER;
|
|
20
26
|
const renderMode = window?._SSR_DATA?.mode || 'string';
|
|
21
|
-
if (
|
|
27
|
+
if ('stream' === renderMode) return streamSSRHydrate();
|
|
22
28
|
function streamSSRHydrate() {
|
|
23
29
|
if (renderLevel !== RenderLevel.SERVER_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
24
30
|
{
|
|
@@ -33,7 +39,7 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
33
39
|
function stringSSRHydrate() {
|
|
34
40
|
if (renderLevel === RenderLevel.CLIENT_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
35
41
|
if (renderLevel === RenderLevel.SERVER_RENDER) return new Promise((resolve)=>{
|
|
36
|
-
|
|
42
|
+
loadableReady(()=>{
|
|
37
43
|
const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
|
|
38
44
|
callback: callback,
|
|
39
45
|
children: App
|
|
@@ -41,14 +47,10 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
41
47
|
ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext)).then((root)=>{
|
|
42
48
|
resolve(root);
|
|
43
49
|
});
|
|
44
|
-
}) : loadableReady(()=>{
|
|
45
|
-
ModernHydrate(wrapRuntimeContextProvider(App, hydrateContext), callback).then((root)=>{
|
|
46
|
-
resolve(root);
|
|
47
|
-
});
|
|
48
50
|
});
|
|
49
51
|
});
|
|
50
52
|
console.warn(`unknow render level: ${renderLevel}, execute render()`);
|
|
51
53
|
return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
|
-
export {
|
|
56
|
+
export { hydrateWithReact, hydrate_hydrateRoot as hydrateRoot };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import { SSR_HYDRATION_ID_PREFIX } from "@modern-js/utils/universal/constants";
|
|
3
2
|
import cookie from "cookie";
|
|
3
|
+
import { createRoot } from "react-dom/client";
|
|
4
4
|
import { getGlobalInternalRuntimeContext } from "../context/index.mjs";
|
|
5
5
|
import { getInitialContext } from "../context/runtime.mjs";
|
|
6
6
|
import { wrapRuntimeContextProvider } from "../react/wrapper.mjs";
|
|
7
|
-
import { hydrateRoot } from "./hydrate.mjs";
|
|
8
|
-
const IS_REACT18 = 'true' === process.env.IS_REACT18;
|
|
7
|
+
import { hydrateRoot, hydrateWithReact } from "./hydrate.mjs";
|
|
9
8
|
const getQuery = ()=>window.location.search.substring(1).split('&').reduce((res, item)=>{
|
|
10
9
|
const [key, value] = item.split('=');
|
|
11
10
|
if (key) res[key] = value;
|
|
@@ -63,39 +62,21 @@ async function render(App, id) {
|
|
|
63
62
|
await runBeforeRender(context);
|
|
64
63
|
const rootElement = id && 'string' != typeof id ? id : document.getElementById(id || 'root');
|
|
65
64
|
async function ModernRender(App) {
|
|
66
|
-
|
|
67
|
-
return renderFunc(App, rootElement);
|
|
65
|
+
return renderWithReact(App, rootElement);
|
|
68
66
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
if (process.env.MODERN_ENABLE_HYDRATION && window._SSR_DATA) {
|
|
68
|
+
async function ModernHydrate(App) {
|
|
69
|
+
return hydrateWithReact(App, rootElement);
|
|
70
|
+
}
|
|
71
|
+
return hydrateRoot(App, context, ModernRender, ModernHydrate);
|
|
72
72
|
}
|
|
73
|
-
if (window._SSR_DATA) return hydrateRoot(App, context, ModernRender, ModernHydrate);
|
|
74
73
|
return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
75
74
|
}
|
|
76
75
|
throw Error('`render` function needs id in browser environment, it needs to be string or element');
|
|
77
76
|
}
|
|
78
|
-
async function
|
|
79
|
-
const
|
|
80
|
-
const root = ReactDOM.createRoot(rootElement);
|
|
77
|
+
async function renderWithReact(App, rootElement) {
|
|
78
|
+
const root = createRoot(rootElement);
|
|
81
79
|
root.render(App);
|
|
82
80
|
return root;
|
|
83
81
|
}
|
|
84
|
-
|
|
85
|
-
const ReactDOM = await import("react-dom");
|
|
86
|
-
ReactDOM.render(App, rootElement);
|
|
87
|
-
return rootElement;
|
|
88
|
-
}
|
|
89
|
-
async function hydrateWithReact18(App, rootElement) {
|
|
90
|
-
const ReactDOM = await import("react-dom/client");
|
|
91
|
-
const root = ReactDOM.hydrateRoot(rootElement, App, {
|
|
92
|
-
identifierPrefix: SSR_HYDRATION_ID_PREFIX
|
|
93
|
-
});
|
|
94
|
-
return root;
|
|
95
|
-
}
|
|
96
|
-
async function hydrateWithReact17(App, rootElement, callback) {
|
|
97
|
-
const ReactDOM = await import("react-dom");
|
|
98
|
-
const root = ReactDOM.hydrate(App, rootElement, callback);
|
|
99
|
-
return root;
|
|
100
|
-
}
|
|
101
|
-
export { hydrateWithReact17, hydrateWithReact18, render, renderWithReact17, renderWithReact18 };
|
|
82
|
+
export { hydrateWithReact, render, renderWithReact };
|
|
@@ -7,11 +7,11 @@ import { buildHtml } from "../shared.mjs";
|
|
|
7
7
|
import { checkIsNode, hasStylesheetLink, safeReplace } from "../utils.mjs";
|
|
8
8
|
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
9
9
|
import { dirname as __rspack_dirname } from "node:path";
|
|
10
|
-
var
|
|
10
|
+
var __rspack_import_meta_dirname__ = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
|
|
11
11
|
const readAsset = async (chunk)=>{
|
|
12
12
|
const fs = await import("fs/promises");
|
|
13
13
|
const path = await import("path");
|
|
14
|
-
const filepath = path.join(
|
|
14
|
+
const filepath = path.join(__rspack_import_meta_dirname__, chunk);
|
|
15
15
|
return fs.readFile(filepath, 'utf-8');
|
|
16
16
|
};
|
|
17
17
|
const checkIsInline = (chunk, enableInline)=>{
|
|
@@ -3,7 +3,7 @@ import { ChunkExtractor } from "@loadable/server";
|
|
|
3
3
|
import { attributesToString, checkIsNode, hasStylesheetLink } from "../utils.mjs";
|
|
4
4
|
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
5
5
|
import { dirname as __rspack_dirname } from "node:path";
|
|
6
|
-
var
|
|
6
|
+
var __rspack_import_meta_dirname__ = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
|
|
7
7
|
const extname = (uri)=>{
|
|
8
8
|
if ('string' != typeof uri || !uri.includes('.')) return '';
|
|
9
9
|
return `.${uri?.split('.').pop()}` || '';
|
|
@@ -17,7 +17,7 @@ const checkIsInline = (chunk, enableInline)=>{
|
|
|
17
17
|
const readAsset = async (chunk)=>{
|
|
18
18
|
const fs = await import("fs/promises");
|
|
19
19
|
const path = await import("path");
|
|
20
|
-
const filepath = path.resolve(
|
|
20
|
+
const filepath = path.resolve(__rspack_import_meta_dirname__, chunk.filename);
|
|
21
21
|
return fs.readFile(filepath, 'utf-8');
|
|
22
22
|
};
|
|
23
23
|
class LoadableCollector {
|
|
@@ -5,7 +5,7 @@ import { isRouteEntry } from "./entry.mjs";
|
|
|
5
5
|
import { handleFileChange, handleGeneratorEntryCode, handleModifyEntrypoints } from "./handler.mjs";
|
|
6
6
|
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
7
7
|
import { dirname as __rspack_dirname } from "node:path";
|
|
8
|
-
var
|
|
8
|
+
var __rspack_import_meta_dirname__ = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
|
|
9
9
|
const routerPlugin = ()=>({
|
|
10
10
|
name: '@modern-js/plugin-router',
|
|
11
11
|
required: [
|
|
@@ -46,7 +46,7 @@ const routerPlugin = ()=>({
|
|
|
46
46
|
include: [
|
|
47
47
|
/[\\/]node_modules[\\/]react-router[\\/]/,
|
|
48
48
|
/[\\/]node_modules[\\/]react-router-dom[\\/]/,
|
|
49
|
-
node_path.resolve(
|
|
49
|
+
node_path.resolve(__rspack_import_meta_dirname__, '../runtime').replace('cjs', 'esm')
|
|
50
50
|
]
|
|
51
51
|
}
|
|
52
52
|
}));
|
|
@@ -67,10 +67,10 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
67
67
|
};
|
|
68
68
|
let cachedRouter = null;
|
|
69
69
|
const RouterWrapper = (props)=>{
|
|
70
|
-
const routerResult = useRouterCreation({
|
|
70
|
+
const routerResult = useRouterCreation(process.env.MODERN_ENABLE_RSC ? {
|
|
71
71
|
...props,
|
|
72
72
|
rscPayload: props?.rscPayload
|
|
73
|
-
}, {
|
|
73
|
+
} : props, {
|
|
74
74
|
api: api,
|
|
75
75
|
createRoutes,
|
|
76
76
|
supportHtml5History,
|
|
@@ -124,16 +124,15 @@ function useRouterCreation(props, options) {
|
|
|
124
124
|
const baseUrl = selectBasePath(location.pathname).replace(/^\/*/, '/');
|
|
125
125
|
const _basename = '/' === baseUrl ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || basename || '') : baseUrl;
|
|
126
126
|
const { unstable_getBlockNavState: getBlockNavState } = runtimeContext;
|
|
127
|
-
const rscPayload = props?.rscPayload ? safeUse(props.rscPayload) : null;
|
|
128
|
-
let hydrationData = window._ROUTER_DATA || rscPayload;
|
|
127
|
+
const rscPayload = process.env.MODERN_ENABLE_RSC && props?.rscPayload ? safeUse(props.rscPayload) : null;
|
|
128
|
+
let hydrationData = process.env.MODERN_ENABLE_RSC ? window._ROUTER_DATA || rscPayload : window._ROUTER_DATA;
|
|
129
129
|
return (0, __rspack_external_react.useMemo)(()=>{
|
|
130
130
|
if (hydrationData?.errors) hydrationData = {
|
|
131
131
|
...hydrationData,
|
|
132
132
|
errors: deserializeErrors(hydrationData.errors)
|
|
133
133
|
};
|
|
134
|
-
const isRscClient = getGlobalIsRscClient();
|
|
135
134
|
let routes = null;
|
|
136
|
-
routes =
|
|
135
|
+
routes = process.env.MODERN_ENABLE_RSC && getGlobalIsRscClient() ? createRoutes ? createRoutes() : createRouteObjectsFromConfig({
|
|
137
136
|
routesConfig: finalRouteConfig
|
|
138
137
|
}) : createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
|
|
139
138
|
routesConfig: finalRouteConfig,
|
|
@@ -141,7 +140,7 @@ function useRouterCreation(props, options) {
|
|
|
141
140
|
}));
|
|
142
141
|
if (!routes) routes = [];
|
|
143
142
|
const hooks = api.getHooks();
|
|
144
|
-
if (rscPayload) try {
|
|
143
|
+
if (process.env.MODERN_ENABLE_RSC && rscPayload) try {
|
|
145
144
|
const router = createClientRouterFromPayload(rscPayload, routes, _basename);
|
|
146
145
|
return {
|
|
147
146
|
router,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
|
-
import type
|
|
2
|
+
import { type Root } from 'react-dom/client';
|
|
3
3
|
import type { TRuntimeContext } from '../context/runtime';
|
|
4
|
-
export declare
|
|
5
|
-
export declare function hydrateRoot(App: React.ReactElement, context: TRuntimeContext, ModernRender: (App: React.ReactElement) => Promise<HTMLElement | Root>, ModernHydrate: (App: React.ReactElement
|
|
4
|
+
export declare function hydrateWithReact(App: React.ReactElement, rootElement: HTMLElement): Promise<Root>;
|
|
5
|
+
export declare function hydrateRoot(App: React.ReactElement, context: TRuntimeContext, ModernRender: (App: React.ReactElement) => Promise<HTMLElement | Root>, ModernHydrate: (App: React.ReactElement) => Promise<HTMLElement | Root>): Promise<HTMLElement | Root>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
|
+
import { hydrateWithReact } from './hydrate';
|
|
3
|
+
export { hydrateWithReact };
|
|
2
4
|
export type RenderFunc = typeof render;
|
|
3
5
|
export declare function render(App: React.ReactElement<{
|
|
4
6
|
basename: string;
|
|
5
7
|
}>, id?: HTMLElement | string): Promise<HTMLElement | import("react-dom/client").Root>;
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function renderWithReact17(App: React.ReactElement, rootElement: HTMLElement): Promise<HTMLElement>;
|
|
8
|
-
export declare function hydrateWithReact18(App: React.ReactElement, rootElement: HTMLElement): Promise<import("react-dom/client").Root>;
|
|
9
|
-
export declare function hydrateWithReact17(App: React.ReactElement, rootElement: HTMLElement, callback?: () => void): Promise<any>;
|
|
8
|
+
export declare function renderWithReact(App: React.ReactElement, rootElement: HTMLElement): Promise<import("react-dom/client").Root>;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "3.
|
|
18
|
+
"version": "3.7.0",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=20"
|
|
21
21
|
},
|
|
@@ -215,21 +215,21 @@
|
|
|
215
215
|
"isbot": "3.8.0",
|
|
216
216
|
"react-helmet": "^6.1.0",
|
|
217
217
|
"react-is": "^18.3.1",
|
|
218
|
-
"@modern-js/plugin": "3.
|
|
219
|
-
"@modern-js/plugin-data-loader": "3.
|
|
220
|
-
"@modern-js/render": "3.
|
|
221
|
-
"@modern-js/runtime-utils": "3.
|
|
222
|
-
"@modern-js/types": "3.
|
|
223
|
-
"@modern-js/utils": "3.
|
|
218
|
+
"@modern-js/plugin": "3.7.0",
|
|
219
|
+
"@modern-js/plugin-data-loader": "3.7.0",
|
|
220
|
+
"@modern-js/render": "3.7.0",
|
|
221
|
+
"@modern-js/runtime-utils": "3.7.0",
|
|
222
|
+
"@modern-js/types": "3.7.0",
|
|
223
|
+
"@modern-js/utils": "3.7.0"
|
|
224
224
|
},
|
|
225
225
|
"peerDependencies": {
|
|
226
|
-
"react": ">=
|
|
227
|
-
"react-dom": ">=
|
|
226
|
+
"react": ">=18.0.0",
|
|
227
|
+
"react-dom": ">=18.0.0"
|
|
228
228
|
},
|
|
229
229
|
"devDependencies": {
|
|
230
230
|
"@remix-run/web-fetch": "^4.1.3",
|
|
231
231
|
"@rsbuild/core": "2.1.0",
|
|
232
|
-
"@rslib/core": "0.23.
|
|
232
|
+
"@rslib/core": "0.23.2",
|
|
233
233
|
"@testing-library/dom": "^10.4.1",
|
|
234
234
|
"@testing-library/react": "^16.3.2",
|
|
235
235
|
"@types/cookie": "0.6.0",
|
|
@@ -240,7 +240,7 @@
|
|
|
240
240
|
"react-dom": "^19.2.7",
|
|
241
241
|
"ts-node": "^10.9.2",
|
|
242
242
|
"typescript": "^5",
|
|
243
|
-
"@modern-js/app-tools": "3.
|
|
243
|
+
"@modern-js/app-tools": "3.7.0",
|
|
244
244
|
"@modern-js/rslib": "2.68.10",
|
|
245
245
|
"@scripts/rstest-config": "2.66.0"
|
|
246
246
|
},
|