ssr-plugin-react 6.2.0 → 6.2.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 CHANGED
@@ -3,6 +3,39 @@
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
+ ## [6.2.3](https://github.com/zhangyuang/ssr/compare/v6.2.1...v6.2.3) (2022-04-01)
7
+
8
+
9
+ ### Features
10
+
11
+ * judge microapp environment automaticlly ([85395dc](https://github.com/zhangyuang/ssr/commit/85395dcd3755ec2d2fdbeb22b2aa7097035e07d2))
12
+
13
+
14
+
15
+
16
+
17
+ ## [6.2.2](https://github.com/zhangyuang/ssr/compare/v6.2.1...v6.2.2) (2022-04-01)
18
+
19
+
20
+ ### Features
21
+
22
+ * judge microapp environment automaticlly ([85395dc](https://github.com/zhangyuang/ssr/commit/85395dcd3755ec2d2fdbeb22b2aa7097035e07d2))
23
+
24
+
25
+
26
+
27
+
28
+ ## [6.2.1](https://github.com/zhangyuang/ssr/compare/v6.2.0...v6.2.1) (2022-04-01)
29
+
30
+
31
+ ### Features
32
+
33
+ * support clientPrefix in vue2 react ([05dd609](https://github.com/zhangyuang/ssr/commit/05dd609e685d7b0855557733738f9ce74979c389))
34
+
35
+
36
+
37
+
38
+
6
39
  # [6.2.0](https://github.com/zhangyuang/ssr/compare/v6.2.0-alpha.0...v6.2.0) (2022-03-31)
7
40
 
8
41
  **Note:** Version bump only for package ssr-plugin-react
@@ -10,12 +10,12 @@ const create_router_1 = require("./create-router");
10
10
  const context_1 = require("./context");
11
11
  const { FeRoutes, layoutFetch, App, PrefixRouterBase } = create_router_1.Routes;
12
12
  const clientRender = async () => {
13
- var _a, _b, _c;
13
+ var _a, _b, _c, _d;
14
14
  const IApp = App !== null && App !== void 0 ? App : function (props) {
15
15
  return props.children;
16
16
  };
17
17
  // 客户端渲染||hydrate
18
- const baseName = (_a = window.prefix) !== null && _a !== void 0 ? _a : PrefixRouterBase;
18
+ const baseName = (_b = (_a = (window.microApp && window.clientPrefix)) !== null && _a !== void 0 ? _a : window.prefix) !== null && _b !== void 0 ? _b : PrefixRouterBase;
19
19
  const routes = await (0, ssr_client_utils_1.preloadComponent)(FeRoutes, baseName);
20
20
  ReactDOM[window.__USE_SSR__ ? 'hydrate' : 'render'](React.createElement(react_router_dom_1.BrowserRouter, { basename: baseName },
21
21
  React.createElement(context_1.AppContext, null,
@@ -31,7 +31,7 @@ const clientRender = async () => {
31
31
  return (React.createElement(react_router_dom_1.Route, { exact: true, key: path, path: path, render: () => React.createElement(WrappedComponent, { key: location.pathname }) }));
32
32
  })))))), document.getElementById('app'));
33
33
  if (!window.__USE_VITE__) {
34
- (_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
34
+ (_d = (_c = module === null || module === void 0 ? void 0 : module.hot) === null || _c === void 0 ? void 0 : _c.accept) === null || _d === void 0 ? void 0 : _d.call(_c); // webpack 场景下的 hmr
35
35
  }
36
36
  };
37
37
  exports.clientRender = clientRender;
@@ -15,7 +15,7 @@ const { FeRoutes, layoutFetch, PrefixRouterBase, state } = create_router_1.Route
15
15
  const serialize = serializeWrap.default || serializeWrap;
16
16
  const serverRender = async (ctx, config) => {
17
17
  var _a;
18
- const { cssOrder, jsOrder, dynamic, mode, parallelFetch, disableClientRender, prefix, isVite, isDev } = config;
18
+ const { cssOrder, jsOrder, dynamic, mode, parallelFetch, disableClientRender, prefix, isVite, isDev, clientPrefix } = config;
19
19
  let path = ctx.request.path; // 这里取 pathname 不能够包含 queryString
20
20
  const base = prefix !== null && prefix !== void 0 ? prefix : PrefixRouterBase; // 以开发者实际传入的为最高优先级
21
21
  if (base) {
@@ -96,7 +96,7 @@ const serverRender = async (ctx, config) => {
96
96
  }
97
97
  const combineData = isCsr ? null : Object.assign(state !== null && state !== void 0 ? state : {}, layoutFetchData !== null && layoutFetchData !== void 0 ? layoutFetchData : {}, fetchData !== null && fetchData !== void 0 ? fetchData : {});
98
98
  const injectState = isCsr ? null : React.createElement("script", { dangerouslySetInnerHTML: {
99
- __html: `window.__USE_SSR__=true; window.__INITIAL_DATA__ =${serialize(combineData)}; ${base && `window.prefix="${base}"`}`
99
+ __html: `window.__USE_SSR__=true; window.__INITIAL_DATA__ =${serialize(combineData)}; ${base && `window.prefix="${base}"`};${clientPrefix && `window.clientPrefix="${clientPrefix}"`}`
100
100
  } });
101
101
  return (React.createElement(react_router_dom_1.StaticRouter, { location: ctx.request.url },
102
102
  React.createElement(create_context_1.STORE_CONTEXT.Provider, { value: { state: combineData } },
@@ -7,12 +7,12 @@ import { Routes } from './create-router';
7
7
  import { AppContext } from './context';
8
8
  const { FeRoutes, layoutFetch, App, PrefixRouterBase } = Routes;
9
9
  const clientRender = async () => {
10
- var _a, _b, _c;
10
+ var _a, _b, _c, _d;
11
11
  const IApp = App !== null && App !== void 0 ? App : function (props) {
12
12
  return props.children;
13
13
  };
14
14
  // 客户端渲染||hydrate
15
- const baseName = (_a = window.prefix) !== null && _a !== void 0 ? _a : PrefixRouterBase;
15
+ const baseName = (_b = (_a = (window.microApp && window.clientPrefix)) !== null && _a !== void 0 ? _a : window.prefix) !== null && _b !== void 0 ? _b : PrefixRouterBase;
16
16
  const routes = await preloadComponent(FeRoutes, baseName);
17
17
  ReactDOM[window.__USE_SSR__ ? 'hydrate' : 'render'](React.createElement(BrowserRouter, { basename: baseName },
18
18
  React.createElement(AppContext, null,
@@ -28,7 +28,7 @@ const clientRender = async () => {
28
28
  return (React.createElement(Route, { exact: true, key: path, path: path, render: () => React.createElement(WrappedComponent, { key: location.pathname }) }));
29
29
  })))))), document.getElementById('app'));
30
30
  if (!window.__USE_VITE__) {
31
- (_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
31
+ (_d = (_c = module === null || module === void 0 ? void 0 : module.hot) === null || _c === void 0 ? void 0 : _c.accept) === null || _d === void 0 ? void 0 : _d.call(_c); // webpack 场景下的 hmr
32
32
  }
33
33
  };
34
34
  if (!window.__disableClientRender__) {
@@ -12,7 +12,7 @@ const { FeRoutes, layoutFetch, PrefixRouterBase, state } = Routes;
12
12
  const serialize = serializeWrap.default || serializeWrap;
13
13
  const serverRender = async (ctx, config) => {
14
14
  var _a;
15
- const { cssOrder, jsOrder, dynamic, mode, parallelFetch, disableClientRender, prefix, isVite, isDev } = config;
15
+ const { cssOrder, jsOrder, dynamic, mode, parallelFetch, disableClientRender, prefix, isVite, isDev, clientPrefix } = config;
16
16
  let path = ctx.request.path; // 这里取 pathname 不能够包含 queryString
17
17
  const base = prefix !== null && prefix !== void 0 ? prefix : PrefixRouterBase; // 以开发者实际传入的为最高优先级
18
18
  if (base) {
@@ -93,7 +93,7 @@ const serverRender = async (ctx, config) => {
93
93
  }
94
94
  const combineData = isCsr ? null : Object.assign(state !== null && state !== void 0 ? state : {}, layoutFetchData !== null && layoutFetchData !== void 0 ? layoutFetchData : {}, fetchData !== null && fetchData !== void 0 ? fetchData : {});
95
95
  const injectState = isCsr ? null : React.createElement("script", { dangerouslySetInnerHTML: {
96
- __html: `window.__USE_SSR__=true; window.__INITIAL_DATA__ =${serialize(combineData)}; ${base && `window.prefix="${base}"`}`
96
+ __html: `window.__USE_SSR__=true; window.__INITIAL_DATA__ =${serialize(combineData)}; ${base && `window.prefix="${base}"`};${clientPrefix && `window.clientPrefix="${clientPrefix}"`}`
97
97
  } });
98
98
  return (React.createElement(StaticRouter, { location: ctx.request.url },
99
99
  React.createElement(Context.Provider, { value: { state: combineData } },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssr-plugin-react",
3
- "version": "6.2.0",
3
+ "version": "6.2.3",
4
4
  "description": "plugin-react for ssr",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -55,10 +55,10 @@
55
55
  "postcss-safe-parser": "^6.0.0",
56
56
  "react-dev-utils": "^11.0.4",
57
57
  "serialize-javascript": "^6.0.0",
58
- "ssr-client-utils": "^6.2.0",
59
- "ssr-hoc-react": "^6.2.0",
60
- "ssr-server-utils": "^6.2.0",
61
- "ssr-webpack": "^6.2.0",
58
+ "ssr-client-utils": "^6.2.3",
59
+ "ssr-hoc-react": "^6.2.3",
60
+ "ssr-server-utils": "^6.2.3",
61
+ "ssr-webpack": "^6.2.3",
62
62
  "terser-webpack-plugin": "^2.3.5",
63
63
  "url-loader": "^4.1.1",
64
64
  "vite": "^2.7.0",
@@ -74,7 +74,7 @@
74
74
  "@types/react-router-dom": "^5.1.3",
75
75
  "@types/webpack": "^4.41.10",
76
76
  "concurrently": "^5.1.0",
77
- "ssr-types-react": "^6.2.0"
77
+ "ssr-types-react": "^6.2.3"
78
78
  },
79
- "gitHead": "d57f07b1a903c18e03807d2937aad4371cf31499"
79
+ "gitHead": "335e2e09d1843665ca9dda82df5f2566612a4e47"
80
80
  }
@@ -17,7 +17,7 @@ const clientRender = async (): Promise<void> => {
17
17
  return props.children!
18
18
  }
19
19
  // 客户端渲染||hydrate
20
- const baseName = window.prefix ?? PrefixRouterBase
20
+ const baseName = (window.microApp && window.clientPrefix) ?? window.prefix ?? PrefixRouterBase
21
21
  const routes = await preloadComponent(FeRoutes, baseName)
22
22
  ReactDOM[window.__USE_SSR__ ? 'hydrate' : 'render'](
23
23
  <BrowserRouter basename={baseName}>
@@ -14,7 +14,7 @@ const { FeRoutes, layoutFetch, PrefixRouterBase, state } = Routes as ReactRoutes
14
14
  const serialize = serializeWrap.default || serializeWrap
15
15
 
16
16
  const serverRender = async (ctx: ISSRContext, config: IConfig): Promise<React.ReactElement> => {
17
- const { cssOrder, jsOrder, dynamic, mode, parallelFetch, disableClientRender, prefix, isVite, isDev } = config
17
+ const { cssOrder, jsOrder, dynamic, mode, parallelFetch, disableClientRender, prefix, isVite, isDev, clientPrefix } = config
18
18
  let path = ctx.request.path // 这里取 pathname 不能够包含 queryString
19
19
  const base = prefix ?? PrefixRouterBase // 以开发者实际传入的为最高优先级
20
20
  if (base) {
@@ -103,7 +103,7 @@ const serverRender = async (ctx: ISSRContext, config: IConfig): Promise<React.Re
103
103
  }
104
104
  const combineData = isCsr ? null : Object.assign(state ?? {}, layoutFetchData ?? {}, fetchData ?? {})
105
105
  const injectState = isCsr ? null : <script dangerouslySetInnerHTML={{
106
- __html: `window.__USE_SSR__=true; window.__INITIAL_DATA__ =${serialize(combineData)}; ${base && `window.prefix="${base}"`}`
106
+ __html: `window.__USE_SSR__=true; window.__INITIAL_DATA__ =${serialize(combineData)}; ${base && `window.prefix="${base}"`};${clientPrefix && `window.clientPrefix="${clientPrefix}"`}`
107
107
  }} />
108
108
 
109
109
  return (