ssr-plugin-react 7.0.5 → 7.0.7

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +317 -432
  2. package/README.md +105 -105
  3. package/cjs/entry/context.d.ts +1 -1
  4. package/cjs/entry/context.d.ts.map +1 -1
  5. package/cjs/entry/context.js +5 -5
  6. package/cjs/entry/context.js.map +1 -1
  7. package/cjs/entry/create.d.ts +2 -3
  8. package/cjs/entry/create.d.ts.map +1 -1
  9. package/cjs/entry/create.js +10 -5
  10. package/cjs/entry/create.js.map +1 -1
  11. package/cjs/entry/react17-client-entry.d.ts.map +1 -1
  12. package/cjs/entry/react17-client-entry.js +7 -8
  13. package/cjs/entry/react17-client-entry.js.map +1 -1
  14. package/cjs/entry/react18-client-entry.d.ts.map +1 -1
  15. package/cjs/entry/react18-client-entry.js +6 -8
  16. package/cjs/entry/react18-client-entry.js.map +1 -1
  17. package/cjs/entry/server-entry.d.ts +2 -2
  18. package/cjs/entry/server-entry.d.ts.map +1 -1
  19. package/cjs/entry/server-entry.js +42 -28
  20. package/cjs/entry/server-entry.js.map +1 -1
  21. package/cjs/index.js +9 -9
  22. package/cjs/index.js.map +1 -1
  23. package/esm/entry/context.d.ts +1 -1
  24. package/esm/entry/context.d.ts.map +1 -1
  25. package/esm/entry/context.js +7 -7
  26. package/esm/entry/context.js.map +1 -1
  27. package/esm/entry/create.d.ts +2 -3
  28. package/esm/entry/create.d.ts.map +1 -1
  29. package/esm/entry/create.js +16 -11
  30. package/esm/entry/create.js.map +1 -1
  31. package/esm/entry/react17-client-entry.d.ts.map +1 -1
  32. package/esm/entry/react17-client-entry.js +14 -15
  33. package/esm/entry/react17-client-entry.js.map +1 -1
  34. package/esm/entry/react18-client-entry.d.ts.map +1 -1
  35. package/esm/entry/react18-client-entry.js +13 -15
  36. package/esm/entry/react18-client-entry.js.map +1 -1
  37. package/esm/entry/server-entry.d.ts +2 -2
  38. package/esm/entry/server-entry.d.ts.map +1 -1
  39. package/esm/entry/server-entry.js +51 -37
  40. package/esm/entry/server-entry.js.map +1 -1
  41. package/esm/index.js +11 -11
  42. package/esm/index.js.map +1 -1
  43. package/package.json +31 -32
  44. package/src/entry/context.tsx +33 -29
  45. package/src/entry/create.ts +27 -24
  46. package/src/entry/react17-client-entry.tsx +66 -66
  47. package/src/entry/react18-client-entry.tsx +72 -72
  48. package/src/entry/server-entry.tsx +192 -141
  49. package/src/index.ts +38 -38
  50. package/tsconfig.cjs.json +2 -4
  51. package/tsconfig.esm.json +2 -4
@@ -1,17 +1,17 @@
1
- import { PassThrough } from 'stream';
2
- import * as React from 'react';
3
- import { createElement } from 'react';
4
- import * as ReactDOMServer from 'react-dom/server';
5
- import { StaticRouter } from 'react-router-dom';
6
- import { findRoute, getManifest, logGreen, normalizePath, getAsyncCssChunk, getAsyncJsChunk, splitPageInfo, reactRefreshFragment, localStorageWrapper, checkRoute, useStore, isReact18, getClientEntry } from 'ssr-common-utils';
7
- import { serialize } from 'ssr-serialize-javascript';
8
- import { AppContext } from './context';
9
- import { Routes, ssrCreateContext, createStore } from './create';
1
+ import { PassThrough } from "stream";
2
+ import * as React from "react";
3
+ import { createElement } from "react";
4
+ import * as ReactDOMServer from "react-dom/server";
5
+ import { StaticRouter } from "react-router-dom";
6
+ import { findRoute, getManifest, logGreen, normalizePath, getAsyncCssChunk, getAsyncJsChunk, splitPageInfo, reactRefreshFragment, localStorageWrapper, checkRoute, useStore, isReact18, getClientEntry, } from "ssr-common-utils";
7
+ import { serialize } from "ssr-serialize-javascript";
8
+ import { AppContext } from "./context";
9
+ import { Routes, ssrCreateContext, createStore } from "./create";
10
10
  const { FeRoutes, layoutFetch, state, Layout } = Routes;
