ssr-plugin-react 6.2.56 → 6.2.57
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/.turbo/turbo-build.log +3 -3
- package/CHANGELOG.md +29 -0
- package/README.md +2 -1
- package/cjs/entry/server-entry.d.ts +5 -1
- package/cjs/entry/server-entry.d.ts.map +1 -1
- package/cjs/entry/server-entry.js +61 -59
- package/cjs/entry/server-entry.js.map +1 -1
- package/esm/entry/server-entry.d.ts +5 -1
- package/esm/entry/server-entry.d.ts.map +1 -1
- package/esm/entry/server-entry.js +63 -61
- package/esm/entry/server-entry.js.map +1 -1
- package/package.json +2 -1
- package/src/entry/server-entry.tsx +65 -63
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
ssr-plugin-react:build: cache hit, replaying output
|
|
1
|
+
ssr-plugin-react:build: cache hit, replaying output 1624d4a22ea6bb71
|
|
2
2
|
ssr-plugin-react:build:
|
|
3
|
-
ssr-plugin-react:build: > ssr-plugin-react@6.2.
|
|
3
|
+
ssr-plugin-react:build: > ssr-plugin-react@6.2.57 build /home/runner/work/ssr/ssr/packages/plugin-react
|
|
4
4
|
ssr-plugin-react:build: > concurrently "tsc -p ./tsconfig.cjs.json " " tsc -p ./tsconfig.esm.json"
|
|
5
5
|
ssr-plugin-react:build:
|
|
6
|
-
ssr-plugin-react:build: [1] tsc -p ./tsconfig.esm.json exited with code 0
|
|
7
6
|
ssr-plugin-react:build: [0] tsc -p ./tsconfig.cjs.json exited with code 0
|
|
7
|
+
ssr-plugin-react:build: [1] tsc -p ./tsconfig.esm.json exited with code 0
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
+
## [6.2.57](https://github.com/zhangyuang/ssr/compare/plugin-react@6.2.56...plugin-react@6.2.57) (2023-02-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* add NODE_OPTIONS tips when nodejs version > 16 ([3492698](https://github.com/zhangyuang/ssr/commit/34926987bb3f6f7562b87b14289f509cecf2a6fa))
|
|
7
|
+
* defaultExternals add react-dom close [#253](https://github.com/zhangyuang/ssr/issues/253) ([f748cee](https://github.com/zhangyuang/ssr/commit/f748ceeac2cf3205549b2a818e9cc4e386a5c250))
|
|
8
|
+
* external ([005b74a](https://github.com/zhangyuang/ssr/commit/005b74a35bbecfc44a1235b8d256aaf934b595bc))
|
|
9
|
+
* judge node version ([b6f17b3](https://github.com/zhangyuang/ssr/commit/b6f17b3a04afdcdea936554b60e6db96e2053532))
|
|
10
|
+
* spa build ([d399bea](https://github.com/zhangyuang/ssr/commit/d399beac0dc3a336194651b3fc05f011a7515ff1))
|
|
11
|
+
* types ([7015666](https://github.com/zhangyuang/ssr/commit/70156663c28c87628596a4466cf8c647d18335dd))
|
|
12
|
+
* update vite-vue plugin version ([#261](https://github.com/zhangyuang/ssr/issues/261)) ([31d3844](https://github.com/zhangyuang/ssr/commit/31d38447e49bc8055d59e4452d02fc9825afab64))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* add @types/koa ([0dffea6](https://github.com/zhangyuang/ssr/commit/0dffea66264dafde6ff16fd211a14137fd8b6e5d))
|
|
18
|
+
* add path-to-regexp to vite build vendorlist ([8934da5](https://github.com/zhangyuang/ssr/commit/8934da5dca7c709d4cbc0635bb194057b59dc2c0))
|
|
19
|
+
* add ssr start --help tips in midway ([f76f0a1](https://github.com/zhangyuang/ssr/commit/f76f0a1a9dc49cb175a800655699a10065571ae2))
|
|
20
|
+
* add vite dev css flicker tips ([1744a72](https://github.com/zhangyuang/ssr/commit/1744a72fbc056532336daef4ee0a439fefe529ff))
|
|
21
|
+
* build spa support priority ([d456969](https://github.com/zhangyuang/ssr/commit/d4569697d00a720c2e820206ebb5df1002c4af8d))
|
|
22
|
+
* spa support extrajsorder cssorder ([ebc82c5](https://github.com/zhangyuang/ssr/commit/ebc82c52d35502533130fc4d6e551aed0f9d1137))
|
|
23
|
+
* spa with customeFooterScript is array ([b9508ae](https://github.com/zhangyuang/ssr/commit/b9508aea7e98bbbdaecaa318667d10d04c10aa82))
|
|
24
|
+
* support element-plus ([e13fed8](https://github.com/zhangyuang/ssr/commit/e13fed826ad634a31f3506afc0a7958340c9dc87))
|
|
25
|
+
* support jsOrderPriority🤔 cssOrderPriority🤔 ([9db9a7d](https://github.com/zhangyuang/ssr/commit/9db9a7d03e8c47a93ca459b8b8b3fad571f73960))
|
|
26
|
+
* use asynclocalstorage for get correct pinia store app context instance ([a38d3e9](https://github.com/zhangyuang/ssr/commit/a38d3e99c2a6aa6a64a20099a59fb06edba1b5ea))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
1
30
|
## [6.2.56](https://github.com/zhangyuang/ssr/compare/plugin-react@6.2.55...plugin-react@6.2.56) (2022-11-22)
|
|
2
31
|
|
|
3
32
|
|
package/README.md
CHANGED
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
- 可能会改动技术栈,如从 `Vue2` 升级为 `Vue3`,从 `Vue3` 降级为 `Vue2` 或 `React/Vue` 互相切换
|
|
41
41
|
- 需要在服务端渲染场景下开箱即用使用 `antd` `vant` 等流行 `ui` 库
|
|
42
42
|
- 需要能够同时支持 `Webpack`, `Vite` 两种开发工具,以便同时得到快速的启动速度 `HMR` 速度以及稳定的生产环境代码
|
|
43
|
-
- 需要在 `Vue3
|
|
43
|
+
- 需要在 `Vue3 SSR` 使用 [pinia](https://pinia.vuejs.org/) 作为数据管理方案
|
|
44
|
+
- 只是单纯的需要一个更快更好用的 `cra` 或 `vue-cli`, `ssr` 框架在纯 `csr` 场景的支持也十分优秀
|
|
44
45
|
|
|
45
46
|
## 哪些应用在使用
|
|
46
47
|
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { ISSRContext, IConfig } from 'ssr-types';
|
|
2
3
|
import { Routes } from './create-router';
|
|
3
|
-
declare const serverRender: (ctx: ISSRContext, config: IConfig) => Promise<string | NodeJS.ReadableStream
|
|
4
|
+
declare const serverRender: (ctx: ISSRContext, config: IConfig) => Promise<string | import("stream").Readable | NodeJS.ReadableStream | {
|
|
5
|
+
html: string;
|
|
6
|
+
teleportsContext: any;
|
|
7
|
+
}>;
|
|
4
8
|
export { serverRender, Routes };
|
|
5
9
|
//# sourceMappingURL=server-entry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-entry.d.ts","sourceRoot":"","sources":["../../src/entry/server-entry.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server-entry.d.ts","sourceRoot":"","sources":["../../src/entry/server-entry.tsx"],"names":[],"mappings":";AAQA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAmD,MAAM,WAAW,CAAA;AAGjG,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAIxC,QAAA,MAAM,YAAY,QAAe,WAAW,UAAU,OAAO;;;EA2E5D,CAAA;AAED,OAAO,EACL,YAAY,EACZ,MAAM,EACP,CAAA"}
|
|
@@ -5,6 +5,8 @@ const React = require("react");
|
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const react_router_dom_1 = require("react-router-dom");
|
|
7
7
|
const server_1 = require("react-dom/server");
|
|
8
|
+
// @ts-expect-error
|
|
9
|
+
const server_2 = require("ssr-react-dom/server");
|
|
8
10
|
const ssr_common_utils_1 = require("ssr-common-utils");
|
|
9
11
|
const ssr_serialize_javascript_1 = require("ssr-serialize-javascript");
|
|
10
12
|
const create_context_1 = require("_build/create-context");
|
|
@@ -12,71 +14,71 @@ const create_router_1 = require("./create-router");
|
|
|
12
14
|
Object.defineProperty(exports, "Routes", { enumerable: true, get: function () { return create_router_1.Routes; } });
|
|
13
15
|
const { FeRoutes, layoutFetch, state, Layout } = create_router_1.Routes;
|
|
14
16
|
const serverRender = async (ctx, config) => {
|
|
15
|
-
var _a
|
|
17
|
+
var _a;
|
|
16
18
|
const { mode, parallelFetch, prefix, isVite, isDev, clientPrefix, stream } = config;
|
|
17
19
|
const rawPath = (_a = ctx.request.path) !== null && _a !== void 0 ? _a : ctx.request.routerPath;
|
|
18
20
|
const path = (0, ssr_common_utils_1.normalizePath)(rawPath, prefix);
|
|
19
21
|
const routeItem = (0, ssr_common_utils_1.findRoute)(FeRoutes, path);
|
|
20
|
-
(0, ssr_common_utils_1.
|
|
21
|
-
if (!routeItem) {
|
|
22
|
-
throw new Error(`
|
|
23
|
-
With Path: ${path} search component failed
|
|
24
|
-
If you create new folder or component file, please restart server by npm start
|
|
25
|
-
`);
|
|
26
|
-
}
|
|
22
|
+
(0, ssr_common_utils_1.checkRoute)({ routeItem, path });
|
|
27
23
|
const { fetch, webpackChunkName, component } = routeItem;
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const injectState = isCsr ? React.createElement("script", { dangerouslySetInnerHTML: { __html: `window.prefix="${prefix}";${clientPrefix ? `window.clientPrefix="${clientPrefix}";` : ''}` } }) : React.createElement("script", { dangerouslySetInnerHTML: {
|
|
63
|
-
__html: `window.__USE_SSR__=true; window.__INITIAL_DATA__ =${(0, ssr_serialize_javascript_1.serialize)(combineData)}; window.prefix="${prefix}";${clientPrefix ? `window.clientPrefix="${clientPrefix}";` : ''}`
|
|
64
|
-
} });
|
|
65
|
-
// with jsx type error, use createElement here
|
|
66
|
-
const ele = (0, react_1.createElement)(react_router_dom_1.StaticRouter, {
|
|
67
|
-
location: ctx.request.url,
|
|
68
|
-
basename: prefix === '/' ? undefined : prefix
|
|
69
|
-
}, (0, react_1.createElement)(create_context_1.STORE_CONTEXT.Provider, {
|
|
70
|
-
value: {
|
|
71
|
-
state: combineData
|
|
24
|
+
const fn = async () => {
|
|
25
|
+
var _a;
|
|
26
|
+
const dynamicCssOrder = await (0, ssr_common_utils_1.getAsyncCssChunk)(ctx, webpackChunkName, config);
|
|
27
|
+
const dynamicJsOrder = await (0, ssr_common_utils_1.getAsyncJsChunk)(ctx, webpackChunkName, config);
|
|
28
|
+
const manifest = await (0, ssr_common_utils_1.getManifest)(config);
|
|
29
|
+
const injectCss = ((isVite && isDev) ? [
|
|
30
|
+
React.createElement("script", { src: "/@vite/client", type: "module", key: "vite-client" }),
|
|
31
|
+
React.createElement("script", { key: "vite-react-refresh", type: "module", dangerouslySetInnerHTML: {
|
|
32
|
+
__html: ssr_common_utils_1.reactRefreshFragment
|
|
33
|
+
} })
|
|
34
|
+
] : dynamicCssOrder.map(css => manifest[css]).filter(Boolean).map(css => React.createElement("link", { rel: 'stylesheet', key: css, href: css })))
|
|
35
|
+
.concat((isVite && isDev) ? [] : dynamicJsOrder.map(js => manifest[js]).filter(Boolean).map(js => React.createElement("link", { href: js, as: "script", rel: isVite ? 'modulepreload' : 'preload', key: js })));
|
|
36
|
+
const injectScript = [
|
|
37
|
+
...(isVite ? [React.createElement("script", { key: "viteWindowInit", dangerouslySetInnerHTML: {
|
|
38
|
+
__html: 'window.__USE_VITE__=true'
|
|
39
|
+
} })] : []),
|
|
40
|
+
...((isVite && isDev) ? [React.createElement("script", { type: "module", src: '/node_modules/ssr-plugin-react/esm/entry/client-entry.js', key: "vite-react-entry" })] : []),
|
|
41
|
+
...dynamicJsOrder.map(js => manifest[js]).filter(Boolean).map(item => React.createElement("script", { key: item, src: item, type: isVite ? 'module' : 'text/javascript' }))
|
|
42
|
+
];
|
|
43
|
+
const staticList = {
|
|
44
|
+
injectCss,
|
|
45
|
+
injectScript
|
|
46
|
+
};
|
|
47
|
+
const isCsr = !!(mode === 'csr' || ((_a = ctx.request.query) === null || _a === void 0 ? void 0 : _a.csr));
|
|
48
|
+
const Component = isCsr ? React.Fragment : (component.name === 'dynamicComponent' ? (await component()).default : component);
|
|
49
|
+
if (isCsr) {
|
|
50
|
+
(0, ssr_common_utils_1.logGreen)(`Current path ${path} use csr render mode`);
|
|
51
|
+
}
|
|
52
|
+
let [layoutFetchData, fetchData] = [{}, {}];
|
|
53
|
+
if (!isCsr) {
|
|
54
|
+
const currentFetch = fetch ? (await fetch()).default : null;
|
|
55
|
+
const lF = layoutFetch ? layoutFetch({ ctx }) : Promise.resolve({});
|
|
56
|
+
const CF = currentFetch ? currentFetch({ ctx }) : Promise.resolve({});
|
|
57
|
+
[layoutFetchData, fetchData] = parallelFetch ? await Promise.all([lF, CF]) : [await lF, await CF];
|
|
72
58
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
59
|
+
const combineData = isCsr ? null : Object.assign(state !== null && state !== void 0 ? state : {}, layoutFetchData !== null && layoutFetchData !== void 0 ? layoutFetchData : {}, fetchData !== null && fetchData !== void 0 ? fetchData : {});
|
|
60
|
+
const injectState = isCsr ? React.createElement("script", { dangerouslySetInnerHTML: { __html: `window.prefix="${prefix}";${clientPrefix ? `window.clientPrefix="${clientPrefix}";` : ''}` } }) : React.createElement("script", { dangerouslySetInnerHTML: {
|
|
61
|
+
__html: `window.__USE_SSR__=true; window.__INITIAL_DATA__ =${(0, ssr_serialize_javascript_1.serialize)(combineData)}; window.prefix="${prefix}";${clientPrefix ? `window.clientPrefix="${clientPrefix}";` : ''}`
|
|
62
|
+
} });
|
|
63
|
+
// with jsx type error, use createElement here
|
|
64
|
+
const ele = (0, react_1.createElement)(react_router_dom_1.StaticRouter, {
|
|
65
|
+
location: ctx.request.url,
|
|
66
|
+
basename: prefix === '/' ? undefined : prefix
|
|
67
|
+
}, (0, react_1.createElement)(create_context_1.STORE_CONTEXT.Provider, {
|
|
68
|
+
value: {
|
|
69
|
+
state: combineData
|
|
70
|
+
}
|
|
71
|
+
}, (0, react_1.createElement)(Layout, {
|
|
72
|
+
ctx: ctx,
|
|
73
|
+
config: config,
|
|
74
|
+
staticList: staticList,
|
|
75
|
+
injectState: injectState
|
|
76
|
+
}, (0, react_1.createElement)(Component, null))));
|
|
77
|
+
return stream ? server_2.renderToNodeStream(ele) : (0, server_1.renderToString)(ele);
|
|
78
|
+
};
|
|
79
|
+
return await ssr_common_utils_1.localStorageWrapper.run({
|
|
80
|
+
context: create_context_1.STORE_CONTEXT
|
|
81
|
+
}, fn);
|
|
80
82
|
};
|
|
81
83
|
exports.serverRender = serverRender;
|
|
82
84
|
//# sourceMappingURL=server-entry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-entry.js","sourceRoot":"","sources":["../../src/entry/server-entry.tsx"],"names":[],"mappings":";;;AAAA,+BAA8B;AAC9B,iCAAqC;AACrC,uDAA+C;AAC/C,
|
|
1
|
+
{"version":3,"file":"server-entry.js","sourceRoot":"","sources":["../../src/entry/server-entry.tsx"],"names":[],"mappings":";;;AAAA,+BAA8B;AAC9B,iCAAqC;AACrC,uDAA+C;AAC/C,6CAAiD;AAEjD,mBAAmB;AACnB,iDAAyD;AACzD,uDAA4K;AAE5K,uEAAoD;AACpD,0DAAgE;AAChE,mDAAwC;AAmFtC,uFAnFO,sBAAM,OAmFP;AAjFR,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,sBAAM,CAAA;AAEvD,MAAM,YAAY,GAAG,KAAK,EAAE,GAAgB,EAAE,MAAe,EAAE,EAAE;;IAC/D,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE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C,CAAC,IAAA,uBAAc,EAAC,GAAG,CAAC,CAAA;IAC3F,CAAC,CAAA;IAED,OAAO,MAAM,sCAAmB,CAAC,GAAG,CAAC;QACnC,OAAO,EAAE,8BAAO;KACjB,EAAE,EAAE,CAAC,CAAA;AACR,CAAC,CAAA;AAGC,oCAAY"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { ISSRContext, IConfig } from 'ssr-types';
|
|
2
3
|
import { Routes } from './create-router';
|
|
3
|
-
declare const serverRender: (ctx: ISSRContext, config: IConfig) => Promise<string | NodeJS.ReadableStream
|
|
4
|
+
declare const serverRender: (ctx: ISSRContext, config: IConfig) => Promise<string | import("stream").Readable | NodeJS.ReadableStream | {
|
|
5
|
+
html: string;
|
|
6
|
+
teleportsContext: any;
|
|
7
|
+
}>;
|
|
4
8
|
export { serverRender, Routes };
|
|
5
9
|
//# sourceMappingURL=server-entry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-entry.d.ts","sourceRoot":"","sources":["../../src/entry/server-entry.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server-entry.d.ts","sourceRoot":"","sources":["../../src/entry/server-entry.tsx"],"names":[],"mappings":";AAQA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAmD,MAAM,WAAW,CAAA;AAGjG,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAIxC,QAAA,MAAM,YAAY,QAAe,WAAW,UAAU,OAAO;;;EA2E5D,CAAA;AAED,OAAO,EACL,YAAY,EACZ,MAAM,EACP,CAAA"}
|
|
@@ -1,78 +1,80 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { createElement } from 'react';
|
|
3
3
|
import { StaticRouter } from 'react-router-dom';
|
|
4
|
-
import { renderToString
|
|
5
|
-
|
|
4
|
+
import { renderToString } from 'react-dom/server';
|
|
5
|
+
// @ts-expect-error
|
|
6
|
+
import { renderToNodeStream } from 'ssr-react-dom/server';
|
|
7
|
+
import { findRoute, getManifest, logGreen, normalizePath, getAsyncCssChunk, getAsyncJsChunk, reactRefreshFragment, localStorageWrapper, checkRoute } from 'ssr-common-utils';
|
|
6
8
|
import { serialize } from 'ssr-serialize-javascript';
|
|
7
9
|
import { STORE_CONTEXT as Context } from '_build/create-context';
|
|
8
10
|
import { Routes } from './create-router';
|
|
9
11
|
const { FeRoutes, layoutFetch, state, Layout } = Routes;
|
|
10
12
|
const serverRender = async (ctx, config) => {
|
|
11
|
-
var _a
|
|
13
|
+
var _a;
|
|
12
14
|
const { mode, parallelFetch, prefix, isVite, isDev, clientPrefix, stream } = config;
|
|
13
15
|
const rawPath = (_a = ctx.request.path) !== null && _a !== void 0 ? _a : ctx.request.routerPath;
|
|
14
16
|
const path = normalizePath(rawPath, prefix);
|
|
15
17
|
const routeItem = findRoute(FeRoutes, path);
|
|
16
|
-
|
|
17
|
-
if (!routeItem) {
|
|
18
|
-
throw new Error(`
|
|
19
|
-
With Path: ${path} search component failed
|
|
20
|
-
If you create new folder or component file, please restart server by npm start
|
|
21
|
-
`);
|
|
22
|
-
}
|
|
18
|
+
checkRoute({ routeItem, path });
|
|
23
19
|
const { fetch, webpackChunkName, component } = routeItem;
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const injectState = isCsr ? React.createElement("script", { dangerouslySetInnerHTML: { __html: `window.prefix="${prefix}";${clientPrefix ? `window.clientPrefix="${clientPrefix}";` : ''}` } }) : React.createElement("script", { dangerouslySetInnerHTML: {
|
|
59
|
-
__html: `window.__USE_SSR__=true; window.__INITIAL_DATA__ =${serialize(combineData)}; window.prefix="${prefix}";${clientPrefix ? `window.clientPrefix="${clientPrefix}";` : ''}`
|
|
60
|
-
} });
|
|
61
|
-
// with jsx type error, use createElement here
|
|
62
|
-
const ele = createElement(StaticRouter, {
|
|
63
|
-
location: ctx.request.url,
|
|
64
|
-
basename: prefix === '/' ? undefined : prefix
|
|
65
|
-
}, createElement(Context.Provider, {
|
|
66
|
-
value: {
|
|
67
|
-
state: combineData
|
|
20
|
+
const fn = async () => {
|
|
21
|
+
var _a;
|
|
22
|
+
const dynamicCssOrder = await getAsyncCssChunk(ctx, webpackChunkName, config);
|
|
23
|
+
const dynamicJsOrder = await getAsyncJsChunk(ctx, webpackChunkName, config);
|
|
24
|
+
const manifest = await getManifest(config);
|
|
25
|
+
const injectCss = ((isVite && isDev) ? [
|
|
26
|
+
React.createElement("script", { src: "/@vite/client", type: "module", key: "vite-client" }),
|
|
27
|
+
React.createElement("script", { key: "vite-react-refresh", type: "module", dangerouslySetInnerHTML: {
|
|
28
|
+
__html: reactRefreshFragment
|
|
29
|
+
} })
|
|
30
|
+
] : dynamicCssOrder.map(css => manifest[css]).filter(Boolean).map(css => React.createElement("link", { rel: 'stylesheet', key: css, href: css })))
|
|
31
|
+
.concat((isVite && isDev) ? [] : dynamicJsOrder.map(js => manifest[js]).filter(Boolean).map(js => React.createElement("link", { href: js, as: "script", rel: isVite ? 'modulepreload' : 'preload', key: js })));
|
|
32
|
+
const injectScript = [
|
|
33
|
+
...(isVite ? [React.createElement("script", { key: "viteWindowInit", dangerouslySetInnerHTML: {
|
|
34
|
+
__html: 'window.__USE_VITE__=true'
|
|
35
|
+
} })] : []),
|
|
36
|
+
...((isVite && isDev) ? [React.createElement("script", { type: "module", src: '/node_modules/ssr-plugin-react/esm/entry/client-entry.js', key: "vite-react-entry" })] : []),
|
|
37
|
+
...dynamicJsOrder.map(js => manifest[js]).filter(Boolean).map(item => React.createElement("script", { key: item, src: item, type: isVite ? 'module' : 'text/javascript' }))
|
|
38
|
+
];
|
|
39
|
+
const staticList = {
|
|
40
|
+
injectCss,
|
|
41
|
+
injectScript
|
|
42
|
+
};
|
|
43
|
+
const isCsr = !!(mode === 'csr' || ((_a = ctx.request.query) === null || _a === void 0 ? void 0 : _a.csr));
|
|
44
|
+
const Component = isCsr ? React.Fragment : (component.name === 'dynamicComponent' ? (await component()).default : component);
|
|
45
|
+
if (isCsr) {
|
|
46
|
+
logGreen(`Current path ${path} use csr render mode`);
|
|
47
|
+
}
|
|
48
|
+
let [layoutFetchData, fetchData] = [{}, {}];
|
|
49
|
+
if (!isCsr) {
|
|
50
|
+
const currentFetch = fetch ? (await fetch()).default : null;
|
|
51
|
+
const lF = layoutFetch ? layoutFetch({ ctx }) : Promise.resolve({});
|
|
52
|
+
const CF = currentFetch ? currentFetch({ ctx }) : Promise.resolve({});
|
|
53
|
+
[layoutFetchData, fetchData] = parallelFetch ? await Promise.all([lF, CF]) : [await lF, await CF];
|
|
68
54
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
55
|
+
const combineData = isCsr ? null : Object.assign(state !== null && state !== void 0 ? state : {}, layoutFetchData !== null && layoutFetchData !== void 0 ? layoutFetchData : {}, fetchData !== null && fetchData !== void 0 ? fetchData : {});
|
|
56
|
+
const injectState = isCsr ? React.createElement("script", { dangerouslySetInnerHTML: { __html: `window.prefix="${prefix}";${clientPrefix ? `window.clientPrefix="${clientPrefix}";` : ''}` } }) : React.createElement("script", { dangerouslySetInnerHTML: {
|
|
57
|
+
__html: `window.__USE_SSR__=true; window.__INITIAL_DATA__ =${serialize(combineData)}; window.prefix="${prefix}";${clientPrefix ? `window.clientPrefix="${clientPrefix}";` : ''}`
|
|
58
|
+
} });
|
|
59
|
+
// with jsx type error, use createElement here
|
|
60
|
+
const ele = createElement(StaticRouter, {
|
|
61
|
+
location: ctx.request.url,
|
|
62
|
+
basename: prefix === '/' ? undefined : prefix
|
|
63
|
+
}, createElement(Context.Provider, {
|
|
64
|
+
value: {
|
|
65
|
+
state: combineData
|
|
66
|
+
}
|
|
67
|
+
}, createElement(Layout, {
|
|
68
|
+
ctx: ctx,
|
|
69
|
+
config: config,
|
|
70
|
+
staticList: staticList,
|
|
71
|
+
injectState: injectState
|
|
72
|
+
}, createElement(Component, null))));
|
|
73
|
+
return stream ? renderToNodeStream(ele) : renderToString(ele);
|
|
74
|
+
};
|
|
75
|
+
return await localStorageWrapper.run({
|
|
76
|
+
context: Context
|
|
77
|
+
}, fn);
|
|
76
78
|
};
|
|
77
79
|
export { serverRender, Routes };
|
|
78
80
|
//# sourceMappingURL=server-entry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-entry.js","sourceRoot":"","sources":["../../src/entry/server-entry.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"server-entry.js","sourceRoot":"","sources":["../../src/entry/server-entry.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,mBAAmB;AACnB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,SA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,KAAK,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM;SAC9C,EAAE,aAAa,CAAC,OAAO,CAAC,QAAQ,EAAE;YACjC,KAAK,EAAE;gBACL,KAAK,EAAE,WAAW;aACnB;SACF,EAAE,aAAa,CAAC,MAAM,EAAE;YACvB,GAAG,EAAE,GAAG;YACR,MAAM,EAAE,MAAM;YACd,UAAU,EAAE,UAAU;YACtB,WAAW,EAAE,WAAW;SACzB,EAAE,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;QACpC,OAAO,MAAM,CAAC,CAAC,CAAE,kBAA6C,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;IAC3F,CAAC,CAAA;IAED,OAAO,MAAM,mBAAmB,CAAC,GAAG,CAAC;QACnC,OAAO,EAAE,OAAO;KACjB,EAAE,EAAE,CAAC,CAAA;AACR,CAAC,CAAA;AAED,OAAO,EACL,YAAY,EACZ,MAAM,EACP,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssr-plugin-react",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.57",
|
|
4
4
|
"description": "plugin-react for ssr",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"ssr-common-utils": "^6.0.0",
|
|
67
67
|
"ssr-hoc-react": "^6.2.7",
|
|
68
68
|
"ssr-mini-css-extract-plugin": "^1.0.0",
|
|
69
|
+
"ssr-react-dom": "^17.0.9",
|
|
69
70
|
"ssr-serialize-javascript": "^6.0.0",
|
|
70
71
|
"ssr-vite-plugin-style-import": "^2.0.1",
|
|
71
72
|
"ssr-webpack": "^6.2.10",
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { createElement } from 'react'
|
|
3
3
|
import { StaticRouter } from 'react-router-dom'
|
|
4
|
-
import { renderToString
|
|
5
|
-
import {
|
|
4
|
+
import { renderToString } from 'react-dom/server'
|
|
5
|
+
import type { renderToNodeStream as ReactStreamType } from 'react-dom/server'
|
|
6
|
+
// @ts-expect-error
|
|
7
|
+
import { renderToNodeStream } from 'ssr-react-dom/server'
|
|
8
|
+
import { findRoute, getManifest, logGreen, normalizePath, getAsyncCssChunk, getAsyncJsChunk, reactRefreshFragment, localStorageWrapper, checkRoute } from 'ssr-common-utils'
|
|
6
9
|
import { ISSRContext, IConfig, ReactESMPreloadFeRouteItem, DynamicFC, StaticFC } from 'ssr-types'
|
|
7
10
|
import { serialize } from 'ssr-serialize-javascript'
|
|
8
11
|
import { STORE_CONTEXT as Context } from '_build/create-context'
|
|
@@ -15,77 +18,76 @@ const serverRender = async (ctx: ISSRContext, config: IConfig) => {
|
|
|
15
18
|
const rawPath = ctx.request.path ?? ctx.request.routerPath
|
|
16
19
|
const path = normalizePath(rawPath, prefix)
|
|
17
20
|
const routeItem = findRoute<ReactESMPreloadFeRouteItem>(FeRoutes, path)
|
|
18
|
-
|
|
21
|
+
checkRoute({ routeItem, path })
|
|
22
|
+
const { fetch, webpackChunkName, component } = routeItem
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
`)
|
|
25
|
-
}
|
|
24
|
+
const fn = async () => {
|
|
25
|
+
const dynamicCssOrder = await getAsyncCssChunk(ctx, webpackChunkName, config)
|
|
26
|
+
const dynamicJsOrder = await getAsyncJsChunk(ctx, webpackChunkName, config)
|
|
27
|
+
const manifest = await getManifest(config)
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const injectCss = ((isVite && isDev) ? [
|
|
30
|
+
<script src="/@vite/client" type="module" key="vite-client" />,
|
|
31
|
+
<script key="vite-react-refresh" type="module" dangerouslySetInnerHTML={{
|
|
32
|
+
__html: reactRefreshFragment
|
|
33
|
+
}} />
|
|
34
|
+
] : dynamicCssOrder.map(css => manifest[css]).filter(Boolean).map(css => <link rel='stylesheet' key={css} href={css} />))
|
|
35
|
+
.concat((isVite && isDev) ? [] : dynamicJsOrder.map(js => manifest[js]).filter(Boolean).map(js =>
|
|
36
|
+
<link href={js} as="script" rel={isVite ? 'modulepreload' : 'preload'} key={js} />
|
|
37
|
+
))
|
|
31
38
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
const injectScript = [
|
|
40
|
+
...(isVite ? [<script key="viteWindowInit" dangerouslySetInnerHTML={{
|
|
41
|
+
__html: 'window.__USE_VITE__=true'
|
|
42
|
+
}} />] : []),
|
|
43
|
+
...((isVite && isDev) ? [<script type="module" src='/node_modules/ssr-plugin-react/esm/entry/client-entry.js' key="vite-react-entry" />] : []),
|
|
44
|
+
...dynamicJsOrder.map(js => manifest[js]).filter(Boolean).map(item => <script key={item} src={item} type={isVite ? 'module' : 'text/javascript'} />)
|
|
45
|
+
]
|
|
46
|
+
const staticList = {
|
|
47
|
+
injectCss,
|
|
48
|
+
injectScript
|
|
49
|
+
}
|
|
41
50
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
__html: 'window.__USE_VITE__=true'
|
|
45
|
-
}} />] : []),
|
|
46
|
-
...((isVite && isDev) ? [<script type="module" src='/node_modules/ssr-plugin-react/esm/entry/client-entry.js' key="vite-react-entry" />] : []),
|
|
47
|
-
...dynamicJsOrder.map(js => manifest[js]).filter(Boolean).map(item => <script key={item} src={item} type={isVite ? 'module' : 'text/javascript'}/>)
|
|
48
|
-
]
|
|
49
|
-
const staticList = {
|
|
50
|
-
injectCss,
|
|
51
|
-
injectScript
|
|
52
|
-
}
|
|
51
|
+
const isCsr = !!(mode === 'csr' || ctx.request.query?.csr)
|
|
52
|
+
const Component = isCsr ? React.Fragment : (component.name === 'dynamicComponent' ? (await (component as DynamicFC)()).default : component as StaticFC)
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
if (isCsr) {
|
|
55
|
+
logGreen(`Current path ${path} use csr render mode`)
|
|
56
|
+
}
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
logGreen(`Current path ${path} use csr render mode`)
|
|
59
|
-
}
|
|
58
|
+
let [layoutFetchData, fetchData] = [{}, {}]
|
|
60
59
|
|
|
61
|
-
|
|
60
|
+
if (!isCsr) {
|
|
61
|
+
const currentFetch = fetch ? (await fetch()).default : null
|
|
62
|
+
const lF = layoutFetch ? layoutFetch({ ctx }) : Promise.resolve({})
|
|
63
|
+
const CF = currentFetch ? currentFetch({ ctx }) : Promise.resolve({});
|
|
64
|
+
[layoutFetchData, fetchData] = parallelFetch ? await Promise.all([lF, CF]) : [await lF, await CF]
|
|
65
|
+
}
|
|
62
66
|
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
const combineData = isCsr ? null : Object.assign(state ?? {}, layoutFetchData ?? {}, fetchData ?? {})
|
|
68
|
+
const injectState = isCsr ? <script dangerouslySetInnerHTML={{ __html: `window.prefix="${prefix}";${clientPrefix ? `window.clientPrefix="${clientPrefix}";` : ''}` }} /> : <script dangerouslySetInnerHTML={{
|
|
69
|
+
__html: `window.__USE_SSR__=true; window.__INITIAL_DATA__ =${serialize(combineData)}; window.prefix="${prefix}";${clientPrefix ? `window.clientPrefix="${clientPrefix}";` : ''}`
|
|
70
|
+
}} />
|
|
71
|
+
// with jsx type error, use createElement here
|
|
72
|
+
const ele = createElement(StaticRouter, {
|
|
73
|
+
location: ctx.request.url,
|
|
74
|
+
basename: prefix === '/' ? undefined : prefix
|
|
75
|
+
}, createElement(Context.Provider, {
|
|
76
|
+
value: {
|
|
77
|
+
state: combineData
|
|
78
|
+
}
|
|
79
|
+
}, createElement(Layout, {
|
|
80
|
+
ctx: ctx,
|
|
81
|
+
config: config,
|
|
82
|
+
staticList: staticList,
|
|
83
|
+
injectState: injectState
|
|
84
|
+
}, createElement(Component, null))))
|
|
85
|
+
return stream ? (renderToNodeStream as typeof ReactStreamType)(ele) : renderToString(ele)
|
|
68
86
|
}
|
|
69
87
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}} />
|
|
74
|
-
// with jsx type error, use createElement here
|
|
75
|
-
const ele = createElement(StaticRouter, {
|
|
76
|
-
location: ctx.request.url,
|
|
77
|
-
basename: prefix === '/' ? undefined : prefix
|
|
78
|
-
}, createElement(Context.Provider, {
|
|
79
|
-
value: {
|
|
80
|
-
state: combineData
|
|
81
|
-
}
|
|
82
|
-
}, createElement(Layout, {
|
|
83
|
-
ctx: ctx,
|
|
84
|
-
config: config,
|
|
85
|
-
staticList: staticList,
|
|
86
|
-
injectState: injectState
|
|
87
|
-
}, createElement(Component, null))))
|
|
88
|
-
return stream ? renderToNodeStream(ele) : renderToString(ele)
|
|
88
|
+
return await localStorageWrapper.run({
|
|
89
|
+
context: Context
|
|
90
|
+
}, fn)
|
|
89
91
|
}
|
|
90
92
|
|
|
91
93
|
export {
|