ssr-plugin-react 5.6.26 → 5.6.31
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 +19 -0
- package/README.md +5 -2
- package/cjs/config/base.js +1 -1
- package/cjs/entry/client-entry.js +6 -5
- package/cjs/entry/create-context.js +1 -1
- package/cjs/entry/server-entry.js +6 -5
- package/esm/config/base.js +1 -1
- package/esm/entry/client-entry.js +6 -5
- package/esm/entry/create-context.js +1 -1
- package/esm/entry/server-entry.js +6 -5
- package/package.json +7 -7
- package/src/config/base.ts +1 -1
- package/src/entry/client-entry.tsx +4 -3
- package/src/entry/create-context.ts +1 -1
- package/src/entry/server-entry.tsx +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [5.6.31](https://github.com/ykfe/ssr/compare/v5.6.30...v5.6.31) (2021-10-21)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package ssr-plugin-react
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [5.6.27](https://github.com/ykfe/ssr/compare/v5.6.26...v5.6.27) (2021-10-14)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* queryString annotation ([#121](https://github.com/ykfe/ssr/issues/121)) ([b939ca9](https://github.com/ykfe/ssr/commit/b939ca9dfce93c297a5408c87af0617985a55cd1))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## [5.6.26](https://github.com/ykfe/ssr/compare/v5.6.25...v5.6.26) (2021-09-29)
|
|
7
26
|
|
|
8
27
|
**Note:** Version bump only for package ssr-plugin-react
|
package/README.md
CHANGED
|
@@ -100,6 +100,9 @@
|
|
|
100
100
|
<td align="center" style="height: 100px"><a href="https://m.film.qq.com/x/tva-vip-center/" target="_blank"><img src="https://res.wx.qq.com/op_res/x7sWI9AfUK1QwH0EDhKp4e_bGWxYOQ_1RlZqBFy9JntJzaE4aRzNhVgmxLNloAFpSQ-mBr9X9pux3QlV9QHHvQ" width="200px;margin: 20px 0" alt="腾讯视频"/><br />
|
|
101
101
|
<a href="https://m.film.qq.com/x/tva-vip-center/" target="_bvlank"><b>腾讯视频
|
|
102
102
|
</b></a></td>
|
|
103
|
+
<td align="center" style="height: 100px"><a href="https://blog.dreamer2q.wang/" target="_blank"><img src="https://res.wx.qq.com/op_res/MxxGgjPFRiTgjiReUefs2aMce-SgNvxxTB9U87YYhcOu6KPw9er7r2Lc0ne-b90nFstTUpc8REDwpxfUreKV1g" width="200px;margin: 20px 0" alt="Dream2qBlog"/><br />
|
|
104
|
+
<a href="https://blog.dreamer2q.wang/" target="_bvlank"><b>个人博客
|
|
105
|
+
</b></a></td>
|
|
103
106
|
</tr>
|
|
104
107
|
</table>
|
|
105
108
|
|
|
@@ -255,8 +258,8 @@ $ npm run start:vite # 以 vite 模式启动,等价于 npx ssr start --vite
|
|
|
255
258
|
欢迎直接扫码加入钉钉群或者微信群
|
|
256
259
|
|
|
257
260
|
<div style="display:flex">
|
|
258
|
-
<img src="https://res.wx.qq.com/op_res/
|
|
259
|
-
<img src="https://res.wx.qq.com/op_res/
|
|
261
|
+
<img src="https://res.wx.qq.com/op_res/7F1t4Z8yCHWilehbcFGjAj0yVn0URMiWBGVJa-TVu_eqw5IwUXA2kPYBnfX6YRHy0FVBB-yC6l0IEL02QTJkLg" width="300">
|
|
262
|
+
<img src="https://res.wx.qq.com/op_res/e7Z2b52xu-o9gaw-FgTmM8w-ohj_vFoDwC9JFl7N3o4c5oThkJ1plMT4D2GrC0rheo5mu5pkgHSw6s-Z8UZhvg" width="300">
|
|
260
263
|
</div>
|
|
261
264
|
|
|
262
265
|
## 前端开发手册
|
package/cjs/config/base.js
CHANGED
|
@@ -9,15 +9,16 @@ const ssr_hoc_react_1 = require("ssr-hoc-react");
|
|
|
9
9
|
// @ts-expect-error
|
|
10
10
|
const Routes = require("_build/ssr-temporary-routes");
|
|
11
11
|
const context_1 = require("./context");
|
|
12
|
-
const { FeRoutes, layoutFetch, App,
|
|
12
|
+
const { FeRoutes, layoutFetch, App, PrefixRouterBase } = Routes;
|
|
13
13
|
const clientRender = async () => {
|
|
14
|
-
var _a, _b;
|
|
14
|
+
var _a, _b, _c;
|
|
15
15
|
const IApp = App !== null && App !== void 0 ? App : function (props) {
|
|
16
16
|
return props.children;
|
|
17
17
|
};
|
|
18
18
|
// 客户端渲染||hydrate
|
|
19
|
-
const
|
|
20
|
-
|
|
19
|
+
const baseName = (_a = window.prefix) !== null && _a !== void 0 ? _a : PrefixRouterBase;
|
|
20
|
+
const routes = await (0, ssr_client_utils_1.preloadComponent)(FeRoutes, baseName);
|
|
21
|
+
ReactDOM[window.__USE_SSR__ ? 'hydrate' : 'render'](React.createElement(react_router_dom_1.BrowserRouter, { basename: baseName },
|
|
21
22
|
React.createElement(context_1.AppContext, null,
|
|
22
23
|
React.createElement(react_router_dom_1.Switch, null,
|
|
23
24
|
React.createElement(IApp, null,
|
|
@@ -31,7 +32,7 @@ const clientRender = async () => {
|
|
|
31
32
|
return (React.createElement(react_router_dom_1.Route, { exact: true, key: path, path: path, render: () => React.createElement(WrappedComponent, { key: location.pathname }) }));
|
|
32
33
|
})))))), document.getElementById('app'));
|
|
33
34
|
if (!window.__USE_VITE__) {
|
|
34
|
-
(
|
|
35
|
+
(_c = (_b = module === null || module === void 0 ? void 0 : module.hot) === null || _b === void 0 ? void 0 : _b.accept) === null || _c === void 0 ? void 0 : _c.call(_b); // webpack 场景下的 hmr
|
|
35
36
|
}
|
|
36
37
|
};
|
|
37
38
|
exports.clientRender = clientRender;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.clientContext = exports.serverContext = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
// 服务端需要为每一个请求创建全新的
|
|
5
|
+
// 服务端需要为每一个请求创建全新的 context 防止请求污染
|
|
6
6
|
const serverContext = (context) => {
|
|
7
7
|
return (0, react_1.createContext)(context);
|
|
8
8
|
};
|
|
@@ -10,14 +10,15 @@ const Routes = require("_build/ssr-temporary-routes");
|
|
|
10
10
|
const create_context_1 = require("./create-context");
|
|
11
11
|
// @ts-expect-error
|
|
12
12
|
const index_tsx_1 = require("@/components/layout/index.tsx");
|
|
13
|
-
const { FeRoutes, layoutFetch,
|
|
13
|
+
const { FeRoutes, layoutFetch, PrefixRouterBase, state } = Routes;
|
|
14
14
|
const serverRender = async (ctx, config) => {
|
|
15
15
|
var _a, _b;
|
|
16
|
-
const { cssOrder, jsOrder, dynamic, mode, chunkName, parallelFetch, disableClientRender } = config;
|
|
16
|
+
const { cssOrder, jsOrder, dynamic, mode, chunkName, parallelFetch, disableClientRender, prefix } = config;
|
|
17
17
|
global.window = (_a = global.window) !== null && _a !== void 0 ? _a : {}; // 防止覆盖上层应用自己定义的 window 对象
|
|
18
|
-
let path = ctx.request.path; // 这里取 pathname 不能够包含
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
let path = ctx.request.path; // 这里取 pathname 不能够包含 queryString
|
|
19
|
+
const base = prefix !== null && prefix !== void 0 ? prefix : PrefixRouterBase; // 以开发者实际传入的为最高优先级
|
|
20
|
+
if (base) {
|
|
21
|
+
path = (0, ssr_server_utils_1.normalizePath)(path, base);
|
|
21
22
|
}
|
|
22
23
|
const { window } = global;
|
|
23
24
|
const routeItem = (0, ssr_server_utils_1.findRoute)(FeRoutes, path);
|
package/esm/config/base.js
CHANGED
|
@@ -6,15 +6,16 @@ import { wrapComponent } from 'ssr-hoc-react';
|
|
|
6
6
|
// @ts-expect-error
|
|
7
7
|
import * as Routes from '_build/ssr-temporary-routes';
|
|
8
8
|
import { AppContext } from './context';
|
|
9
|
-
const { FeRoutes, layoutFetch, App,
|
|
9
|
+
const { FeRoutes, layoutFetch, App, PrefixRouterBase } = Routes;
|
|
10
10
|
const clientRender = async () => {
|
|
11
|
-
var _a, _b;
|
|
11
|
+
var _a, _b, _c;
|
|
12
12
|
const IApp = App !== null && App !== void 0 ? App : function (props) {
|
|
13
13
|
return props.children;
|
|
14
14
|
};
|
|
15
15
|
// 客户端渲染||hydrate
|
|
16
|
-
const
|
|
17
|
-
|
|
16
|
+
const baseName = (_a = window.prefix) !== null && _a !== void 0 ? _a : PrefixRouterBase;
|
|
17
|
+
const routes = await preloadComponent(FeRoutes, baseName);
|
|
18
|
+
ReactDOM[window.__USE_SSR__ ? 'hydrate' : 'render'](React.createElement(BrowserRouter, { basename: baseName },
|
|
18
19
|
React.createElement(AppContext, null,
|
|
19
20
|
React.createElement(Switch, null,
|
|
20
21
|
React.createElement(IApp, null,
|
|
@@ -28,7 +29,7 @@ const clientRender = async () => {
|
|
|
28
29
|
return (React.createElement(Route, { exact: true, key: path, path: path, render: () => React.createElement(WrappedComponent, { key: location.pathname }) }));
|
|
29
30
|
})))))), document.getElementById('app'));
|
|
30
31
|
if (!window.__USE_VITE__) {
|
|
31
|
-
(
|
|
32
|
+
(_c = (_b = module === null || module === void 0 ? void 0 : module.hot) === null || _b === void 0 ? void 0 : _b.accept) === null || _c === void 0 ? void 0 : _c.call(_b); // webpack 场景下的 hmr
|
|
32
33
|
}
|
|
33
34
|
};
|
|
34
35
|
if (!window.__disableClientRender__) {
|
|
@@ -7,14 +7,15 @@ import * as Routes from '_build/ssr-temporary-routes';
|
|
|
7
7
|
import { serverContext } from './create-context';
|
|
8
8
|
// @ts-expect-error
|
|
9
9
|
import Layout from '@/components/layout/index.tsx';
|
|
10
|
-
const { FeRoutes, layoutFetch,
|
|
10
|
+
const { FeRoutes, layoutFetch, PrefixRouterBase, state } = Routes;
|
|
11
11
|
const serverRender = async (ctx, config) => {
|
|
12
12
|
var _a, _b;
|
|
13
|
-
const { cssOrder, jsOrder, dynamic, mode, chunkName, parallelFetch, disableClientRender } = config;
|
|
13
|
+
const { cssOrder, jsOrder, dynamic, mode, chunkName, parallelFetch, disableClientRender, prefix } = config;
|
|
14
14
|
global.window = (_a = global.window) !== null && _a !== void 0 ? _a : {}; // 防止覆盖上层应用自己定义的 window 对象
|
|
15
|
-
let path = ctx.request.path; // 这里取 pathname 不能够包含
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
let path = ctx.request.path; // 这里取 pathname 不能够包含 queryString
|
|
16
|
+
const base = prefix !== null && prefix !== void 0 ? prefix : PrefixRouterBase; // 以开发者实际传入的为最高优先级
|
|
17
|
+
if (base) {
|
|
18
|
+
path = normalizePath(path, base);
|
|
18
19
|
}
|
|
19
20
|
const { window } = global;
|
|
20
21
|
const routeItem = findRoute(FeRoutes, path);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssr-plugin-react",
|
|
3
|
-
"version": "5.6.
|
|
3
|
+
"version": "5.6.31",
|
|
4
4
|
"description": "plugin-react for ssr",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"postcss-safe-parser": "4.0.1",
|
|
54
54
|
"react-dev-utils": "^11.0.4",
|
|
55
55
|
"serialize-javascript": "^3.0.0",
|
|
56
|
-
"ssr-client-utils": "^5.6.
|
|
57
|
-
"ssr-hoc-react": "^5.6.
|
|
58
|
-
"ssr-server-utils": "^5.6.
|
|
59
|
-
"ssr-webpack": "^5.6.
|
|
56
|
+
"ssr-client-utils": "^5.6.28",
|
|
57
|
+
"ssr-hoc-react": "^5.6.29",
|
|
58
|
+
"ssr-server-utils": "^5.6.28",
|
|
59
|
+
"ssr-webpack": "^5.6.28",
|
|
60
60
|
"terser-webpack-plugin": "^2.3.5",
|
|
61
61
|
"url-loader": "1.1.1",
|
|
62
62
|
"webpack-bundle-analyzer": "^3.6.1",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@types/react-router-dom": "^5.1.3",
|
|
71
71
|
"@types/serialize-javascript": "^1.5.0",
|
|
72
72
|
"@types/webpack": "^4.41.10",
|
|
73
|
-
"ssr-types-react": "^5.6.
|
|
73
|
+
"ssr-types-react": "^5.6.29"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "8da1715438cebeae99cfa30355a1563e1823a0d9"
|
|
76
76
|
}
|
package/src/config/base.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { IWindow, LayoutProps, ReactClientESMFeRouteItem, ReactClientRoutesType
|
|
|
8
8
|
import * as Routes from '_build/ssr-temporary-routes'
|
|
9
9
|
import { AppContext } from './context'
|
|
10
10
|
|
|
11
|
-
const { FeRoutes, layoutFetch, App,
|
|
11
|
+
const { FeRoutes, layoutFetch, App, PrefixRouterBase } = Routes as ReactClientRoutesType
|
|
12
12
|
|
|
13
13
|
declare const module: any
|
|
14
14
|
declare const window: IWindow
|
|
@@ -18,9 +18,10 @@ const clientRender = async (): Promise<void> => {
|
|
|
18
18
|
return props.children!
|
|
19
19
|
}
|
|
20
20
|
// 客户端渲染||hydrate
|
|
21
|
-
const
|
|
21
|
+
const baseName = window.prefix ?? PrefixRouterBase
|
|
22
|
+
const routes = await preloadComponent(FeRoutes, baseName)
|
|
22
23
|
ReactDOM[window.__USE_SSR__ ? 'hydrate' : 'render'](
|
|
23
|
-
<BrowserRouter basename={
|
|
24
|
+
<BrowserRouter basename={baseName}>
|
|
24
25
|
<AppContext>
|
|
25
26
|
<Switch>
|
|
26
27
|
<IApp>
|
|
@@ -9,16 +9,17 @@ import { serverContext } from './create-context'
|
|
|
9
9
|
// @ts-expect-error
|
|
10
10
|
import Layout from '@/components/layout/index.tsx'
|
|
11
11
|
|
|
12
|
-
const { FeRoutes, layoutFetch,
|
|
12
|
+
const { FeRoutes, layoutFetch, PrefixRouterBase, state } = Routes as ReactRoutesType
|
|
13
13
|
|
|
14
14
|
declare const global: IGlobal
|
|
15
15
|
|
|
16
16
|
const serverRender = async (ctx: ISSRContext, config: IConfig): Promise<React.ReactElement> => {
|
|
17
|
-
const { cssOrder, jsOrder, dynamic, mode, chunkName, parallelFetch, disableClientRender } = config
|
|
17
|
+
const { cssOrder, jsOrder, dynamic, mode, chunkName, parallelFetch, disableClientRender, prefix } = config
|
|
18
18
|
global.window = global.window ?? {} // 防止覆盖上层应用自己定义的 window 对象
|
|
19
|
-
let path = ctx.request.path // 这里取 pathname 不能够包含
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
let path = ctx.request.path // 这里取 pathname 不能够包含 queryString
|
|
20
|
+
const base = prefix ?? PrefixRouterBase // 以开发者实际传入的为最高优先级
|
|
21
|
+
if (base) {
|
|
22
|
+
path = normalizePath(path, base)
|
|
22
23
|
}
|
|
23
24
|
const { window } = global
|
|
24
25
|
const routeItem = findRoute<ReactServerESMFeRouteItem>(FeRoutes, path)
|