11
11
  const serverRender = async (ctx, config) => {
12
12
  var _a;
13
13
  const context = ssrCreateContext();
14
- const { mode, parallelFetch, prefix, isVite, isDev, clientPrefix, onReady, onError, stream, rootId, hashRouter, streamHighWaterMark } = config;
14
+ const { mode, parallelFetch, prefix, isVite, isDev, clientPrefix, onReady, onError, stream, rootId, hashRouter, streamHighWaterMark, } = config;
15
15
  const rawPath = (_a = ctx.request.path) !== null && _a !== void 0 ? _a : ctx.request.url;
16
16
  const path = normalizePath(rawPath, prefix);
17
17
  const routeItem = findRoute(FeRoutes, path);
@@ -26,8 +26,8 @@ const serverRender = async (ctx, config) => {
26
26
  ? [
27
27
  React.createElement("script", { src: "/@vite/client", type: "module", key: "vite-client" }),
28
28
  React.createElement("script", { key: "vite-react-refresh", type: "module", dangerouslySetInnerHTML: {
29
- __html: reactRefreshFragment
30
- } })
29
+ __html: reactRefreshFragment,
30
+ } }),
31
31
  ]
32
32
  : dynamicCssOrder
33
33
  .map((css) => manifest[css])
@@ -37,27 +37,35 @@ const serverRender = async (ctx, config) => {
37
37
  : dynamicJsOrder
38
38
  .map((js) => manifest[js])
39
39
  .filter(Boolean)
40
- .map((js) => React.createElement("link", { href: js, as: "script", rel: isVite ? 'modulepreload' : 'preload', key: js })));
40
+ .map((js) => (React.createElement("link", { href: js, as: "script", rel: isVite ? "modulepreload" : "preload", key: js }))));
41
41
  const injectScript = [
42
42
  ...(isVite
43
43
  ? [
44
44
  React.createElement("script", { key: "viteWindowInit", dangerouslySetInnerHTML: {
45
- __html: 'window.__USE_VITE__=true'
46
- } })
45
+ __html: "window.__USE_VITE__=true",
46
+ } }),
47
+ ]
48
+ : []),
49
+ ...(isVite && isDev
50
+ ? [
51
+ React.createElement("script", { type: "module", src: `/node_modules/ssr-plugin-react/esm/entry/${getClientEntry()}.js`, key: "vite-react-entry" }),
47
52
  ]
48
53
  : []),
49
- ...(isVite && isDev ? [React.createElement("script", { type: "module", src: `/node_modules/ssr-plugin-react/esm/entry/${getClientEntry()}.js`, key: "vite-react-entry" })] : []),
50
54
  ...dynamicJsOrder
51
55
  .map((js) => manifest[js])
52
56
  .filter(Boolean)
53
- .map((item) => React.createElement("script", { key: item, src: item, type: isVite ? 'module' : 'text/javascript' }))
57
+ .map((item) => (React.createElement("script", { key: item, src: item, type: isVite ? "module" : "text/javascript" }))),
54
58
  ];
55
59
  const staticList = {
56
60
  injectCss,
57
- injectScript
61
+ injectScript,
58
62
  };
