@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.
- package/esm/shuvi-app/entry/client/app.js +7 -0
- package/esm/shuvi-app/react/view/ReactView.client.jsx +29 -39
- package/esm/shuvi-app/react/view/render.d.ts +8 -0
- package/esm/shuvi-app/react/view/{render-action.js → render.js} +6 -6
- package/package.json +12 -12
- package/esm/shuvi-app/react/view/render-action.d.ts +0 -10
|
@@ -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 {
|
|
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
|
-
|
|
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
|
-
|
|
56
|
-
|
|
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
|
-
|
|
74
|
-
this._isInitialRender = false;
|
|
75
|
-
};
|
|
76
|
-
renderAction({
|
|
77
|
-
ssr,
|
|
78
|
-
isInitialRender,
|
|
66
|
+
doRender({
|
|
79
67
|
root,
|
|
80
|
-
|
|
81
|
-
|
|
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
|
|
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
|
-
|
|
6
|
-
if (
|
|
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
|
-
|
|
21
|
-
if (
|
|
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 {
|
|
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.
|
|
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.
|
|
69
|
-
"@shuvi/platform-shared": "1.0.0-rc.
|
|
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.
|
|
73
|
-
"@shuvi/router-react": "1.0.0-rc.
|
|
74
|
-
"@shuvi/runtime": "1.0.0-rc.
|
|
75
|
-
"@shuvi/service": "1.0.0-rc.
|
|
76
|
-
"@shuvi/shared": "1.0.0-rc.
|
|
77
|
-
"@shuvi/toolpack": "1.0.0-rc.
|
|
78
|
-
"@shuvi/utils": "1.0.0-rc.
|
|
79
|
-
"@shuvi/error-overlay": "1.0.0-rc.
|
|
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.
|
|
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 };
|