@ossy/app 1.11.3 → 1.11.4
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/cli/render-page.task.js +33 -12
- package/package.json +10 -10
package/cli/render-page.task.js
CHANGED
|
@@ -11,16 +11,11 @@ export function buildPrerenderAppConfig ({
|
|
|
11
11
|
urlPath,
|
|
12
12
|
isAuthenticated = false,
|
|
13
13
|
}) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (activeRouteId != null && page?.id === activeRouteId) {
|
|
20
|
-
entry.element = page?.element
|
|
21
|
-
}
|
|
22
|
-
return entry
|
|
23
|
-
})
|
|
14
|
+
/** Never attach `element` here — it cannot round-trip through `JSON.stringify` in the hydrate bootstrap. */
|
|
15
|
+
const pages = pageList.map((page) => ({
|
|
16
|
+
id: page?.id,
|
|
17
|
+
path: page?.path,
|
|
18
|
+
}))
|
|
24
19
|
return {
|
|
25
20
|
...buildTimeConfig,
|
|
26
21
|
url: urlPath,
|
|
@@ -42,16 +37,42 @@ export function appConfigForBootstrap (appConfig) {
|
|
|
42
37
|
return { ...appConfig, pages }
|
|
43
38
|
}
|
|
44
39
|
|
|
40
|
+
/** Plain data clone so server render props match `JSON.parse(JSON.stringify(...))` on the client. */
|
|
41
|
+
function jsonSafeClone (value) {
|
|
42
|
+
if (value == null || typeof value !== 'object') return value
|
|
43
|
+
if (typeof value === 'function' || React.isValidElement(value)) return value
|
|
44
|
+
try {
|
|
45
|
+
return JSON.parse(JSON.stringify(value))
|
|
46
|
+
} catch {
|
|
47
|
+
return value
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Props passed to `<App>` for SSR and the exact object embedded in `window.__INITIAL_APP_CONFIG__`.
|
|
53
|
+
* Keeps server and hydrate trees aligned (fixes React #418 hydration mismatches).
|
|
54
|
+
*/
|
|
55
|
+
export function buildHydrationAppConfig (appConfig) {
|
|
56
|
+
const base = appConfigForBootstrap(appConfig)
|
|
57
|
+
return {
|
|
58
|
+
...base,
|
|
59
|
+
theme: jsonSafeClone(base.theme),
|
|
60
|
+
themes: jsonSafeClone(base.themes),
|
|
61
|
+
resourceTemplates: jsonSafeClone(base.resourceTemplates),
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
45
65
|
export const BuildPage = {
|
|
46
66
|
async handle ({ route, appConfig, isDevReloadEnabled }) {
|
|
47
|
-
const
|
|
67
|
+
const hydrationConfig = buildHydrationAppConfig(appConfig)
|
|
68
|
+
const rootElement = cloneElement(route.element, hydrationConfig)
|
|
48
69
|
const devReloadScript = isDevReloadEnabled
|
|
49
70
|
? `(function(){try{var es=new EventSource('/__ossy_reload');es.addEventListener('reload',function(){location.reload();});}catch(e){}})();`
|
|
50
71
|
: ``
|
|
51
72
|
|
|
52
73
|
const hydrateUrl = `/static/hydrate-${route.id}.js`
|
|
53
74
|
const { prelude } = await prerenderToNodeStream(rootElement, {
|
|
54
|
-
bootstrapScriptContent: `window.__INITIAL_APP_CONFIG__ = ${JSON.stringify(
|
|
75
|
+
bootstrapScriptContent: `window.__INITIAL_APP_CONFIG__ = ${JSON.stringify(hydrationConfig)};${devReloadScript}`,
|
|
55
76
|
bootstrapModules: [hydrateUrl],
|
|
56
77
|
})
|
|
57
78
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/app",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"source": "./src/index.js",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"@babel/eslint-parser": "^7.15.8",
|
|
28
28
|
"@babel/preset-react": "^7.26.3",
|
|
29
29
|
"@babel/register": "^7.25.9",
|
|
30
|
-
"@ossy/connected-components": "^1.11.
|
|
31
|
-
"@ossy/design-system": "^1.11.
|
|
32
|
-
"@ossy/pages": "^1.11.
|
|
33
|
-
"@ossy/router": "^1.11.
|
|
34
|
-
"@ossy/router-react": "^1.11.
|
|
35
|
-
"@ossy/sdk": "^1.11.
|
|
36
|
-
"@ossy/sdk-react": "^1.11.
|
|
37
|
-
"@ossy/themes": "^1.11.
|
|
30
|
+
"@ossy/connected-components": "^1.11.4",
|
|
31
|
+
"@ossy/design-system": "^1.11.4",
|
|
32
|
+
"@ossy/pages": "^1.11.4",
|
|
33
|
+
"@ossy/router": "^1.11.4",
|
|
34
|
+
"@ossy/router-react": "^1.11.4",
|
|
35
|
+
"@ossy/sdk": "^1.11.4",
|
|
36
|
+
"@ossy/sdk-react": "^1.11.4",
|
|
37
|
+
"@ossy/themes": "^1.11.4",
|
|
38
38
|
"@rollup/plugin-alias": "^6.0.0",
|
|
39
39
|
"@rollup/plugin-babel": "6.1.0",
|
|
40
40
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"README.md",
|
|
68
68
|
"tsconfig.json"
|
|
69
69
|
],
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "431ec3200bf38c97ac4d5a269f596133da3958bc"
|
|
71
71
|
}
|