59
- const isCsr = !!(mode === 'csr' || ((_a = ctx.request.query) === null || _a === void 0 ? void 0 : _a.csr));
60
- const Component = isCsr ? React.Fragment : component.name === 'dynamicComponent' ? (await component()).default : component;
63
+ const isCsr = !!(mode === "csr" || ((_a = ctx.request.query) === null || _a === void 0 ? void 0 : _a.csr));
64
+ const Component = isCsr
65
+ ? React.Fragment
66
+ : component.name === "dynamicComponent"
67
+ ? (await component()).default
68
+ : component;
61
69
  if (isCsr) {
62
70
  logGreen(`Current path ${path} use csr render mode`);
63
71
  }
@@ -66,25 +74,29 @@ const serverRender = async (ctx, config) => {
66
74
  const currentFetch = fetch ? (await fetch()).default : null;
67
75
  const lF = layoutFetch ? layoutFetch({ ctx }) : Promise.resolve({});
68
76
  const CF = currentFetch ? currentFetch({ ctx }) : Promise.resolve({});
69
- [layoutFetchData, fetchData] = parallelFetch ? await Promise.all([lF, CF]) : [await lF, await CF];
77
+ [layoutFetchData, fetchData] = parallelFetch
78
+ ? await Promise.all([lF, CF])
79
+ : [await lF, await CF];
70
80
  }
71
- const combineData = isCsr ? null : Object.assign({}, state !== null && state !== void 0 ? state : {}, layoutFetchData !== null && layoutFetchData !== void 0 ? layoutFetchData : {}, fetchData !== null && fetchData !== void 0 ? fetchData : {});
72
- const ssrDevInfo = { manifest: isDev ? manifest : '', rootId };
81
+ const combineData = isCsr
82
+ ? null
83
+ : Object.assign({}, state !== null && state !== void 0 ? state : {}, layoutFetchData !== null && layoutFetchData !== void 0 ? layoutFetchData : {}, fetchData !== null && fetchData !== void 0 ? fetchData : {});
84
+ const ssrDevInfo = { manifest: isDev ? manifest : "", rootId };
73
85
  const innerHTML = splitPageInfo({
74
- 'window.__USE_SSR__': !isCsr,
75
- 'window.__INITIAL_DATA__': isCsr ? {} : serialize(combineData),
76
- 'window.__USE_VITE__': isVite,
77
- 'window.prefix': `"${prefix}"`,
78
- 'window.clientPrefix': `"${clientPrefix !== null && clientPrefix !== void 0 ? clientPrefix : ''}"`,
79
- 'window.ssrDevInfo': JSON.stringify(ssrDevInfo),
80
- 'window.hashRouter': Boolean(hashRouter),
81
- 'window.__VALTIO_DATA__': isCsr ? {} : serialize(useStore())
86
+ "window.__USE_SSR__": !isCsr,
87
+ "window.__INITIAL_DATA__": isCsr ? {} : serialize(combineData),
88
+ "window.__USE_VITE__": isVite,
89
+ "window.prefix": `"${prefix}"`,
90
+ "window.clientPrefix": `"${clientPrefix !== null && clientPrefix !== void 0 ? clientPrefix : ""}"`,
91
+ "window.ssrDevInfo": JSON.stringify(ssrDevInfo),
92
+ "window.hashRouter": Boolean(hashRouter),
93
+ "window.__VALTIO_DATA__": isCsr ? {} : serialize(useStore()),
82
94
  });
83
95
  const injectState = React.createElement("script", { dangerouslySetInnerHTML: { __html: innerHTML } });
84
96
  // with jsx type error, use createElement here
85
97
  const ele = createElement(StaticRouter, {
86
98
  location: ctx.request.url,
87
- basename: prefix === '/' ? undefined : prefix
99
+ basename: prefix === "/" ? undefined : prefix,
88
100
  }, createElement(AppContext, {
89
101
  context: context,
90
102
  initialState: combineData,
@@ -92,8 +104,8 @@ const serverRender = async (ctx, config) => {
92
104
  ctx: ctx,
93
105
  config: config,
94
106
  staticList: staticList,
95
- injectState: injectState
96
- }, createElement(Component, null))
107
+ injectState: injectState,
108
+ }, createElement(Component, null)),
97
109
  }));
