@shuvi/platform-web 1.0.0-rc.7 → 1.0.0-rc.8

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.
@@ -55,3 +55,10 @@ if (module.hot) {
55
55
  });
56
56
  module.hot.accept(['@shuvi/app/files/routes'], handleHotUpdate);
57
57
  }
58
+ // For e2e test
59
+ if (window.__SHUVI) {
60
+ window.__SHUVI.router = app.router;
61
+ }
62
+ else {
63
+ window.__SHUVI = { router: app.router };
64
+ }
@@ -14,7 +14,7 @@ import { getServerError } from '@shuvi/error-overlay';
14
14
  import AppContainer from '../AppContainer';
15
15
  import { HeadManager, HeadManagerContext } from '../head';
16
16
  import Loadable from '../loadable';
17
- import { renderAction } from './render-action';
17
+ import { doRender } from './render';
18
18
  const headManager = new HeadManager();
19
19
  export class ReactClientView {
20
20
  constructor() {
@@ -23,37 +23,30 @@ export class ReactClientView {
23
23
  const { _isInitialRender: isInitialRender } = this;
24
24
  const { router, appComponent: AppComponent, setError: setAppError, error: appError } = app;
25
25
  let { ssr, dynamicIds } = appData;
26
- // For e2e test
27
- if (window.__SHUVI) {
28
- window.__SHUVI.router = router;
29
- }
30
- else {
31
- window.__SHUVI = { router };
32
- }
33
- if (process.env.NODE_ENV === 'development') {
34
- if (appError && appError.source === 'server') {
35
- setTimeout(() => {
36
- var _a;
37
- let error;
38
- try {
39
- // Generate a new error object. We `throw` it because some browsers
40
- // will set the `stack` when thrown, and we want to ensure ours is
41
- // not overridden when we re-throw it below.
42
- throw new Error(appError.message);
43
- }
44
- catch (e) {
45
- error = e;
46
- }
47
- error.name = (_a = appError.name) !== null && _a !== void 0 ? _a : '';
48
- error.stack = appError.stack;
49
- throw getServerError(error);
50
- });
51
- }
52
- }
26
+ const shouldHydrate = ssr && isInitialRender;
53
27
  const TypedAppComponent = AppComponent;
54
- if (ssr) {
55
- yield Loadable.preloadReady(dynamicIds);
56
- yield router.ready;
28
+ if (ssr && isInitialRender) {
29
+ if (process.env.NODE_ENV === 'development') {
30
+ if (appError && appError.source === 'server') {
31
+ setTimeout(() => {
32
+ var _a;
33
+ let error;
34
+ try {
35
+ // Generate a new error object. We `throw` it because some browsers
36
+ // will set the `stack` when thrown, and we want to ensure ours is
37
+ // not overridden when we re-throw it below.
38
+ throw new Error(appError.message);
39
+ }
40
+ catch (e) {
41
+ error = e;
42
+ }
43
+ error.name = (_a = appError.name) !== null && _a !== void 0 ? _a : '';
44
+ error.stack = appError.stack;
45
+ throw getServerError(error);
46
+ });
47
+ }
48
+ }
49
+ yield Promise.all([Loadable.preloadReady(dynamicIds), router.ready]);
57
50
  }
58
51
  else {
59
52
  yield router.ready;
@@ -70,15 +63,12 @@ export class ReactClientView {
70
63
  </HeadManagerContext.Provider>
71
64
  </AppContainer>
72
65
  </Router>);
73
- const ssrCallback = () => {
74
- this._isInitialRender = false;
75
- };
76
- renderAction({
77
- ssr,
78
- isInitialRender,
66
+ doRender({
79
67
  root,
80
- callback: ssrCallback,
81
- appContainer
68
+ appContainer,
69
+ shouldHydrate
70
+ }, () => {
71
+ this._isInitialRender = false;
82
72
  });
83
73
  });
84
74
  }
@@ -0,0 +1,8 @@
1
+ import { ReactNode } from 'react';
2
+ declare type RenderActionParam = {
3
+ appContainer: Element | Document;
4
+ root?: ReactNode;
5
+ shouldHydrate?: boolean;
6
+ };
7
+ declare let doRender: (options: RenderActionParam, callback: () => void) => void;
8
+ export { doRender };
@@ -1,9 +1,9 @@
1
- let renderAction;
1
+ let doRender;
2
2
  if (process.env.__SHUVI__AFTER__REACT__18__) {
3
3
  const { createRoot, hydrateRoot } = require('react-dom/client');
4
4
  let renderRoot;
5
- renderAction = ({ ssr, isInitialRender, root, callback, appContainer }) => {
6
- if (ssr && isInitialRender) {
5
+ doRender = ({ root, appContainer, shouldHydrate }, callback) => {
6
+ if (shouldHydrate) {
7
7
  renderRoot = hydrateRoot(appContainer, root);
8
8
  callback === null || callback === void 0 ? void 0 : callback();
9
9
  }
@@ -17,8 +17,8 @@ if (process.env.__SHUVI__AFTER__REACT__18__) {
17
17
  }
18
18
  else {
19
19
  const { hydrate, render } = require('react-dom');
20
- renderAction = ({ ssr, isInitialRender, root, callback, appContainer }) => {
21
- if (ssr && isInitialRender) {
20
+ doRender = ({ root, appContainer, shouldHydrate }, callback) => {
21
+ if (shouldHydrate) {
22
22
  hydrate(root, appContainer, callback);
23
23
  }
24
24
  else {
@@ -26,4 +26,4 @@ else {
26
26
  }
27
27
  };
28
28
  }
29
- export { renderAction };
29
+ export { doRender };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/platform-web",
3
- "version": "1.0.0-rc.7",
3
+ "version": "1.0.0-rc.8",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/shuvijs/shuvi.git",
@@ -65,18 +65,18 @@
65
65
  },
66
66
  "dependencies": {
67
67
  "@next/react-refresh-utils": "12.1.6",
68
- "@shuvi/hook": "1.0.0-rc.7",
69
- "@shuvi/platform-shared": "1.0.0-rc.7",
68
+ "@shuvi/hook": "1.0.0-rc.8",
69
+ "@shuvi/platform-shared": "1.0.0-rc.8",
70
70
  "@shuvi/redox": "0.0.6",
71
71
  "@shuvi/redox-react": "0.0.6",
72
- "@shuvi/router": "1.0.0-rc.7",
73
- "@shuvi/router-react": "1.0.0-rc.7",
74
- "@shuvi/runtime": "1.0.0-rc.7",
75
- "@shuvi/service": "1.0.0-rc.7",
76
- "@shuvi/shared": "1.0.0-rc.7",
77
- "@shuvi/toolpack": "1.0.0-rc.7",
78
- "@shuvi/utils": "1.0.0-rc.7",
79
- "@shuvi/error-overlay": "1.0.0-rc.7",
72
+ "@shuvi/router": "1.0.0-rc.8",
73
+ "@shuvi/router-react": "1.0.0-rc.8",
74
+ "@shuvi/runtime": "1.0.0-rc.8",
75
+ "@shuvi/service": "1.0.0-rc.8",
76
+ "@shuvi/shared": "1.0.0-rc.8",
77
+ "@shuvi/toolpack": "1.0.0-rc.8",
78
+ "@shuvi/utils": "1.0.0-rc.8",
79
+ "@shuvi/error-overlay": "1.0.0-rc.8",
80
80
  "content-type": "1.0.4",
81
81
  "cookie": "0.4.1",
82
82
  "ejs": "3.1.5",
@@ -92,7 +92,7 @@
92
92
  "use-sync-external-store": "1.1.0"
93
93
  },
94
94
  "peerDependencies": {
95
- "@shuvi/service": "1.0.0-rc.7"
95
+ "@shuvi/service": "1.0.0-rc.8"
96
96
  },
97
97
  "devDependencies": {
98
98
  "@types/react": "18.0.9",
@@ -1,10 +0,0 @@
1
- import { ReactNode } from 'react';
2
- declare type RenderActionParam = {
3
- ssr?: boolean;
4
- isInitialRender?: boolean;
5
- root?: ReactNode;
6
- callback?: () => unknown;
7
- appContainer?: Element | Document;
8
- };
9
- declare let renderAction: (options: RenderActionParam) => void;
10
- export { renderAction };