@modern-js/runtime 2.0.0-beta.1 → 2.0.0-beta.3
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 +181 -0
- package/dist/js/modern/cli/index.js +3 -1
- package/dist/js/modern/core/compatible.js +4 -3
- package/dist/js/modern/document/cli/index.js +10 -8
- package/dist/js/modern/document/constants.js +1 -1
- package/dist/js/modern/router/runtime/plugin.js +8 -7
- package/dist/js/modern/router/runtime/plugin.node.js +10 -6
- package/dist/js/modern/router/runtime/server.js +1 -0
- package/dist/js/modern/router/runtime/utils.js +2 -4
- package/dist/js/modern/ssr/cli/index.js +14 -0
- package/dist/js/modern/ssr/serverRender/renderToStream/bulidTemplate.before.js +5 -1
- package/dist/js/modern/state/cli/index.js +0 -1
- package/dist/js/modern/state/runtime/plugin.js +10 -3
- package/dist/js/node/cli/index.js +3 -1
- package/dist/js/node/core/compatible.js +4 -3
- package/dist/js/node/document/cli/index.js +10 -8
- package/dist/js/node/document/constants.js +1 -1
- package/dist/js/node/router/runtime/plugin.js +7 -6
- package/dist/js/node/router/runtime/plugin.node.js +9 -5
- package/dist/js/node/router/runtime/server.js +16 -0
- package/dist/js/node/router/runtime/utils.js +2 -4
- package/dist/js/node/ssr/cli/index.js +14 -0
- package/dist/js/node/ssr/serverRender/renderToStream/bulidTemplate.before.js +5 -1
- package/dist/js/node/state/cli/index.js +0 -1
- package/dist/js/node/state/runtime/plugin.js +10 -3
- package/dist/js/treeshaking/cli/index.js +3 -1
- package/dist/js/treeshaking/core/compatible.js +31 -41
- package/dist/js/treeshaking/document/cli/index.js +14 -9
- package/dist/js/treeshaking/document/constants.js +1 -1
- package/dist/js/treeshaking/router/runtime/plugin.js +9 -7
- package/dist/js/treeshaking/router/runtime/plugin.node.js +18 -13
- package/dist/js/treeshaking/router/runtime/server.js +1 -0
- package/dist/js/treeshaking/router/runtime/utils.js +2 -4
- package/dist/js/treeshaking/ssr/cli/index.js +15 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/bulidTemplate.before.js +5 -1
- package/dist/js/treeshaking/state/cli/index.js +0 -1
- package/dist/js/treeshaking/state/runtime/plugin.js +14 -3
- package/dist/types/cli/index.d.ts +2 -2
- package/dist/types/core/compatible.d.ts +6 -8
- package/dist/types/core/plugin.d.ts +15 -15
- package/dist/types/document/cli/index.d.ts +2 -2
- package/dist/types/document/constants.d.ts +1 -1
- package/dist/types/router/cli/index.d.ts +2 -2
- package/dist/types/router/runtime/plugin.d.ts +1 -0
- package/dist/types/router/runtime/plugin.node.d.ts +1 -0
- package/dist/types/router/runtime/server.d.ts +1 -0
- package/dist/types/router/runtime/types.d.ts +1 -0
- package/dist/types/ssr/cli/index.d.ts +2 -2
- package/dist/types/ssr/serverRender/types.d.ts +2 -2
- package/dist/types/state/cli/index.d.ts +2 -2
- package/dist/types/state/runtime/plugin.d.ts +7 -2
- package/package.json +28 -27
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,186 @@
|
|
|
1
1
|
# @modern-js/runtime
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.3
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- dda38c9c3e: chore: v2
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- c9e800d39a: feat: support React18 streaming SSR
|
|
12
|
+
feat: 支持 React18 流式 SSR
|
|
13
|
+
- 543be9558e: feat: compile server loader and support handle loader request
|
|
14
|
+
feat: 编译 server loader 并支持处理 loader 的请求
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 2344eb26ed: fix: bootstrap function params type define
|
|
19
|
+
|
|
20
|
+
fix: 修复 bootstrap 函数参数类型定义
|
|
21
|
+
|
|
22
|
+
- a11fcf8b50: feat: fallback logic of streaming ssr
|
|
23
|
+
feat: streaming ssr 降级逻辑
|
|
24
|
+
- e7ce063: fix: root layout css chunks should't be loaded
|
|
25
|
+
fix: 不应该加载 root layout 的 css chunks
|
|
26
|
+
- b18fa8f3ed: feat: remove @loadable/component in streaming ssr
|
|
27
|
+
feat: 移除 streaming ssr 中的 @loadable/component 逻辑
|
|
28
|
+
- 6604f1b: feat: support router basename
|
|
29
|
+
feat: router 插件支持设置 basename
|
|
30
|
+
- fda836f: feat: support `models`,`initialState` config for state plugin
|
|
31
|
+
feat: state 插件支持`model`,`initialState` 配置
|
|
32
|
+
- 3e57f2bd58: feat: add document feature with plugin
|
|
33
|
+
|
|
34
|
+
feat: 增加 document 功能插件
|
|
35
|
+
|
|
36
|
+
- 2e60319: fix: some optimizations for router and loader
|
|
37
|
+
fix: 一些 router 和 loader 的优化
|
|
38
|
+
q
|
|
39
|
+
- fbf5eed5aa: fix: fix ssg failure due to lack of Web Response API
|
|
40
|
+
fix: 修复因为缺少 Web Response API 而导致 ssg 失败
|
|
41
|
+
- a2509bfbdb: feat: bump esbuild from 0.14.38 to 0.15.7
|
|
42
|
+
|
|
43
|
+
feat: 将 esbuild 从 0.14.38 版本升级至 0.15.7 版本
|
|
44
|
+
|
|
45
|
+
- 425e570: feat: export react-router-dom/server staticRouter
|
|
46
|
+
feat: 导出 react-router-dom/server 的 staticRouter 组件
|
|
47
|
+
- e4357f1: fix: change default document file and name
|
|
48
|
+
|
|
49
|
+
fix: 重置默认的 document 文件和文件名
|
|
50
|
+
|
|
51
|
+
- 4369648ae2: fix: fix html template of streaming ssr
|
|
52
|
+
fix: 修复流式渲染的 html 模版
|
|
53
|
+
- 92c0994468: chore: remove `registerPrefetch`
|
|
54
|
+
chore: 移除 `registerPrefetch`
|
|
55
|
+
- 6bda14ed71: feat: refactor router with react-router@6.4
|
|
56
|
+
|
|
57
|
+
feat: 使用 react-router@6.4 重构路由模块
|
|
58
|
+
|
|
59
|
+
- 92004d1906: feat: support load chunks parallelly
|
|
60
|
+
feat: 支持并行加载 chunks
|
|
61
|
+
- 40ed5874c6: feat: inject css chunk into html for streaming ssr
|
|
62
|
+
feat: streaming ssr 返回的 html 注入 css chunk
|
|
63
|
+
- 60d5378632: fix: function extname should not return array
|
|
64
|
+
fix: 函数 extname 不应该返回一个数组
|
|
65
|
+
- 8b8e1bb571: feat: support nested routes
|
|
66
|
+
feat: 支持嵌套路由
|
|
67
|
+
- 3bbea92b2a: feat: support Hook、Middleware new API
|
|
68
|
+
feat: 支持 Hook、Middleware 的新 API
|
|
69
|
+
- 18aaf42249: fix: fix server loader redirects
|
|
70
|
+
fix: 修复 server loader 重定向错误
|
|
71
|
+
- 34702d5: feat: support internal env vars: metaName_TARGET
|
|
72
|
+
feat: 支持内置环境变量 metaName_TARGET
|
|
73
|
+
- fcace5b5b9: fix: remove overmuch `@modernjs/utils` dependency import in ssr runtime & SSR hydrate error
|
|
74
|
+
fix: 去除 ssr 运行时过多的 `@modernjs/utils` 依赖引入 & SSR hydrate 错误
|
|
75
|
+
- Updated dependencies [6aca875]
|
|
76
|
+
- Updated dependencies [2e60319]
|
|
77
|
+
- Updated dependencies [92f0eade39]
|
|
78
|
+
- Updated dependencies [edd1cfb1af]
|
|
79
|
+
- Updated dependencies [cc971eabfc]
|
|
80
|
+
- Updated dependencies [5b9049f2e9]
|
|
81
|
+
- Updated dependencies [6bda14ed71]
|
|
82
|
+
- Updated dependencies [92004d1906]
|
|
83
|
+
- Updated dependencies [b8bbe036c7]
|
|
84
|
+
- Updated dependencies [40ed5874c6]
|
|
85
|
+
- Updated dependencies [87c1ff86b9]
|
|
86
|
+
- Updated dependencies [d5a31df781]
|
|
87
|
+
- Updated dependencies [dda38c9c3e]
|
|
88
|
+
- Updated dependencies [102d32e4ba]
|
|
89
|
+
- Updated dependencies [8b8e1bb571]
|
|
90
|
+
- Updated dependencies [3bbea92b2a]
|
|
91
|
+
- Updated dependencies [b710adb]
|
|
92
|
+
- Updated dependencies [f179749375]
|
|
93
|
+
- Updated dependencies [ea7cf06]
|
|
94
|
+
- Updated dependencies [bbe4c4a]
|
|
95
|
+
- Updated dependencies [e4558a0]
|
|
96
|
+
- Updated dependencies [abf3421a75]
|
|
97
|
+
- Updated dependencies [543be9558e]
|
|
98
|
+
- Updated dependencies [14b712da84]
|
|
99
|
+
- @modern-js/utils@2.0.0-beta.3
|
|
100
|
+
- @modern-js/types@2.0.0-beta.3
|
|
101
|
+
- @modern-js/plugin@2.0.0-beta.3
|
|
102
|
+
|
|
103
|
+
## 2.0.0-beta.2
|
|
104
|
+
|
|
105
|
+
### Major Changes
|
|
106
|
+
|
|
107
|
+
- dda38c9c3e: chore: v2
|
|
108
|
+
|
|
109
|
+
### Minor Changes
|
|
110
|
+
|
|
111
|
+
- c9e800d39a: feat: support React18 streaming SSR
|
|
112
|
+
feat: 支持 React18 流式 SSR
|
|
113
|
+
- 543be9558e: feat: compile server loader and support handle loader request
|
|
114
|
+
feat: 编译 server loader 并支持处理 loader 的请求
|
|
115
|
+
|
|
116
|
+
### Patch Changes
|
|
117
|
+
|
|
118
|
+
- 2344eb2: fix: bootstrap function params type define
|
|
119
|
+
|
|
120
|
+
fix: 修复 bootstrap 函数参数类型定义
|
|
121
|
+
|
|
122
|
+
- a11fcf8: feat: fallback logic of streaming ssr
|
|
123
|
+
feat: streaming ssr 降级逻辑
|
|
124
|
+
- b18fa8f3ed: feat: remove @loadable/component in streaming ssr
|
|
125
|
+
feat: 移除 streaming ssr 中的 @loadable/component 逻辑
|
|
126
|
+
- 3e57f2b: feat: add document feature with plugin
|
|
127
|
+
|
|
128
|
+
feat: 增加 document 功能插件
|
|
129
|
+
|
|
130
|
+
- fbf5eed: fix: fix ssg failure due to lack of Web Response API
|
|
131
|
+
fix: 修复因为缺少 Web Response API 而导致 ssg 失败
|
|
132
|
+
- a2509bfbdb: feat: bump esbuild from 0.14.38 to 0.15.7
|
|
133
|
+
|
|
134
|
+
feat: 将 esbuild 从 0.14.38 版本升级至 0.15.7 版本
|
|
135
|
+
|
|
136
|
+
- e4357f1: fix: change default document file and name
|
|
137
|
+
|
|
138
|
+
fix: 重置默认的 document 文件和文件名
|
|
139
|
+
|
|
140
|
+
- 4369648ae2: fix: fix html template of streaming ssr
|
|
141
|
+
fix: 修复流式渲染的 html 模版
|
|
142
|
+
- 92c0994: chore: remove `registerPrefetch`
|
|
143
|
+
chore: 移除 `registerPrefetch`
|
|
144
|
+
- 6bda14ed71: feat: refactor router with react-router@6.4
|
|
145
|
+
|
|
146
|
+
feat: 使用 react-router@6.4 重构路由模块
|
|
147
|
+
|
|
148
|
+
- 92004d1: feat: support load chunks parallelly
|
|
149
|
+
feat: 支持并行加载 chunks
|
|
150
|
+
- 40ed587: feat: inject css chunk into html for streaming ssr
|
|
151
|
+
feat: streaming ssr 返回的 html 注入 css chunk
|
|
152
|
+
- 60d5378632: fix: function extname should not return array
|
|
153
|
+
fix: 函数 extname 不应该返回一个数组
|
|
154
|
+
- 8b8e1bb571: feat: support nested routes
|
|
155
|
+
feat: 支持嵌套路由
|
|
156
|
+
- 3bbea92b2a: feat: support Hook、Middleware new API
|
|
157
|
+
feat: 支持 Hook、Middleware 的新 API
|
|
158
|
+
- 18aaf42: fix: fix server loader redirects
|
|
159
|
+
fix: 修复 server loader 重定向错误
|
|
160
|
+
- fcace5b5b9: fix: remove overmuch `@modernjs/utils` dependency import in ssr runtime & SSR hydrate error
|
|
161
|
+
fix: 去除 ssr 运行时过多的 `@modernjs/utils` 依赖引入 & SSR hydrate 错误
|
|
162
|
+
- Updated dependencies [92f0ead]
|
|
163
|
+
- Updated dependencies [edd1cfb1af]
|
|
164
|
+
- Updated dependencies [cc971eabfc]
|
|
165
|
+
- Updated dependencies [5b9049f2e9]
|
|
166
|
+
- Updated dependencies [6bda14ed71]
|
|
167
|
+
- Updated dependencies [92004d1]
|
|
168
|
+
- Updated dependencies [b8bbe036c7]
|
|
169
|
+
- Updated dependencies [40ed587]
|
|
170
|
+
- Updated dependencies [87c1ff8]
|
|
171
|
+
- Updated dependencies [d5a31df781]
|
|
172
|
+
- Updated dependencies [dda38c9c3e]
|
|
173
|
+
- Updated dependencies [102d32e4ba]
|
|
174
|
+
- Updated dependencies [8b8e1bb571]
|
|
175
|
+
- Updated dependencies [3bbea92b2a]
|
|
176
|
+
- Updated dependencies [f179749]
|
|
177
|
+
- Updated dependencies [abf3421a75]
|
|
178
|
+
- Updated dependencies [543be9558e]
|
|
179
|
+
- Updated dependencies [14b712da84]
|
|
180
|
+
- @modern-js/utils@2.0.0-beta.2
|
|
181
|
+
- @modern-js/types@2.0.0-beta.2
|
|
182
|
+
- @modern-js/plugin@2.0.0-beta.2
|
|
183
|
+
|
|
3
184
|
## 2.0.0-beta.1
|
|
4
185
|
|
|
5
186
|
### Major Changes
|
|
@@ -5,7 +5,6 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
5
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
6
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
7
7
|
import React, { useContext, useMemo } from 'react';
|
|
8
|
-
import defaultReactDOM from 'react-dom';
|
|
9
8
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
10
9
|
import { RuntimeReactContext } from "../runtime-context";
|
|
11
10
|
import { runtime } from "./plugin";
|
|
@@ -95,7 +94,7 @@ id,
|
|
|
95
94
|
/**
|
|
96
95
|
* root.render need use root to run function
|
|
97
96
|
*/
|
|
98
|
-
root, ReactDOM
|
|
97
|
+
root, ReactDOM
|
|
99
98
|
// eslint-disable-next-line consistent-return
|
|
100
99
|
) => {
|
|
101
100
|
let App = BootApp;
|
|
@@ -153,7 +152,9 @@ root, ReactDOM = defaultReactDOM
|
|
|
153
152
|
context.initialData = initialData;
|
|
154
153
|
}
|
|
155
154
|
const rootElement = typeof id !== 'string' ? id : document.getElementById(id || 'root');
|
|
156
|
-
|
|
155
|
+
if (!ReactDOM) {
|
|
156
|
+
throw Error('The `bootstrap` need provide `ReactDOM` parameter');
|
|
157
|
+
}
|
|
157
158
|
// https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html
|
|
158
159
|
const ModernRender = App => {
|
|
159
160
|
if (IS_REACT18) {
|
|
@@ -9,10 +9,15 @@ import { createDebugger, findExists } from '@modern-js/utils';
|
|
|
9
9
|
import { DocumentContext } from "../DocumentContext";
|
|
10
10
|
import { DOCUMENT_SCRIPTS_PLACEHOLDER, DOCUMENT_FILE_NAME, DOCUMENT_META_PLACEHOLDER, PLACEHOLDER_REPLACER_MAP, DOC_EXT, DOCUMENT_SSR_PLACEHOLDER, DOCUMENT_CHUNKSMAP_PLACEHOLDER, DOCUMENT_SSRDATASCRIPT_PLACEHOLDER, HTML_SEPARATOR } from "../constants";
|
|
11
11
|
const debug = createDebugger('html_genarate');
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
// get the entry document file,
|
|
14
|
+
// if not exist, fallback to src/
|
|
15
|
+
const getDocumenByEntryName = function getDocumenByEntryName(entrypoints, entryName, fallbackDir) {
|
|
13
16
|
var _entrypoints$find;
|
|
14
17
|
const entryDir = (_entrypoints$find = entrypoints.find(item => item.entryName === entryName)) === null || _entrypoints$find === void 0 ? void 0 : _entrypoints$find.absoluteEntryDir;
|
|
15
|
-
const
|
|
18
|
+
const entryDirs = DOC_EXT.map(item => `${entryDir}${path.sep}${DOCUMENT_FILE_NAME}.${item}`);
|
|
19
|
+
const fallbackDirs = fallbackDir ? DOC_EXT.map(item => [fallbackDir, 'src', `${DOCUMENT_FILE_NAME}.${item}`].join(path.sep)) : [];
|
|
20
|
+
const docFile = findExists([...entryDirs, ...fallbackDirs]);
|
|
16
21
|
return docFile || undefined;
|
|
17
22
|
};
|
|
18
23
|
export default (() => ({
|
|
@@ -39,14 +44,11 @@ export default (() => ({
|
|
|
39
44
|
const documentEntry = (entryName, templateParameters) => {
|
|
40
45
|
const {
|
|
41
46
|
entrypoints,
|
|
42
|
-
internalDirectory
|
|
47
|
+
internalDirectory,
|
|
48
|
+
appDirectory
|
|
43
49
|
} = api.useAppContext();
|
|
44
50
|
// search the document.[tsx|jsx|js|ts] under entry
|
|
45
|
-
|
|
46
|
-
let documentFilePath = getDocumenByEntryName(entrypoints, entryName);
|
|
47
|
-
if (!documentFilePath) {
|
|
48
|
-
documentFilePath = getDocumenByEntryName(entrypoints, 'main');
|
|
49
|
-
}
|
|
51
|
+
const documentFilePath = getDocumenByEntryName(entrypoints, entryName, appDirectory);
|
|
50
52
|
// if no document file, do nothing as default
|
|
51
53
|
if (!documentFilePath) {
|
|
52
54
|
return null;
|
|
@@ -8,7 +8,7 @@ export const HTML_SSRDATASCRIPT_SEPARATOR = '<!--<?- SSRDataScript ?>-->';
|
|
|
8
8
|
export const DOCUMENT_SSR_PLACEHOLDER = encodeURIComponent(HTML_SEPARATOR);
|
|
9
9
|
export const DOCUMENT_CHUNKSMAP_PLACEHOLDER = encodeURIComponent(HTML_CHUNKSMAP_SEPARATOR);
|
|
10
10
|
export const DOCUMENT_SSRDATASCRIPT_PLACEHOLDER = encodeURIComponent(HTML_SSRDATASCRIPT_SEPARATOR);
|
|
11
|
-
export const DOCUMENT_FILE_NAME = '
|
|
11
|
+
export const DOCUMENT_FILE_NAME = 'Document';
|
|
12
12
|
export const DOCUMENT_SCRIPTS_PLACEHOLDER = encodeURIComponent('<!-- chunk scripts placeholder -->');
|
|
13
13
|
export const DOCUMENT_NO_SCRIPTE_PLACEHOLDER = encodeURIComponent('<!-- no-script -->');
|
|
14
14
|
export const PLACEHOLDER_REPLACER_MAP = {
|
|
@@ -4,11 +4,12 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { createBrowserRouter, createHashRouter, RouterProvider, createRoutesFromElements } from 'react-router-dom';
|
|
6
6
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
7
|
-
import { renderRoutes } from "./utils";
|
|
7
|
+
import { renderRoutes, urlJoin } from "./utils";
|
|
8
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
9
|
export const routerPlugin = ({
|
|
10
10
|
serverBase: _serverBase = [],
|
|
11
11
|
supportHtml5History: _supportHtml5History = true,
|
|
12
|
+
basename: _basename2 = '',
|
|
12
13
|
routesConfig,
|
|
13
14
|
createRoutes
|
|
14
15
|
}) => {
|
|
@@ -22,7 +23,7 @@ export const routerPlugin = ({
|
|
|
22
23
|
}, next) => {
|
|
23
24
|
// can not get routes config, skip wrapping React Router.
|
|
24
25
|
// e.g. App.tsx as the entrypoint
|
|
25
|
-
if (!routesConfig) {
|
|
26
|
+
if (!routesConfig && !createRoutes) {
|
|
26
27
|
return next({
|
|
27
28
|
App
|
|
28
29
|
});
|
|
@@ -30,13 +31,13 @@ export const routerPlugin = ({
|
|
|
30
31
|
const getRouteApp = () => {
|
|
31
32
|
return props => {
|
|
32
33
|
var _window$_SERVER_DATA;
|
|
33
|
-
const
|
|
34
|
-
const routes = createRoutes ? createRoutes() : createRoutesFromElements(routeElements);
|
|
34
|
+
const routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes(routesConfig));
|
|
35
35
|
const baseUrl = ((_window$_SERVER_DATA = window._SERVER_DATA) === null || _window$_SERVER_DATA === void 0 ? void 0 : _window$_SERVER_DATA.router.baseUrl) || select(location.pathname);
|
|
36
|
+
const _basename = baseUrl === '/' ? urlJoin(baseUrl, _basename2) : baseUrl;
|
|
36
37
|
const router = _supportHtml5History ? createBrowserRouter(routes, {
|
|
37
|
-
basename:
|
|
38
|
+
basename: _basename
|
|
38
39
|
}) : createHashRouter(routes, {
|
|
39
|
-
basename:
|
|
40
|
+
basename: _basename
|
|
40
41
|
});
|
|
41
42
|
return /*#__PURE__*/_jsx(App, _objectSpread(_objectSpread({}, props), {}, {
|
|
42
43
|
children: /*#__PURE__*/_jsx(RouterProvider, {
|
|
@@ -46,7 +47,7 @@ export const routerPlugin = ({
|
|
|
46
47
|
};
|
|
47
48
|
};
|
|
48
49
|
const RouteApp = getRouteApp();
|
|
49
|
-
if (routesConfig.globalApp) {
|
|
50
|
+
if (routesConfig !== null && routesConfig !== void 0 && routesConfig.globalApp) {
|
|
50
51
|
return next({
|
|
51
52
|
App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
|
|
52
53
|
});
|
|
@@ -8,7 +8,7 @@ import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
|
8
8
|
import { installGlobals } from '@remix-run/node';
|
|
9
9
|
import { createRoutesFromElements } from 'react-router-dom';
|
|
10
10
|
import { RuntimeReactContext } from "../../core";
|
|
11
|
-
import { renderRoutes } from "./utils";
|
|
11
|
+
import { renderRoutes, urlJoin } from "./utils";
|
|
12
12
|
|
|
13
13
|
// Polyfill Web Fetch API
|
|
14
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -54,6 +54,7 @@ export function createFetchHeaders(requestHeaders) {
|
|
|
54
54
|
return headers;
|
|
55
55
|
}
|
|
56
56
|
export const routerPlugin = ({
|
|
57
|
+
basename: _basename2 = '',
|
|
57
58
|
routesConfig,
|
|
58
59
|
createRoutes
|
|
59
60
|
}) => {
|
|
@@ -66,7 +67,7 @@ export const routerPlugin = ({
|
|
|
66
67
|
}, next) {
|
|
67
68
|
// can not get routes config, skip wrapping React Router.
|
|
68
69
|
// e.g. App.tsx as the entrypoint
|
|
69
|
-
if (!routesConfig) {
|
|
70
|
+
if (!routesConfig && !createRoutes) {
|
|
70
71
|
return next({
|
|
71
72
|
context
|
|
72
73
|
});
|
|
@@ -74,11 +75,14 @@ export const routerPlugin = ({
|
|
|
74
75
|
const {
|
|
75
76
|
request
|
|
76
77
|
} = context.ssrContext;
|
|
77
|
-
const
|
|
78
|
-
const
|
|
78
|
+
const baseUrl = request.baseUrl;
|
|
79
|
+
const _basename = baseUrl === '/' ? urlJoin(baseUrl, _basename2) : baseUrl;
|
|
80
|
+
const routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes(routesConfig));
|
|
79
81
|
const {
|
|
80
82
|
query
|
|
81
|
-
} = createStaticHandler(routes
|
|
83
|
+
} = createStaticHandler(routes, {
|
|
84
|
+
basename: _basename
|
|
85
|
+
});
|
|
82
86
|
const remixRequest = createFetchRequest(request);
|
|
83
87
|
const routerContext = await query(remixRequest);
|
|
84
88
|
if (routerContext instanceof Response) {
|
|
@@ -122,7 +126,7 @@ export const routerPlugin = ({
|
|
|
122
126
|
};
|
|
123
127
|
};
|
|
124
128
|
const RouteApp = getRouteApp();
|
|
125
|
-
if (routesConfig.globalApp) {
|
|
129
|
+
if (routesConfig !== null && routesConfig !== void 0 && routesConfig.globalApp) {
|
|
126
130
|
return next({
|
|
127
131
|
App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
|
|
128
132
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'react-router-dom/server';
|
|
@@ -49,12 +49,10 @@ const renderNestedRoute = (nestedRoute, parent) => {
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
if (!parent) {
|
|
52
|
+
if (!parent && element) {
|
|
53
53
|
element = /*#__PURE__*/_jsx(RootLayout, {
|
|
54
54
|
routes: [nestedRoute],
|
|
55
|
-
children:
|
|
56
|
-
children: element
|
|
57
|
-
})
|
|
55
|
+
children: element
|
|
58
56
|
});
|
|
59
57
|
}
|
|
60
58
|
routeProps.element = element;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1
4
|
import { getEntryOptions, SERVER_RENDER_FUNCTION_NAME, LOADABLE_STATS_FILE, isUseSSRBundle, createRuntimeExportsUtils, isSingleEntry } from '@modern-js/utils';
|
|
2
5
|
const PLUGIN_IDENTIFIER = 'ssr';
|
|
3
6
|
const hasStringSSREntry = userConfig => {
|
|
@@ -36,6 +39,7 @@ export default (() => ({
|
|
|
36
39
|
tools: {
|
|
37
40
|
webpackChain: (chain, {
|
|
38
41
|
name,
|
|
42
|
+
isServer,
|
|
39
43
|
CHAIN_ID
|
|
40
44
|
}) => {
|
|
41
45
|
const userConfig = api.useResolvedConfigContext();
|
|
@@ -46,6 +50,16 @@ export default (() => ({
|
|
|
46
50
|
filename: LOADABLE_STATS_FILE
|
|
47
51
|
}]);
|
|
48
52
|
}
|
|
53
|
+
|
|
54
|
+
// add environment variables to determine the node/browser
|
|
55
|
+
const prefix = `${appContext.metaName.split(/[-_]/)[0]}_`.toUpperCase();
|
|
56
|
+
const modernVars = {
|
|
57
|
+
[`process.env.${prefix}TARGET`]: JSON.stringify(isServer ? 'node' : 'browser')
|
|
58
|
+
};
|
|
59
|
+
chain.plugin(CHAIN_ID.PLUGIN.DEFINE).tap(args => {
|
|
60
|
+
const [vars, ...rest] = args;
|
|
61
|
+
return [_objectSpread(_objectSpread({}, vars), modernVars), ...rest];
|
|
62
|
+
});
|
|
49
63
|
},
|
|
50
64
|
babel: config => {
|
|
51
65
|
const userConfig = api.useResolvedConfigContext();
|
|
@@ -33,7 +33,11 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
33
33
|
} = routeManifest;
|
|
34
34
|
const cssChunks = [];
|
|
35
35
|
const matches = matchRoutes(routes, routerContext.location);
|
|
36
|
-
matches === null || matches === void 0 ? void 0 : matches.forEach(match => {
|
|
36
|
+
matches === null || matches === void 0 ? void 0 : matches.forEach((match, index) => {
|
|
37
|
+
// root layout css chunks should't be loaded
|
|
38
|
+
if (!index) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
37
41
|
const routeId = match.route.id;
|
|
38
42
|
if (routeId) {
|
|
39
43
|
const {
|
|
@@ -19,9 +19,16 @@ const getStoreConfig = config => {
|
|
|
19
19
|
const internalPlugins = ['immer', 'effects', 'autoActions', 'devtools'];
|
|
20
20
|
const plugins = [];
|
|
21
21
|
internalPlugins.filter(plugin => config[plugin] !== false).forEach(plugin => plugins.push(StatePluginHandleMap[plugin](config[plugin])));
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const storeConfig = {};
|
|
23
|
+
for (const [key, value] of Object.entries(config)) {
|
|
24
|
+
if (internalPlugins.includes(key)) {
|
|
25
|
+
plugins.push(StatePluginHandleMap[key](value));
|
|
26
|
+
} else {
|
|
27
|
+
storeConfig[key] = value;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
storeConfig.plugins = plugins;
|
|
31
|
+
return storeConfig;
|
|
25
32
|
};
|
|
26
33
|
const state = config => ({
|
|
27
34
|
name: '@modern-js/plugin-state',
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useRuntimeContext = exports.createApp = exports.bootstrap = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
-
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
9
8
|
var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
|
|
10
9
|
var _runtimeContext = require("../runtime-context");
|
|
11
10
|
var _plugin = require("./plugin");
|
|
@@ -105,7 +104,7 @@ id,
|
|
|
105
104
|
/**
|
|
106
105
|
* root.render need use root to run function
|
|
107
106
|
*/
|
|
108
|
-
root, ReactDOM
|
|
107
|
+
root, ReactDOM
|
|
109
108
|
// eslint-disable-next-line consistent-return
|
|
110
109
|
) => {
|
|
111
110
|
let App = BootApp;
|
|
@@ -163,7 +162,9 @@ root, ReactDOM = _reactDom.default
|
|
|
163
162
|
context.initialData = initialData;
|
|
164
163
|
}
|
|
165
164
|
const rootElement = typeof id !== 'string' ? id : document.getElementById(id || 'root');
|
|
166
|
-
|
|
165
|
+
if (!ReactDOM) {
|
|
166
|
+
throw Error('The `bootstrap` need provide `ReactDOM` parameter');
|
|
167
|
+
}
|
|
167
168
|
// https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html
|
|
168
169
|
const ModernRender = App => {
|
|
169
170
|
if (IS_REACT18) {
|
|
@@ -18,10 +18,15 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
18
18
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
19
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
20
|
const debug = (0, _utils.createDebugger)('html_genarate');
|
|
21
|
-
|
|
21
|
+
|
|
22
|
+
// get the entry document file,
|
|
23
|
+
// if not exist, fallback to src/
|
|
24
|
+
const getDocumenByEntryName = function getDocumenByEntryName(entrypoints, entryName, fallbackDir) {
|
|
22
25
|
var _entrypoints$find;
|
|
23
26
|
const entryDir = (_entrypoints$find = entrypoints.find(item => item.entryName === entryName)) === null || _entrypoints$find === void 0 ? void 0 : _entrypoints$find.absoluteEntryDir;
|
|
24
|
-
const
|
|
27
|
+
const entryDirs = _constants.DOC_EXT.map(item => `${entryDir}${_path.default.sep}${_constants.DOCUMENT_FILE_NAME}.${item}`);
|
|
28
|
+
const fallbackDirs = fallbackDir ? _constants.DOC_EXT.map(item => [fallbackDir, 'src', `${_constants.DOCUMENT_FILE_NAME}.${item}`].join(_path.default.sep)) : [];
|
|
29
|
+
const docFile = (0, _utils.findExists)([...entryDirs, ...fallbackDirs]);
|
|
25
30
|
return docFile || undefined;
|
|
26
31
|
};
|
|
27
32
|
var _default = () => ({
|
|
@@ -48,14 +53,11 @@ var _default = () => ({
|
|
|
48
53
|
const documentEntry = (entryName, templateParameters) => {
|
|
49
54
|
const {
|
|
50
55
|
entrypoints,
|
|
51
|
-
internalDirectory
|
|
56
|
+
internalDirectory,
|
|
57
|
+
appDirectory
|
|
52
58
|
} = api.useAppContext();
|
|
53
59
|
// search the document.[tsx|jsx|js|ts] under entry
|
|
54
|
-
|
|
55
|
-
let documentFilePath = getDocumenByEntryName(entrypoints, entryName);
|
|
56
|
-
if (!documentFilePath) {
|
|
57
|
-
documentFilePath = getDocumenByEntryName(entrypoints, 'main');
|
|
58
|
-
}
|
|
60
|
+
const documentFilePath = getDocumenByEntryName(entrypoints, entryName, appDirectory);
|
|
59
61
|
// if no document file, do nothing as default
|
|
60
62
|
if (!documentFilePath) {
|
|
61
63
|
return null;
|
|
@@ -21,7 +21,7 @@ const DOCUMENT_CHUNKSMAP_PLACEHOLDER = encodeURIComponent(HTML_CHUNKSMAP_SEPARAT
|
|
|
21
21
|
exports.DOCUMENT_CHUNKSMAP_PLACEHOLDER = DOCUMENT_CHUNKSMAP_PLACEHOLDER;
|
|
22
22
|
const DOCUMENT_SSRDATASCRIPT_PLACEHOLDER = encodeURIComponent(HTML_SSRDATASCRIPT_SEPARATOR);
|
|
23
23
|
exports.DOCUMENT_SSRDATASCRIPT_PLACEHOLDER = DOCUMENT_SSRDATASCRIPT_PLACEHOLDER;
|
|
24
|
-
const DOCUMENT_FILE_NAME = '
|
|
24
|
+
const DOCUMENT_FILE_NAME = 'Document';
|
|
25
25
|
exports.DOCUMENT_FILE_NAME = DOCUMENT_FILE_NAME;
|
|
26
26
|
const DOCUMENT_SCRIPTS_PLACEHOLDER = encodeURIComponent('<!-- chunk scripts placeholder -->');
|
|
27
27
|
exports.DOCUMENT_SCRIPTS_PLACEHOLDER = DOCUMENT_SCRIPTS_PLACEHOLDER;
|
|
@@ -16,6 +16,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
16
16
|
const routerPlugin = ({
|
|
17
17
|
serverBase: _serverBase = [],
|
|
18
18
|
supportHtml5History: _supportHtml5History = true,
|
|
19
|
+
basename: _basename2 = '',
|
|
19
20
|
routesConfig,
|
|
20
21
|
createRoutes
|
|
21
22
|
}) => {
|
|
@@ -29,7 +30,7 @@ const routerPlugin = ({
|
|
|
29
30
|
}, next) => {
|
|
30
31
|
// can not get routes config, skip wrapping React Router.
|
|
31
32
|
// e.g. App.tsx as the entrypoint
|
|
32
|
-
if (!routesConfig) {
|
|
33
|
+
if (!routesConfig && !createRoutes) {
|
|
33
34
|
return next({
|
|
34
35
|
App
|
|
35
36
|
});
|
|
@@ -37,13 +38,13 @@ const routerPlugin = ({
|
|
|
37
38
|
const getRouteApp = () => {
|
|
38
39
|
return props => {
|
|
39
40
|
var _window$_SERVER_DATA;
|
|
40
|
-
const
|
|
41
|
-
const routes = createRoutes ? createRoutes() : (0, _reactRouterDom.createRoutesFromElements)(routeElements);
|
|
41
|
+
const routes = createRoutes ? createRoutes() : (0, _reactRouterDom.createRoutesFromElements)((0, _utils.renderRoutes)(routesConfig));
|
|
42
42
|
const baseUrl = ((_window$_SERVER_DATA = window._SERVER_DATA) === null || _window$_SERVER_DATA === void 0 ? void 0 : _window$_SERVER_DATA.router.baseUrl) || select(location.pathname);
|
|
43
|
+
const _basename = baseUrl === '/' ? (0, _utils.urlJoin)(baseUrl, _basename2) : baseUrl;
|
|
43
44
|
const router = _supportHtml5History ? (0, _reactRouterDom.createBrowserRouter)(routes, {
|
|
44
|
-
basename:
|
|
45
|
+
basename: _basename
|
|
45
46
|
}) : (0, _reactRouterDom.createHashRouter)(routes, {
|
|
46
|
-
basename:
|
|
47
|
+
basename: _basename
|
|
47
48
|
});
|
|
48
49
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(App, _objectSpread(_objectSpread({}, props), {}, {
|
|
49
50
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.RouterProvider, {
|
|
@@ -53,7 +54,7 @@ const routerPlugin = ({
|
|
|
53
54
|
};
|
|
54
55
|
};
|
|
55
56
|
const RouteApp = getRouteApp();
|
|
56
|
-
if (routesConfig.globalApp) {
|
|
57
|
+
if (routesConfig !== null && routesConfig !== void 0 && routesConfig.globalApp) {
|
|
57
58
|
return next({
|
|
58
59
|
App: (0, _hoistNonReactStatics.default)(RouteApp, routesConfig.globalApp)
|
|
59
60
|
});
|
|
@@ -63,6 +63,7 @@ function createFetchHeaders(requestHeaders) {
|
|
|
63
63
|
return headers;
|
|
64
64
|
}
|
|
65
65
|
const routerPlugin = ({
|
|
66
|
+
basename: _basename2 = '',
|
|
66
67
|
routesConfig,
|
|
67
68
|
createRoutes
|
|
68
69
|
}) => {
|
|
@@ -75,7 +76,7 @@ const routerPlugin = ({
|
|
|
75
76
|
}, next) {
|
|
76
77
|
// can not get routes config, skip wrapping React Router.
|
|
77
78
|
// e.g. App.tsx as the entrypoint
|
|
78
|
-
if (!routesConfig) {
|
|
79
|
+
if (!routesConfig && !createRoutes) {
|
|
79
80
|
return next({
|
|
80
81
|
context
|
|
81
82
|
});
|
|
@@ -83,11 +84,14 @@ const routerPlugin = ({
|
|
|
83
84
|
const {
|
|
84
85
|
request
|
|
85
86
|
} = context.ssrContext;
|
|
86
|
-
const
|
|
87
|
-
const
|
|
87
|
+
const baseUrl = request.baseUrl;
|
|
88
|
+
const _basename = baseUrl === '/' ? (0, _utils.urlJoin)(baseUrl, _basename2) : baseUrl;
|
|
89
|
+
const routes = createRoutes ? createRoutes() : (0, _reactRouterDom.createRoutesFromElements)((0, _utils.renderRoutes)(routesConfig));
|
|
88
90
|
const {
|
|
89
91
|
query
|
|
90
|
-
} = (0, _router.unstable_createStaticHandler)(routes
|
|
92
|
+
} = (0, _router.unstable_createStaticHandler)(routes, {
|
|
93
|
+
basename: _basename
|
|
94
|
+
});
|
|
91
95
|
const remixRequest = createFetchRequest(request);
|
|
92
96
|
const routerContext = await query(remixRequest);
|
|
93
97
|
if (routerContext instanceof Response) {
|
|
@@ -131,7 +135,7 @@ const routerPlugin = ({
|
|
|
131
135
|
};
|
|
132
136
|
};
|
|
133
137
|
const RouteApp = getRouteApp();
|
|
134
|
-
if (routesConfig.globalApp) {
|
|
138
|
+
if (routesConfig !== null && routesConfig !== void 0 && routesConfig.globalApp) {
|
|
135
139
|
return next({
|
|
136
140
|
App: (0, _hoistNonReactStatics.default)(RouteApp, routesConfig.globalApp)
|
|
137
141
|
});
|