98
110
  // for ctx.body will loose asynclocalstorage context, consume stream in advance like vue2/3
99
111
  if (isReact18()) {
@@ -101,19 +113,21 @@ const serverRender = async (ctx, config) => {
101
113
  ? ReactDOMServer
102
114
  .renderToPipeableStream(ele, {
103
115
  onAllReady: onReady,
104
- onError: onError
116
+ onError: onError,
105
117
  })
106
118
  .pipe(new PassThrough({ highWaterMark: streamHighWaterMark }))
107
119
  : ReactDOMServer.renderToString(ele);
108
120
  }
109
121
  else {
110
- return stream ? ReactDOMServer.renderToNodeStream(ele).pipe(new PassThrough({ highWaterMark: streamHighWaterMark })) : ReactDOMServer.renderToString(ele);
122
+ return stream
123
+ ? ReactDOMServer.renderToNodeStream(ele).pipe(new PassThrough({ highWaterMark: streamHighWaterMark }))
124
+ : ReactDOMServer.renderToString(ele);
111
125
  }
112
126
  };
113
127
  return await localStorageWrapper.run({
114
128
  context: context,
115
129
  ctx,
116
- store: createStore()
130
+ store: createStore(),
117
131
  }, fn);
118
132
  };
119
133
  export { serverRender, Routes };
