@ossy/app 1.5.0 → 1.6.0

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.
@@ -1,6 +1,15 @@
1
1
  import React, { cloneElement } from 'react'
2
2
  import { prerenderToNodeStream } from 'react-dom/static'
3
3
 
4
+ /** Strips non-JSON content (e.g. React elements on `pages`) for the bootstrap script. */
5
+ export function appConfigForBootstrap (appConfig) {
6
+ if (!appConfig || typeof appConfig !== 'object') return appConfig
7
+ const pages = Array.isArray(appConfig.pages)
8
+ ? appConfig.pages.map(({ id, path }) => ({ id, path }))
9
+ : appConfig.pages
10
+ return { ...appConfig, pages }
11
+ }
12
+
4
13
  export const BuildPage = {
5
14
  async handle ({ route, appConfig, isDevReloadEnabled }) {
6
15
  const rootElement = cloneElement(route.element, appConfig)
@@ -10,7 +19,7 @@ export const BuildPage = {
10
19
 
11
20
  const hydrateUrl = `/static/hydrate-${route.id}.js`
12
21
  const { prelude } = await prerenderToNodeStream(rootElement, {
13
- bootstrapScriptContent: `window.__INITIAL_APP_CONFIG__ = ${JSON.stringify(appConfig)};${devReloadScript}`,
22
+ bootstrapScriptContent: `window.__INITIAL_APP_CONFIG__ = ${JSON.stringify(appConfigForBootstrap(appConfig))};${devReloadScript}`,
14
23
  bootstrapModules: [hydrateUrl],
15
24
  })
16
25
 
package/cli/server.js CHANGED
@@ -111,12 +111,18 @@ const Router = OssyRouter.of({
111
111
  pages: [...apiRouteList, ...pageList]
112
112
  })
113
113
 
114
- function resolveAppConfig ({ req, buildTimeConfig }) {
114
+ function resolveAppConfig ({ req, buildTimeConfig, activeRouteId }) {
115
115
  const userAppSettings = req.userAppSettings || {}
116
- const pages = pageList.map((page) => ({
117
- id: page?.id,
118
- path: page?.path,
119
- }))
116
+ const pages = pageList.map((page) => {
117
+ const entry = {
118
+ id: page?.id,
119
+ path: page?.path,
120
+ }
121
+ if (activeRouteId != null && page?.id === activeRouteId) {
122
+ entry.element = page?.element
123
+ }
124
+ return entry
125
+ })
120
126
  return {
121
127
  ...buildTimeConfig,
122
128
  url: req.originalUrl,
@@ -141,13 +147,17 @@ app.all('*all', (req, res) => {
141
147
  return
142
148
  }
143
149
 
144
- const appConfig = resolveAppConfig({ req, buildTimeConfig })
145
-
146
150
  if (!route?.element) {
147
151
  res.status(404).send('Not found')
148
152
  return
149
153
  }
150
154
 
155
+ const appConfig = resolveAppConfig({
156
+ req,
157
+ buildTimeConfig,
158
+ activeRouteId: route.id,
159
+ })
160
+
151
161
  BuildPage.handle({ route, appConfig, isDevReloadEnabled })
152
162
  .then(html => { res.send(html) })
153
163
  .catch(err => { res.send(err) })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ossy/app",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
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.5.0",
31
- "@ossy/design-system": "^1.5.0",
32
- "@ossy/pages": "^1.5.0",
33
- "@ossy/router": "^1.5.0",
34
- "@ossy/router-react": "^1.5.0",
35
- "@ossy/sdk": "^1.5.0",
36
- "@ossy/sdk-react": "^1.5.0",
37
- "@ossy/themes": "^1.5.0",
30
+ "@ossy/connected-components": "^1.6.0",
31
+ "@ossy/design-system": "^1.6.0",
32
+ "@ossy/pages": "^1.6.0",
33
+ "@ossy/router": "^1.6.0",
34
+ "@ossy/router-react": "^1.6.0",
35
+ "@ossy/sdk": "^1.6.0",
36
+ "@ossy/sdk-react": "^1.6.0",
37
+ "@ossy/themes": "^1.6.0",
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": "b1a36350ae22ae6776163952e3bf03b2a6cb6498"
70
+ "gitHead": "a1c29650f72ec23bd397d3c9e1c42387461acf8e"
71
71
  }