@modern-js/runtime 1.16.1 → 1.17.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/CHANGELOG.md +26 -0
- package/dist/js/modern/cli/index.js +1 -10
- package/dist/js/modern/core/compatible.js +5 -5
- package/dist/js/modern/core/index.js +2 -2
- package/dist/js/modern/ssr/index.js +5 -5
- package/dist/js/node/cli/index.js +0 -10
- package/dist/js/node/core/compatible.js +5 -5
- package/dist/js/node/ssr/index.js +5 -5
- package/dist/js/treeshaking/cli/index.js +1 -9
- package/dist/js/treeshaking/core/compatible.js +19 -21
- package/dist/js/treeshaking/core/index.js +2 -2
- package/dist/js/treeshaking/ssr/index.js +5 -5
- package/dist/types/common.d.ts +8 -1
- package/dist/types/core/app-config.d.ts +1 -3
- package/dist/types/core/compatible.d.ts +6 -1
- package/dist/types/core/index.d.ts +0 -1
- package/dist/types/core/loader/useLoader.d.ts +1 -0
- package/dist/types/index.d.ts +3 -8
- package/dist/types/state/runtime/plugin.d.ts +0 -5
- package/package.json +10 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @modern-js/runtime
|
|
2
2
|
|
|
3
|
+
## 1.17.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 77d3a38: feat: remove `.runtime-exports/index.js` export
|
|
8
|
+
|
|
9
|
+
feat: 移除 `.runtime-exports/index.js` 导出
|
|
10
|
+
|
|
11
|
+
- 492437f: fix: runtime type
|
|
12
|
+
|
|
13
|
+
fix: 修复 runtime 类型定义
|
|
14
|
+
|
|
15
|
+
- c3d4a6a: feat: support react 18 ssr
|
|
16
|
+
feat: 支持 React 18 下使用 SSR
|
|
17
|
+
- Updated dependencies [1b9176f]
|
|
18
|
+
- Updated dependencies [77d3a38]
|
|
19
|
+
- Updated dependencies [151329d]
|
|
20
|
+
- Updated dependencies [5af9472]
|
|
21
|
+
- Updated dependencies [6b6a534]
|
|
22
|
+
- Updated dependencies [6b43a2b]
|
|
23
|
+
- Updated dependencies [a7be124]
|
|
24
|
+
- Updated dependencies [31547b4]
|
|
25
|
+
- @modern-js/utils@1.17.0
|
|
26
|
+
- @modern-js/webpack@1.17.0
|
|
27
|
+
- @modern-js/plugin@1.17.0
|
|
28
|
+
|
|
3
29
|
## 1.16.1
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import { PLUGIN_SCHEMAS,
|
|
2
|
+
import { PLUGIN_SCHEMAS, cleanRequireCache, isReact18 } from '@modern-js/utils';
|
|
3
3
|
import PluginState from "../state/cli";
|
|
4
4
|
import PluginSSR from "../ssr/cli";
|
|
5
5
|
import PluginRouter from "../router/cli";
|
|
@@ -8,19 +8,15 @@ export default (() => ({
|
|
|
8
8
|
post: ['@modern-js/plugin-router', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-design-token'],
|
|
9
9
|
usePlugins: [PluginState(), PluginRouter(), PluginSSR()],
|
|
10
10
|
setup: api => {
|
|
11
|
-
let runtimeExportsUtils = {};
|
|
12
11
|
return {
|
|
13
12
|
config() {
|
|
14
13
|
const dir = api.useAppContext().internalDirectory || '';
|
|
15
|
-
runtimeExportsUtils = createRuntimeExportsUtils(dir, 'index');
|
|
16
14
|
process.env.IS_REACT18 = isReact18(path.join(dir, '../../')).toString();
|
|
17
15
|
return {
|
|
18
16
|
runtime: {},
|
|
19
17
|
runtimeByEntries: {},
|
|
20
18
|
source: {
|
|
21
19
|
alias: {
|
|
22
|
-
'@modern-js/runtime$': runtimeExportsUtils.getPath(),
|
|
23
|
-
|
|
24
20
|
/**
|
|
25
21
|
* twin.macro inserts styled-components into the code during the compilation process
|
|
26
22
|
* But it will not be installed under the user project.
|
|
@@ -37,11 +33,6 @@ export default (() => ({
|
|
|
37
33
|
return PLUGIN_SCHEMAS['@modern-js/runtime'];
|
|
38
34
|
},
|
|
39
35
|
|
|
40
|
-
addRuntimeExports() {
|
|
41
|
-
const runtimePackage = path.resolve(__dirname, '../../../../');
|
|
42
|
-
runtimeExportsUtils.addExport(`export * from '${runtimePackage}'`);
|
|
43
|
-
},
|
|
44
|
-
|
|
45
36
|
async beforeRestart() {
|
|
46
37
|
cleanRequireCache([require.resolve("../state/cli"), require.resolve("../router/cli"), require.resolve("../ssr/cli")]);
|
|
47
38
|
}
|
|
@@ -110,7 +110,7 @@ id,
|
|
|
110
110
|
/**
|
|
111
111
|
* root.render need use root to run function
|
|
112
112
|
*/
|
|
113
|
-
root,
|
|
113
|
+
root, ReactDOM = defaultReactDOM) => {
|
|
114
114
|
let App = BootApp;
|
|
115
115
|
let runner = runnerMap.get(App); // ensure Component used is created by `createApp`
|
|
116
116
|
|
|
@@ -178,17 +178,17 @@ root, render = defaultReactDOM.render, hydrate = defaultReactDOM.hydrate) => {
|
|
|
178
178
|
|
|
179
179
|
const ModernRender = App => {
|
|
180
180
|
if (IS_REACT18) {
|
|
181
|
-
root.render(App);
|
|
181
|
+
(root || ReactDOM.createRoot(rootElement)).render(App);
|
|
182
182
|
} else {
|
|
183
|
-
render(App, rootElement);
|
|
183
|
+
ReactDOM.render(App, rootElement);
|
|
184
184
|
}
|
|
185
185
|
};
|
|
186
186
|
|
|
187
187
|
const ModernHydrate = (App, callback) => {
|
|
188
188
|
if (IS_REACT18) {
|
|
189
|
-
|
|
189
|
+
ReactDOM.hydrateRoot(rootElement, App);
|
|
190
190
|
} else {
|
|
191
|
-
hydrate(App, rootElement, callback);
|
|
191
|
+
ReactDOM.hydrate(App, rootElement, callback);
|
|
192
192
|
}
|
|
193
193
|
};
|
|
194
194
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createPlugin, createRuntime, runtime, registerInit, registerPrefetch } from "./plugin";
|
|
2
|
-
export { defineConfig, getConfig } from "./app-config";
|
|
3
|
-
|
|
2
|
+
export { defineConfig, getConfig } from "./app-config"; // compatible
|
|
3
|
+
|
|
4
4
|
export * from "./compatible";
|
|
5
5
|
export { RuntimeReactContext } from "../runtime-context";
|
|
6
6
|
export * from "./loader";
|
|
@@ -25,11 +25,10 @@ const ssr = () => ({
|
|
|
25
25
|
}) => {
|
|
26
26
|
var _window, _window$_SSR_DATA;
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
// if render level not exist, use client render
|
|
29
|
+
const renderLevel = ((_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.renderLevel) || RenderLevel.CLIENT_RENDER; // client render and server prefetch use same logic
|
|
29
30
|
|
|
30
|
-
if (renderLevel === RenderLevel.CLIENT_RENDER) {
|
|
31
|
-
// prefetch block render while csr
|
|
32
|
-
// await (App as any)?.prefetch?.(context);
|
|
31
|
+
if (renderLevel === RenderLevel.CLIENT_RENDER || renderLevel === RenderLevel.SERVER_PREFETCH) {
|
|
33
32
|
ModernRender( /*#__PURE__*/_jsx(App, {
|
|
34
33
|
context: context
|
|
35
34
|
}));
|
|
@@ -63,7 +62,8 @@ const ssr = () => ({
|
|
|
63
62
|
});
|
|
64
63
|
} else {
|
|
65
64
|
// unknown renderlevel or renderlevel is server prefetch.
|
|
66
|
-
|
|
65
|
+
console.warn(`unknow render level: ${renderLevel}, execute render()`);
|
|
66
|
+
ModernRender( /*#__PURE__*/_jsx(App, {
|
|
67
67
|
context: context
|
|
68
68
|
}));
|
|
69
69
|
}
|
|
@@ -22,19 +22,15 @@ var _default = () => ({
|
|
|
22
22
|
post: ['@modern-js/plugin-router', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-design-token'],
|
|
23
23
|
usePlugins: [(0, _cli.default)(), (0, _cli3.default)(), (0, _cli2.default)()],
|
|
24
24
|
setup: api => {
|
|
25
|
-
let runtimeExportsUtils = {};
|
|
26
25
|
return {
|
|
27
26
|
config() {
|
|
28
27
|
const dir = api.useAppContext().internalDirectory || '';
|
|
29
|
-
runtimeExportsUtils = (0, _utils.createRuntimeExportsUtils)(dir, 'index');
|
|
30
28
|
process.env.IS_REACT18 = (0, _utils.isReact18)(_path.default.join(dir, '../../')).toString();
|
|
31
29
|
return {
|
|
32
30
|
runtime: {},
|
|
33
31
|
runtimeByEntries: {},
|
|
34
32
|
source: {
|
|
35
33
|
alias: {
|
|
36
|
-
'@modern-js/runtime$': runtimeExportsUtils.getPath(),
|
|
37
|
-
|
|
38
34
|
/**
|
|
39
35
|
* twin.macro inserts styled-components into the code during the compilation process
|
|
40
36
|
* But it will not be installed under the user project.
|
|
@@ -51,12 +47,6 @@ var _default = () => ({
|
|
|
51
47
|
return _utils.PLUGIN_SCHEMAS['@modern-js/runtime'];
|
|
52
48
|
},
|
|
53
49
|
|
|
54
|
-
addRuntimeExports() {
|
|
55
|
-
const runtimePackage = _path.default.resolve(__dirname, '../../../../');
|
|
56
|
-
|
|
57
|
-
runtimeExportsUtils.addExport(`export * from '${runtimePackage}'`);
|
|
58
|
-
},
|
|
59
|
-
|
|
60
50
|
async beforeRestart() {
|
|
61
51
|
(0, _utils.cleanRequireCache)([require.resolve("../state/cli"), require.resolve("../router/cli"), require.resolve("../ssr/cli")]);
|
|
62
52
|
}
|
|
@@ -135,7 +135,7 @@ id,
|
|
|
135
135
|
/**
|
|
136
136
|
* root.render need use root to run function
|
|
137
137
|
*/
|
|
138
|
-
root,
|
|
138
|
+
root, ReactDOM = _reactDom.default) => {
|
|
139
139
|
let App = BootApp;
|
|
140
140
|
let runner = runnerMap.get(App); // ensure Component used is created by `createApp`
|
|
141
141
|
|
|
@@ -203,17 +203,17 @@ root, render = _reactDom.default.render, hydrate = _reactDom.default.hydrate) =>
|
|
|
203
203
|
|
|
204
204
|
const ModernRender = App => {
|
|
205
205
|
if (IS_REACT18) {
|
|
206
|
-
root.render(App);
|
|
206
|
+
(root || ReactDOM.createRoot(rootElement)).render(App);
|
|
207
207
|
} else {
|
|
208
|
-
render(App, rootElement);
|
|
208
|
+
ReactDOM.render(App, rootElement);
|
|
209
209
|
}
|
|
210
210
|
};
|
|
211
211
|
|
|
212
212
|
const ModernHydrate = (App, callback) => {
|
|
213
213
|
if (IS_REACT18) {
|
|
214
|
-
|
|
214
|
+
ReactDOM.hydrateRoot(rootElement, App);
|
|
215
215
|
} else {
|
|
216
|
-
hydrate(App, rootElement, callback);
|
|
216
|
+
ReactDOM.hydrate(App, rootElement, callback);
|
|
217
217
|
}
|
|
218
218
|
};
|
|
219
219
|
|
|
@@ -55,11 +55,10 @@ const ssr = () => ({
|
|
|
55
55
|
}) => {
|
|
56
56
|
var _window, _window$_SSR_DATA;
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
// if render level not exist, use client render
|
|
59
|
+
const renderLevel = ((_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.renderLevel) || _type.RenderLevel.CLIENT_RENDER; // client render and server prefetch use same logic
|
|
59
60
|
|
|
60
|
-
if (renderLevel === _type.RenderLevel.CLIENT_RENDER) {
|
|
61
|
-
// prefetch block render while csr
|
|
62
|
-
// await (App as any)?.prefetch?.(context);
|
|
61
|
+
if (renderLevel === _type.RenderLevel.CLIENT_RENDER || renderLevel === _type.RenderLevel.SERVER_PREFETCH) {
|
|
63
62
|
ModernRender( /*#__PURE__*/(0, _jsxRuntime.jsx)(App, {
|
|
64
63
|
context: context
|
|
65
64
|
}));
|
|
@@ -93,7 +92,8 @@ const ssr = () => ({
|
|
|
93
92
|
});
|
|
94
93
|
} else {
|
|
95
94
|
// unknown renderlevel or renderlevel is server prefetch.
|
|
96
|
-
|
|
95
|
+
console.warn(`unknow render level: ${renderLevel}, execute render()`);
|
|
96
|
+
ModernRender( /*#__PURE__*/(0, _jsxRuntime.jsx)(App, {
|
|
97
97
|
context: context
|
|
98
98
|
}));
|
|
99
99
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import { PLUGIN_SCHEMAS,
|
|
4
|
+
import { PLUGIN_SCHEMAS, cleanRequireCache, isReact18 } from '@modern-js/utils';
|
|
5
5
|
import PluginState from "../state/cli";
|
|
6
6
|
import PluginSSR from "../ssr/cli";
|
|
7
7
|
import PluginRouter from "../router/cli";
|
|
@@ -11,19 +11,15 @@ export default (function () {
|
|
|
11
11
|
post: ['@modern-js/plugin-router', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-design-token'],
|
|
12
12
|
usePlugins: [PluginState(), PluginRouter(), PluginSSR()],
|
|
13
13
|
setup: function setup(api) {
|
|
14
|
-
var runtimeExportsUtils = {};
|
|
15
14
|
return {
|
|
16
15
|
config: function config() {
|
|
17
16
|
var dir = api.useAppContext().internalDirectory || '';
|
|
18
|
-
runtimeExportsUtils = createRuntimeExportsUtils(dir, 'index');
|
|
19
17
|
process.env.IS_REACT18 = isReact18(path.join(dir, '../../')).toString();
|
|
20
18
|
return {
|
|
21
19
|
runtime: {},
|
|
22
20
|
runtimeByEntries: {},
|
|
23
21
|
source: {
|
|
24
22
|
alias: {
|
|
25
|
-
'@modern-js/runtime$': runtimeExportsUtils.getPath(),
|
|
26
|
-
|
|
27
23
|
/**
|
|
28
24
|
* twin.macro inserts styled-components into the code during the compilation process
|
|
29
25
|
* But it will not be installed under the user project.
|
|
@@ -38,10 +34,6 @@ export default (function () {
|
|
|
38
34
|
validateSchema: function validateSchema() {
|
|
39
35
|
return PLUGIN_SCHEMAS['@modern-js/runtime'];
|
|
40
36
|
},
|
|
41
|
-
addRuntimeExports: function addRuntimeExports() {
|
|
42
|
-
var runtimePackage = path.resolve(__dirname, '../../../../');
|
|
43
|
-
runtimeExportsUtils.addExport("export * from '".concat(runtimePackage, "'"));
|
|
44
|
-
},
|
|
45
37
|
beforeRestart: function beforeRestart() {
|
|
46
38
|
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
47
39
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
@@ -105,8 +105,7 @@ export var bootstrap = /*#__PURE__*/function () {
|
|
|
105
105
|
* root.render need use root to run function
|
|
106
106
|
*/
|
|
107
107
|
root) {
|
|
108
|
-
var
|
|
109
|
-
hydrate,
|
|
108
|
+
var ReactDOM,
|
|
110
109
|
App,
|
|
111
110
|
runner,
|
|
112
111
|
context,
|
|
@@ -128,8 +127,7 @@ export var bootstrap = /*#__PURE__*/function () {
|
|
|
128
127
|
while (1) {
|
|
129
128
|
switch (_context2.prev = _context2.next) {
|
|
130
129
|
case 0:
|
|
131
|
-
|
|
132
|
-
hydrate = _args.length > 4 && _args[4] !== undefined ? _args[4] : defaultReactDOM.hydrate;
|
|
130
|
+
ReactDOM = _args.length > 3 && _args[3] !== undefined ? _args[3] : defaultReactDOM;
|
|
133
131
|
App = BootApp;
|
|
134
132
|
runner = runnerMap.get(App); // ensure Component used is created by `createApp`
|
|
135
133
|
|
|
@@ -157,7 +155,7 @@ export var bootstrap = /*#__PURE__*/function () {
|
|
|
157
155
|
|
|
158
156
|
|
|
159
157
|
if (id) {
|
|
160
|
-
_context2.next =
|
|
158
|
+
_context2.next = 8;
|
|
161
159
|
break;
|
|
162
160
|
}
|
|
163
161
|
|
|
@@ -165,16 +163,16 @@ export var bootstrap = /*#__PURE__*/function () {
|
|
|
165
163
|
context: context
|
|
166
164
|
}));
|
|
167
165
|
|
|
168
|
-
case
|
|
166
|
+
case 8:
|
|
169
167
|
isBrowser = typeof window !== 'undefined' && window.name !== 'nodejs';
|
|
170
168
|
|
|
171
169
|
if (!isBrowser) {
|
|
172
|
-
_context2.next =
|
|
170
|
+
_context2.next = 29;
|
|
173
171
|
break;
|
|
174
172
|
}
|
|
175
173
|
|
|
176
174
|
if (!isClientArgs(id)) {
|
|
177
|
-
_context2.next =
|
|
175
|
+
_context2.next = 26;
|
|
178
176
|
break;
|
|
179
177
|
}
|
|
180
178
|
|
|
@@ -198,10 +196,10 @@ export var bootstrap = /*#__PURE__*/function () {
|
|
|
198
196
|
ssrContext: ssrData === null || ssrData === void 0 ? void 0 : ssrData.context
|
|
199
197
|
} : {}));
|
|
200
198
|
context.initialData = ssrData === null || ssrData === void 0 ? void 0 : (_ssrData$data2 = ssrData.data) === null || _ssrData$data2 === void 0 ? void 0 : _ssrData$data2.initialData;
|
|
201
|
-
_context2.next =
|
|
199
|
+
_context2.next = 18;
|
|
202
200
|
return runInit(context);
|
|
203
201
|
|
|
204
|
-
case
|
|
202
|
+
case 18:
|
|
205
203
|
initialData = _context2.sent;
|
|
206
204
|
|
|
207
205
|
if (initialData) {
|
|
@@ -212,17 +210,17 @@ export var bootstrap = /*#__PURE__*/function () {
|
|
|
212
210
|
|
|
213
211
|
ModernRender = function ModernRender(App) {
|
|
214
212
|
if (IS_REACT18) {
|
|
215
|
-
root.render(App);
|
|
213
|
+
(root || ReactDOM.createRoot(_rootElement)).render(App);
|
|
216
214
|
} else {
|
|
217
|
-
render(App, _rootElement);
|
|
215
|
+
ReactDOM.render(App, _rootElement);
|
|
218
216
|
}
|
|
219
217
|
};
|
|
220
218
|
|
|
221
219
|
ModernHydrate = function ModernHydrate(App, callback) {
|
|
222
220
|
if (IS_REACT18) {
|
|
223
|
-
|
|
221
|
+
ReactDOM.hydrateRoot(_rootElement, App);
|
|
224
222
|
} else {
|
|
225
|
-
hydrate(App, _rootElement, callback);
|
|
223
|
+
ReactDOM.hydrate(App, _rootElement, callback);
|
|
226
224
|
}
|
|
227
225
|
};
|
|
228
226
|
|
|
@@ -240,14 +238,14 @@ export var bootstrap = /*#__PURE__*/function () {
|
|
|
240
238
|
}
|
|
241
239
|
}));
|
|
242
240
|
|
|
243
|
-
case
|
|
241
|
+
case 26:
|
|
244
242
|
throw Error('`bootstrap` needs id in browser environment, it needs to be string or element');
|
|
245
243
|
|
|
246
|
-
case
|
|
247
|
-
_context2.next =
|
|
244
|
+
case 27:
|
|
245
|
+
_context2.next = 35;
|
|
248
246
|
break;
|
|
249
247
|
|
|
250
|
-
case
|
|
248
|
+
case 29:
|
|
251
249
|
Object.assign(context, {
|
|
252
250
|
ssrContext: id,
|
|
253
251
|
isBrowser: false,
|
|
@@ -257,10 +255,10 @@ export var bootstrap = /*#__PURE__*/function () {
|
|
|
257
255
|
skipStatic: process.env.NODE_ENV === 'production' && !id.staticGenerate
|
|
258
256
|
})
|
|
259
257
|
});
|
|
260
|
-
_context2.next =
|
|
258
|
+
_context2.next = 32;
|
|
261
259
|
return runInit(context);
|
|
262
260
|
|
|
263
|
-
case
|
|
261
|
+
case 32:
|
|
264
262
|
_initialData = _context2.sent;
|
|
265
263
|
context.initialData = _initialData;
|
|
266
264
|
return _context2.abrupt("return", runner.server({
|
|
@@ -268,7 +266,7 @@ export var bootstrap = /*#__PURE__*/function () {
|
|
|
268
266
|
context: context
|
|
269
267
|
}));
|
|
270
268
|
|
|
271
|
-
case
|
|
269
|
+
case 35:
|
|
272
270
|
case "end":
|
|
273
271
|
return _context2.stop();
|
|
274
272
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createPlugin, createRuntime, runtime, registerInit, registerPrefetch } from "./plugin";
|
|
2
|
-
export { defineConfig, getConfig } from "./app-config";
|
|
3
|
-
|
|
2
|
+
export { defineConfig, getConfig } from "./app-config"; // compatible
|
|
3
|
+
|
|
4
4
|
export * from "./compatible";
|
|
5
5
|
export { RuntimeReactContext } from "../runtime-context";
|
|
6
6
|
export * from "./loader";
|
|
@@ -25,11 +25,10 @@ var ssr = function ssr() {
|
|
|
25
25
|
switch (_context.prev = _context.next) {
|
|
26
26
|
case 0:
|
|
27
27
|
App = _ref.App, context = _ref.context, ModernRender = _ref.ModernRender, ModernHydrate = _ref.ModernHydrate;
|
|
28
|
-
|
|
28
|
+
// if render level not exist, use client render
|
|
29
|
+
renderLevel = ((_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.renderLevel) || RenderLevel.CLIENT_RENDER; // client render and server prefetch use same logic
|
|
29
30
|
|
|
30
|
-
if (renderLevel === RenderLevel.CLIENT_RENDER) {
|
|
31
|
-
// prefetch block render while csr
|
|
32
|
-
// await (App as any)?.prefetch?.(context);
|
|
31
|
+
if (renderLevel === RenderLevel.CLIENT_RENDER || renderLevel === RenderLevel.SERVER_PREFETCH) {
|
|
33
32
|
ModernRender( /*#__PURE__*/_jsx(App, {
|
|
34
33
|
context: context
|
|
35
34
|
}));
|
|
@@ -65,7 +64,8 @@ var ssr = function ssr() {
|
|
|
65
64
|
});
|
|
66
65
|
} else {
|
|
67
66
|
// unknown renderlevel or renderlevel is server prefetch.
|
|
68
|
-
|
|
67
|
+
console.warn("unknow render level: ".concat(renderLevel, ", execute render()"));
|
|
68
|
+
ModernRender( /*#__PURE__*/_jsx(App, {
|
|
69
69
|
context: context
|
|
70
70
|
}));
|
|
71
71
|
}
|
package/dist/types/common.d.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import type { StateConfig } from './state';
|
|
2
|
+
import type { RouterConfig } from './router';
|
|
3
|
+
export declare const isBrowser: () => boolean;
|
|
4
|
+
export interface AppConfig {
|
|
5
|
+
router?: RouterConfig | boolean;
|
|
6
|
+
state?: StateConfig | boolean;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
|
-
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
}
|
|
2
|
+
import { AppConfig } from '../common';
|
|
5
3
|
export declare const getConfig: (Component: React.ComponentType<any>) => AppConfig | undefined;
|
|
6
4
|
export declare const defineConfig: (Component: React.ComponentType<any>, config: AppConfig) => React.ComponentType<any>;
|
|
@@ -11,7 +11,12 @@ interface HydrateFunc {
|
|
|
11
11
|
(container: Element | Document, initialChildren: React.ReactNode): void;
|
|
12
12
|
(initialChildren: React.ReactNode, container: Element | Document, callback?: () => void): void;
|
|
13
13
|
}
|
|
14
|
-
declare type BootStrap<T = unknown> = (App: React.ComponentType, id
|
|
14
|
+
declare type BootStrap<T = unknown> = (App: React.ComponentType, id: string | Record<string, any> | HTMLElement, root: any, ReactDOM: {
|
|
15
|
+
render: (children: React.ReactNode, rootElement?: HTMLElement) => void;
|
|
16
|
+
hydrate: HydrateFunc;
|
|
17
|
+
createRoot?: (rootElement: HTMLElement) => any;
|
|
18
|
+
hydrateRoot: HydrateFunc;
|
|
19
|
+
}) => Promise<T>;
|
|
15
20
|
export declare const bootstrap: BootStrap;
|
|
16
21
|
export declare const useRuntimeContext: () => TRuntimeContext;
|
|
17
22
|
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { createPlugin, createRuntime, runtime, registerInit, registerPrefetch } from './plugin';
|
|
2
2
|
export type { Plugin } from './plugin';
|
|
3
3
|
export { defineConfig, getConfig } from './app-config';
|
|
4
|
-
export type { AppConfig } from './app-config';
|
|
5
4
|
export * from './compatible';
|
|
6
5
|
export type { TRuntimeContext, RuntimeContext } from '../runtime-context';
|
|
7
6
|
export { RuntimeReactContext } from '../runtime-context';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import type { StateConfig } from './state';
|
|
2
2
|
import type { RouterConfig } from './router';
|
|
3
|
-
export type { Plugin
|
|
3
|
+
export type { Plugin } from './core';
|
|
4
|
+
export type { AppConfig } from './common';
|
|
4
5
|
export type { BaseRuntimeContext, RuntimeContext, BaseTRuntimeContext, TRuntimeContext } from './runtime-context';
|
|
5
6
|
export { createApp, createPlugin, useLoader, bootstrap, RuntimeReactContext, registerPrefetch, defineConfig, registerInit, useRuntimeContext } from './core';
|
|
6
|
-
export { StateConfig, RouterConfig };
|
|
7
|
-
declare module './core' {
|
|
8
|
-
interface AppConfig {
|
|
9
|
-
router?: RouterConfig | boolean;
|
|
10
|
-
state?: StateConfig | boolean;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
7
|
+
export { StateConfig, RouterConfig };
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { createStore } from '@modern-js-reduck/store';
|
|
2
2
|
import type { Plugin } from '../../core';
|
|
3
|
-
declare module '../../core' {
|
|
4
|
-
interface SSRData {
|
|
5
|
-
storeState: any;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
3
|
export declare type StateConfig = Parameters<typeof createStore>[0];
|
|
9
4
|
declare const state: (config: StateConfig) => Plugin;
|
|
10
5
|
export default state;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.17.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./type.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -140,9 +140,9 @@
|
|
|
140
140
|
"@loadable/babel-plugin": "^5.13.2",
|
|
141
141
|
"@loadable/server": "^5.15.1",
|
|
142
142
|
"@loadable/component": "^5.15.0",
|
|
143
|
-
"@modern-js/plugin": "1.
|
|
144
|
-
"@modern-js/webpack": "1.
|
|
145
|
-
"@modern-js/utils": "1.
|
|
143
|
+
"@modern-js/plugin": "1.17.0",
|
|
144
|
+
"@modern-js/webpack": "1.17.0",
|
|
145
|
+
"@modern-js/utils": "1.17.0",
|
|
146
146
|
"@modern-js-reduck/plugin-auto-actions": "^1.0.2",
|
|
147
147
|
"@modern-js-reduck/plugin-devtools": "^1.0.3",
|
|
148
148
|
"@modern-js-reduck/plugin-effects": "^1.0.2",
|
|
@@ -166,16 +166,16 @@
|
|
|
166
166
|
"ts-jest": "^27.0.4",
|
|
167
167
|
"typescript": "^4",
|
|
168
168
|
"jest": "^27",
|
|
169
|
-
"@modern-js/core": "1.
|
|
170
|
-
"@modern-js/types": "1.
|
|
171
|
-
"@modern-js/utils": "1.
|
|
169
|
+
"@modern-js/core": "1.17.0",
|
|
170
|
+
"@modern-js/types": "1.17.0",
|
|
171
|
+
"@modern-js/utils": "1.17.0",
|
|
172
172
|
"@types/jest": "^27",
|
|
173
173
|
"@types/node": "^14",
|
|
174
174
|
"@types/react-side-effect": "^1.1.1",
|
|
175
175
|
"@types/loadable__webpack-plugin": "^5.7.3",
|
|
176
176
|
"@types/serialize-javascript": "^5.0.1",
|
|
177
|
-
"@scripts/build": "1.
|
|
178
|
-
"@scripts/jest-config": "1.
|
|
177
|
+
"@scripts/build": "1.17.0",
|
|
178
|
+
"@scripts/jest-config": "1.17.0",
|
|
179
179
|
"@testing-library/react": "^12.0.0",
|
|
180
180
|
"@testing-library/react-hooks": "^7.0.1",
|
|
181
181
|
"@types/hoist-non-react-statics": "^3.3.1",
|
|
@@ -211,6 +211,7 @@
|
|
|
211
211
|
}
|
|
212
212
|
},
|
|
213
213
|
"scripts": {
|
|
214
|
+
"dev": "modern build --watch",
|
|
214
215
|
"new": "modern new",
|
|
215
216
|
"build": "wireit",
|
|
216
217
|
"test": "wireit"
|