@@ -1 +1 @@
1
- {"version":3,"file":"server-entry.js","sourceRoot":"","sources":["../../src/entry/server-entry.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,gBAAgB,EAAE,eAAe,EAAE,aAAa,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEhO,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEhE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;AAKvD,MAAM,YAAY,GAAG,KAAK,EAAE,GAAgB,EAAE,MAAe,EAAE,EAAE;;IAChE,MAAM,OAAO,GAAG,gBAAgB,EAAE,CAAA;IAClC,M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BAAsB,CAAC,GAAG,EAAE;oBAC3B,UAAU,EAAE,OAAO;oBACnB,OAAO,EAAE,OAAc;iBACxB,CAAC;qBACD,IAAI,CAAC,IAAI,WAAW,CAAC,EAAE,aAAa,EAAE,mBAAmB,EAAE,CAAC,CAAC;gBAClE,CAAC,CAAC,cAAc,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QACzC,CAAC;aAAM,CAAC;YACN,OAAO,MAAM;gBACX,CAAC,CAAC,cAAc,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,IAAI,CACzC,IAAI,WAAW,CAAC,EAAE,aAAa,EAAE,mBAAmB,EAAE,CAAC,CACxD;gBACH,CAAC,CAAC,cAAc,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QACzC,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,MAAM,mBAAmB,CAAC,GAAG,CAClC;QACE,OAAO,EAAE,OAAc;QACvB,GAAG;QACH,KAAK,EAAE,WAAW,EAAE;KACrB,EACD,EAAE,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC"}
package/esm/index.js CHANGED
@@ -1,20 +1,20 @@
1
- import { resolve } from 'path';
2
- import { loadConfig, getCwd } from 'ssr-common-utils';
1
+ import { resolve } from "path";
2
+ import { loadConfig, getCwd } from "ssr-common-utils";
3
3
  const { tool } = loadConfig();
4
4
  export function clientPlugin() {
5
5
  const cwd = getCwd();
6
- const webpackPath = resolve(cwd, './node_modules/ssr-webpack');
7
- const vitePath = resolve(cwd, './node_modules/ssr-vite');
8
- const rspackPath = resolve(cwd, './node_modules/ssr-rspack');
6
+ const webpackPath = resolve(cwd, "./node_modules/ssr-webpack");
7
+ const vitePath = resolve(cwd, "./node_modules/ssr-vite");
8
+ const rspackPath = resolve(cwd, "./node_modules/ssr-rspack");
9
9
  return {
10
- name: 'plugin-react',
10
+ name: "plugin-react",
11
11
  start: async () => {
12
- if (tool === 'vite') {
12
+ if (tool === "vite") {
13
13
  const { start } = await import(vitePath);
14
14
  await start();
15
15
  }
16
16
  else {
17
- if (tool === 'rspack') {
17
+ if (tool === "rspack") {
18
18
  const { start } = await import(rspackPath);
19
19
  await start();
20
20
  return;
@@ -24,12 +24,12 @@ export function clientPlugin() {
24
24
  }
25
25
  },
26
26
  build: async () => {
27
- if (tool === 'vite') {
27
+ if (tool === "vite") {
28
28
  const { build } = await import(vitePath);
29
29
  await build();
30
30
  }
31
31
  else {
32
- if (tool === 'rspack') {
32
+ if (tool === "rspack") {
33
33
  const { build } = await import(rspackPath);
34
34
  await build();
35
35
  return;
@@ -37,7 +37,7 @@ export function clientPlugin() {
37
37
  const { build } = await import(webpackPath);
38
38
  await build();
39
39
  }
40
- }
40
+ },
41
41
  };
42
42
  }
43
43
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAErD,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,EAAE,CAAA;AAE7B,MAAM,UAAU,YAAY;IAC3B,MAAM,GAAG,GAAG,MAAM,EAAE,CAAA;IACpB,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,4BAA4B,CAAC,CAAA;IAC9D,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE,yBAAyB,CAAC,CAAA;IACxD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,2BAA2B,CAAC,CAAA;IAC5D,OAAO;QACN,IAAI,EAAE,cAAc;QACpB,KAAK,EAAE,KAAK,IAAI,EAAE;YACjB,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;gBACrB,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CA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,CAAC"}
package/package.json CHANGED
@@ -1,59 +1,58 @@
1
1
  {
2
2
  "name": "ssr-plugin-react",
3
- "version": "7.0.5",
3
+ "version": "7.0.7",
4
4
  "description": "plugin-react for ssr",
5
- "main": "./cjs/index.js",
6
- "module": "./esm/index.js",
7
- "sideEffects": false,
8
- "scripts": {
9
- "build": "concurrently \"tsc -p ./tsconfig.cjs.json \" \" tsc -p ./tsconfig.esm.json\"",
10
- "watch": "concurrently \"tsc -w -p ./tsconfig.cjs.json \" \"tsc -w -p ./tsconfig.esm.json \""
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/zhangyuang/ssr.git"
15
- },
16
5
  "keywords": [
17
6
  "cli",
7
+ "react",
18
8
  "serverless",
19
9
  "ssr",
20
- "react",
21
10
  "vue"
22
11
  ],
23
- "author": "zhangyuang",
24
- "license": "MIT",
12
+ "homepage": "https://github.com/zhangyuang/ssr#readme",
25
13
  "bugs": {
26
14
  "url": "https://github.com/zhangyuang/ssr/issues"
27
15
  },
28
- "engines": {
29
- "node": ">=14.17.0"
16
+ "license": "MIT",
17
+ "author": "zhangyuang",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/zhangyuang/ssr.git"
21
+ },
22
+ "sideEffects": false,
23
+ "main": "./cjs/index.js",
24
+ "module": "./esm/index.js",
25
+ "scripts": {
26
+ "build": "concurrently \"tsc -p ./tsconfig.cjs.json \" \" tsc -p ./tsconfig.esm.json\"",
27
+ "watch": "concurrently \"tsc -w -p ./tsconfig.cjs.json \" \"tsc -w -p ./tsconfig.esm.json \""
30
28
  },
31
- "homepage": "https://github.com/zhangyuang/ssr#readme",
32
29
  "dependencies": {
33
- "ssr-common-utils": "^7.0.0",
34
- "@vitejs/plugin-react-oxc": "^0.3.0",
35
- "@vitejs/plugin-react": "^4.0.0",
30
+ "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
31
+ "@vitejs/plugin-react": "^6.0.1",
36
32
  "babel-preset-react-app": "^10.0.0",
33
+ "ssr-common-utils": "^7.0.0",
37
34
  "ssr-hoc-react": "^7.0.0",
38
- "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
39
35
  "valtio": "^1.13.2"
40
36
  },
41
- "peerDependencies": {
42
- "react": ">=17.0.1",
43
- "react-dom": ">=17.0.0",
44
- "react-router": "^5.1.8",
45
- "react-router-dom": "^5.0.0"
46
- },
47
37
  "devDependencies": {
48
- "@types/react18": "npm:@types/react@^18.0.0",
49
- "@types/react-dom18": "npm:@types/react-dom@^18.0.0",
50
38
  "@types/react": "^17.0.0",
51
39
  "@types/react-dom": "^17.0.0",
40
+ "@types/react-dom18": "npm:@types/react-dom@^18.0.0",
52
41
  "@types/react-router-dom": "^5.1.3",
42
+ "@types/react18": "npm:@types/react@^18.0.0",
53
43
  "@types/webpack": "^4.41.10",
54
44
  "concurrently": "^5.1.0",
55
45
  "ssr-types": "workspace:*",
56
- "ssr-webpack": "workspace:*",
57
- "ssr-vite": "workspace:*"
46
+ "ssr-vite": "workspace:*",
47
+ "ssr-webpack": "workspace:*"
48
+ },
49
+ "peerDependencies": {
50
+ "react": ">=17.0.1",
51
+ "react-dom": ">=17.0.0",
52
+ "react-router": "^5.1.8",
53
+ "react-router-dom": "^5.0.0"
54
+ },
55
+ "engines": {
56
+ "node": ">=14.17.0"
58
57
  }
59
58
  }
@@ -1,42 +1,46 @@
1
- import { useReducer, createElement } from 'react'
2
- import { IProps, Action, IWindow, ReactRoutesType } from 'ssr-types'
3
- import { Routes } from './create'
1
+ import { useReducer, createElement } from "react";
2
+ import { IProps, Action, IWindow, ReactRoutesType } from "ssr-types";
3
+ import { Routes } from "./create";
4
4
 
5
- const { reducer, state } = Routes as ReactRoutesType
5
+ const { reducer, state } = Routes as ReactRoutesType;
6
6
 
7
- const userState = state ?? {}
8
- const userReducer = reducer ?? function () {}
7
+ const userState = state ?? {};
8
+ const userReducer = reducer ?? function () {};
9
9
 
10
- const isDev = process.env.NODE_ENV !== 'production'
10
+ const isDev = process.env.NODE_ENV !== "production";
11
11
 
12
- declare const window: IWindow
12
+ declare const window: IWindow;
13
13
 
14
14
  function defaultReducer(state: any, action: Action) {
15
- switch (action.type) {
16
- case 'updateContext':
17
- if (isDev) {
18
- console.log('[SSR:updateContext]: dispatch updateContext with action')
19
- console.log(action)
20
- }
21
- return { ...state, ...action.payload }
22
- }
15
+ switch (action.type) {
16
+ case "updateContext":
17
+ if (isDev) {
18
+ console.log("[SSR:updateContext]: dispatch updateContext with action");
19
+ console.log(action);
20
+ }
21
+ return { ...state, ...action.payload };
22
+ }
23
23
  }
24
24
 
25
25
  function combineReducer(state: any, action: any) {
26
- return defaultReducer(state, action) || userReducer(state, action)
26
+ return defaultReducer(state, action) || userReducer(state, action);
27
27
  }
28
28
 
29
29
  export function AppContext(props: IProps) {
30
- const initialState = Object.assign({}, userState ?? {}, __isBrowser__ ? window?.__INITIAL_DATA__ : props.initialState)
31
- const [state, dispatch] = useReducer(combineReducer, initialState)
32
- return createElement(
33
- props.context.Provider,
34
- {
35
- value: {
36
- state,
37
- dispatch
38
- }
39
- },
40
- props.children as any
41
- )
30
+ const initialState = Object.assign(
31
+ {},
32
+ userState ?? {},
33
+ __isBrowser__ ? window?.__INITIAL_DATA__ : props.initialState,
34
+ );
35
+ const [state, dispatch] = useReducer(combineReducer, initialState);
36
+ return createElement(
37
+ props.context.Provider,
38
+ {
39
+ value: {
40
+ state,
41
+ dispatch,
42
+ },
43
+ },
44
+ props.children as any,
45
+ );
42
46
  }
@@ -1,28 +1,31 @@
1
- import * as declareRoutes from '_build/ssr-declare-routes'
2
- import * as ManualRoutes from '_build/ssr-manual-routes'
3
- import { createContext } from 'react'
4
- import { combineRoutes } from 'ssr-common-utils'
5
- import { deepClone } from 'ssr-deepclone'
6
- import type { IContext } from 'ssr-types'
7
- import { ReactRoutesType } from 'ssr-types'
8
- import { proxy } from 'valtio'
1
+ import * as declareRoutes from "_build/ssr-declare-routes";
2
+ import * as ManualRoutes from "_build/ssr-manual-routes";
3
+ import { createContext } from "react";
4
+ import { combineRoutes } from "ssr-common-utils";
5
+ import { deepClone } from "ssr-deepclone";
6
+ import { proxy } from "valtio";
7
+ import type { IContext, ReactRoutesType } from "ssr-types";
9
8
 
10
- export const Routes = combineRoutes(declareRoutes, ManualRoutes) as ReactRoutesType
9
+ export const Routes = combineRoutes(declareRoutes, ManualRoutes) as ReactRoutesType;
11
10
  export const ssrCreateContext = () => {
12
- const STORE_CONTEXT = createContext<IContext>({
13
- state: {}
14
- })
15
- if (__isBrowser__) {
16
- window.STORE_CONTEXT = STORE_CONTEXT
17
- }
18
- return STORE_CONTEXT
19
- }
11
+ const STORE_CONTEXT = createContext<IContext>({
12
+ state: {},
13
+ });
14
+ if (__isBrowser__) {
15
+ window.STORE_CONTEXT = STORE_CONTEXT;
16
+ }
17
+ return STORE_CONTEXT;
18
+ };
20
19
 
21
- export function createStore(initialData?: any) {
22
- const { store } = Routes
23
- const storeInstance = initialData ? store : deepClone(store)
24
- for (const key in storeInstance) {
25
- storeInstance[key] = initialData ? proxy(initialData[key]) : proxy(storeInstance[key])
26
- }
27
- return storeInstance
20
+ export function createStore() {
21
+ const { store } = Routes;
22
+ const storeInstance = __isBrowser__ ? store : proxy(deepClone(store));
23
+ if (__isBrowser__) {
24
+ for (const key in storeInstance) {
25
+ if (__isBrowser__ && window.__VALTIO_DATA__?.[key]) {
26
+ Object.assign(storeInstance[key], window.__VALTIO_DATA__[key]);
27
+ }
28
+ }
29
+ }
30
+ return storeInstance;
28
31
  }
@@ -1,73 +1,73 @@
1
- import type { LayoutProps } from 'ssr-types'
2
- import ReactDOM from 'react-dom'
3
- import { createElement } from 'react'
4
- import { BrowserRouter, Route, Switch } from 'react-router-dom'
5
- import { preloadComponent, isMicro, setStoreContext, setStore } from 'ssr-common-utils'
6
- import { wrapComponent } from 'ssr-hoc-react'
7
- import { ssrCreateContext, Routes, createStore } from './create'
8
- import { AppContext } from './context'
1
+ import type { LayoutProps } from "ssr-types";
2
+ import ReactDOM from "react-dom";
3
+ import { createElement } from "react";
4
+ import { BrowserRouter, Route, Switch } from "react-router-dom";
5
+ import { preloadComponent, isMicro, setStoreContext, setStore } from "ssr-common-utils";
6
+ import { wrapComponent } from "ssr-hoc-react";
7
+ import { ssrCreateContext, Routes, createStore } from "./create";
8
+ import { AppContext } from "./context";
9
9
 
10
- const { FeRoutes, layoutFetch, App } = Routes
10
+ const { FeRoutes, layoutFetch, App } = Routes;
11
11
 
12
12
  const clientRender = async (): Promise<void> => {
13
- const IApp =
14
- App ??
15
- function (props: LayoutProps) {
16
- return props.children!
17
- }
18
- const context = ssrCreateContext() as any
19
- setStoreContext(context)
20
- const store = createStore(window.__VALTIO_DATA__)
21
- setStore(store ?? {})
22
- const baseName = isMicro() ? window.clientPrefix : window.prefix
23
- const routes = await preloadComponent(FeRoutes, baseName)
24
- const container = document.querySelector(window.ssrDevInfo.rootId ?? '#app')!
25
- const ele = createElement(
26
- //@ts-ignore
27
- BrowserRouter,
28
- {
29
- basename: baseName
30
- },
31
- createElement(AppContext, {
32
- context,
33
- children: createElement(
34
- Switch,
35
- null,
36
- createElement(
37
- IApp as any,
38
- null,
39
- createElement(
40
- Switch,
41
- null,
42
- routes.map((item) => {
43
- const { fetch, component, path } = item
44
- component.fetch = fetch
45
- component.layoutFetch = layoutFetch
46
- const WrappedComponent = wrapComponent(component)
47
- return createElement(Route, {
48
- exact: true,
49
- key: path,
50
- path: path,
51
- render: (props) =>
52
- createElement(WrappedComponent, {
53
- ...props,
54
- key: props.history.location.key
55
- })
56
- })
57
- })
58
- )
59
- )
60
- )
61
- })
62
- )
13
+ const IApp =
14
+ App ??
15
+ function (props: LayoutProps) {
16
+ return props.children!;
17
+ };
18
+ const context = ssrCreateContext() as any;
19
+ setStoreContext(context);
20
+ const store = createStore();
21
+ setStore(store ?? {});
22
+ const baseName = isMicro() ? window.clientPrefix : window.prefix;
23
+ const routes = await preloadComponent(FeRoutes, baseName);
24
+ const container = document.querySelector(window.ssrDevInfo.rootId ?? "#app")!;
25
+ const ele = createElement(
26
+ //@ts-ignore
27
+ BrowserRouter,
28
+ {
29
+ basename: baseName,
30
+ },
31
+ createElement(AppContext, {
32
+ context,
33
+ children: createElement(
34
+ Switch,
35
+ null,
36
+ createElement(
37
+ IApp as any,
38
+ null,
39
+ createElement(
40
+ Switch,
41
+ null,
42
+ routes.map((item) => {
43
+ const { fetch, component, path } = item;
44
+ component.fetch = fetch;
45
+ component.layoutFetch = layoutFetch;
46
+ const WrappedComponent = wrapComponent(component);
47
+ return createElement(Route, {
48
+ exact: true,
49
+ key: path,
50
+ path: path,
51
+ render: (props) =>
52
+ createElement(WrappedComponent, {
53
+ ...props,
54
+ key: props.history.location.key,
55
+ }),
56
+ });
57
+ }),
58
+ ),
59
+ ),
60
+ ),
61
+ }),
62
+ );
63
63
 
64
- ReactDOM[window.__USE_SSR__ ? 'hydrate' : 'render'](ele, container)
64
+ ReactDOM[window.__USE_SSR__ ? "hydrate" : "render"](ele, container);
65
65
 
66
- if (!window.__USE_VITE__) {
67
- ;(module as any)?.hot?.accept?.()
68
- }
69
- }
66
+ if (!window.__USE_VITE__) {
67
+ (module as any)?.hot?.accept?.();
68
+ }
69
+ };
70
70
 
71
- clientRender()
71
+ clientRender();
72
72
 
73
- export { clientRender }
73
+ export { clientRender };