@ossy/app 1.11.3 → 1.11.5
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/build.js +2 -2
- package/cli/dev.js +5 -4
- package/cli/prerender-react.task.js +4 -4
- package/cli/render-page.task.js +33 -12
- package/package.json +10 -10
package/cli/build.js
CHANGED
|
@@ -22,8 +22,8 @@ const RESOURCE_TEMPLATE_FILE_PATTERN = /\.resource\.js$/
|
|
|
22
22
|
/** Written next to `*.resource.js` under `src/resource-templates/` when that dir exists. */
|
|
23
23
|
export const OSSY_RESOURCE_TEMPLATES_OUT = '.ossy-system-templates.generated.js'
|
|
24
24
|
|
|
25
|
-
/** Rollup output paths
|
|
26
|
-
const BROWSER_STATIC_PREFIX = '
|
|
25
|
+
/** Rollup output paths when `output.dir` is `<build>/public` (see `entryFileNames` / `chunkFileNames`). */
|
|
26
|
+
const BROWSER_STATIC_PREFIX = 'static/'
|
|
27
27
|
|
|
28
28
|
export function minifyBrowserStaticChunks () {
|
|
29
29
|
return {
|
package/cli/dev.js
CHANGED
|
@@ -125,17 +125,18 @@ export const dev = async (cliArgs) => {
|
|
|
125
125
|
buildPath,
|
|
126
126
|
})
|
|
127
127
|
|
|
128
|
+
// `dir` must not be an ancestor of hydrate stubs (`build/.ossy/…`) or Rollup watch errors.
|
|
128
129
|
const clientOutput = {
|
|
129
|
-
dir: buildPath,
|
|
130
|
+
dir: path.join(buildPath, 'public'),
|
|
130
131
|
format: 'esm',
|
|
131
132
|
entryFileNames ({ name }) {
|
|
132
133
|
if (name.startsWith('hydrate__')) {
|
|
133
134
|
const pageId = name.slice('hydrate__'.length)
|
|
134
|
-
return `
|
|
135
|
+
return `static/hydrate-${pageId}.js`
|
|
135
136
|
}
|
|
136
|
-
return '
|
|
137
|
+
return 'static/[name].js'
|
|
137
138
|
},
|
|
138
|
-
chunkFileNames: '
|
|
139
|
+
chunkFileNames: 'static/[name]-[hash].js',
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
let restartTimer = null
|
|
@@ -48,18 +48,18 @@ async function bundleOneHydratePage ({
|
|
|
48
48
|
})
|
|
49
49
|
try {
|
|
50
50
|
await bundle.write({
|
|
51
|
-
dir: buildPath,
|
|
51
|
+
dir: path.join(buildPath, 'public'),
|
|
52
52
|
format: 'esm',
|
|
53
53
|
inlineDynamicImports: true,
|
|
54
54
|
entryFileNames (chunkInfo) {
|
|
55
55
|
const n = chunkInfo.name
|
|
56
56
|
if (n.startsWith('hydrate__')) {
|
|
57
57
|
const pageId = n.slice('hydrate__'.length)
|
|
58
|
-
return `
|
|
58
|
+
return `static/hydrate-${pageId}.js`
|
|
59
59
|
}
|
|
60
|
-
return '
|
|
60
|
+
return 'static/[name].js'
|
|
61
61
|
},
|
|
62
|
-
chunkFileNames: '
|
|
62
|
+
chunkFileNames: 'static/[name]-[hash].js',
|
|
63
63
|
plugins: minifyPlugin ? [minifyPlugin] : [],
|
|
64
64
|
})
|
|
65
65
|
} finally {
|
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.5",
|
|
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.5",
|
|
31
|
+
"@ossy/design-system": "^1.11.5",
|
|
32
|
+
"@ossy/pages": "^1.11.5",
|
|
33
|
+
"@ossy/router": "^1.11.5",
|
|
34
|
+
"@ossy/router-react": "^1.11.5",
|
|
35
|
+
"@ossy/sdk": "^1.11.5",
|
|
36
|
+
"@ossy/sdk-react": "^1.11.5",
|
|
37
|
+
"@ossy/themes": "^1.11.5",
|
|
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": "9dcb9e0e0a09c23690f1a8e009fa79e2961fe6d6"
|
|
71
71
|
}
|