@ossy/app 1.2.0 → 1.3.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.
Files changed (3) hide show
  1. package/cli/build.js +14 -4
  2. package/cli/server.js +15 -3
  3. package/package.json +10 -10
package/cli/build.js CHANGED
@@ -415,10 +415,12 @@ export function generatePageHydrateModule ({ pageAbsPath, stubAbsPath, srcDir })
415
415
  return [
416
416
  '// Generated by @ossy/app — do not edit',
417
417
  '',
418
- "import React, { cloneElement } from 'react'",
418
+ "import React, { cloneElement, createElement } from 'react'",
419
419
  "import 'react-dom'",
420
420
  "import { hydrateRoot } from 'react-dom/client'",
421
+ "import { App } from '@ossy/connected-components'",
421
422
  `import * as _page from './${rel}'`,
423
+ `import pageRoutes from './${OSSY_GEN_PAGES_BASENAME}'`,
422
424
  '',
423
425
  'function toPage(mod, derived) {',
424
426
  ' const meta = mod?.metadata || {}',
@@ -431,9 +433,17 @@ export function generatePageHydrateModule ({ pageAbsPath, stubAbsPath, srcDir })
431
433
  '',
432
434
  `const _route = toPage(_page, { id: ${idLiteral}, path: ${pathLiteral} })`,
433
435
  'const initialConfig = window.__INITIAL_APP_CONFIG__ || {}',
434
- 'const rootTree = _route?.element',
435
- ' ? cloneElement(_route.element, initialConfig)',
436
- " : React.createElement('p', null, 'Not found')",
436
+ 'const pagesForApp = pageRoutes.map((p) =>',
437
+ ' p.id === _route.id',
438
+ ' ? { ...p, element: cloneElement(p.element, initialConfig) }',
439
+ ' : p',
440
+ ')',
441
+ 'const rootTree = createElement(App, {',
442
+ ' ...initialConfig,',
443
+ ' url: window.location.href,',
444
+ ' pages: pagesForApp,',
445
+ ' includeDocumentShell: false,',
446
+ '})',
437
447
  'hydrateRoot(document, rootTree)',
438
448
  '',
439
449
  ].join('\n')
package/cli/server.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import path from 'path';
2
2
  import url from 'url'
3
- import React, { cloneElement } from 'react';
3
+ import React, { cloneElement, createElement } from 'react';
4
4
  import express from 'express'
5
5
  import morgan from 'morgan'
6
6
  import { Router as OssyRouter } from '@ossy/router'
7
+ import { App } from '@ossy/connected-components'
7
8
  import { prerenderToNodeStream } from 'react-dom/static'
8
9
  import { ProxyInternal } from './proxy-internal.js'
9
10
  import cookieParser from 'cookie-parser'
@@ -127,7 +128,7 @@ app.all('*all', (req, res) => {
127
128
 
128
129
  const appConfig = {
129
130
  ...buildTimeConfig,
130
- url: req.url,
131
+ url: req.originalUrl,
131
132
  theme: userAppSettings.theme || buildTimeConfig.theme || 'light',
132
133
  isAuthenticated: req.isAuthenticated || false,
133
134
  workspaceId: userAppSettings.workspaceId || buildTimeConfig.workspaceId,
@@ -141,7 +142,18 @@ app.all('*all', (req, res) => {
141
142
  return
142
143
  }
143
144
 
144
- prerenderHtmlDocument(cloneElement(route.element, appConfig), appConfig, route.id)
145
+ const pagesForApp = pageList.map((p) =>
146
+ p.id === route.id
147
+ ? { ...p, element: cloneElement(p.element, appConfig) }
148
+ : p
149
+ )
150
+ const rootElement = createElement(App, {
151
+ ...appConfig,
152
+ pages: pagesForApp,
153
+ includeDocumentShell: false,
154
+ })
155
+
156
+ prerenderHtmlDocument(rootElement, appConfig, route.id)
145
157
  .then(html => { res.send(html) })
146
158
  .catch(err => { res.send(err) })
147
159
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ossy/app",
3
- "version": "1.2.0",
3
+ "version": "1.3.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.2.0",
31
- "@ossy/design-system": "^1.2.0",
32
- "@ossy/pages": "^1.2.0",
33
- "@ossy/router": "^1.2.0",
34
- "@ossy/router-react": "^1.2.0",
35
- "@ossy/sdk": "^1.2.0",
36
- "@ossy/sdk-react": "^1.2.0",
37
- "@ossy/themes": "^1.2.0",
30
+ "@ossy/connected-components": "^1.3.0",
31
+ "@ossy/design-system": "^1.3.0",
32
+ "@ossy/pages": "^1.3.0",
33
+ "@ossy/router": "^1.3.0",
34
+ "@ossy/router-react": "^1.3.0",
35
+ "@ossy/sdk": "^1.3.0",
36
+ "@ossy/sdk-react": "^1.3.0",
37
+ "@ossy/themes": "^1.3.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": "81441ed4d81a8ca000dc8c4a5c4634e860bfb22b"
70
+ "gitHead": "15e5a4ab14895064b6281eec4daf1cea3340806e"
71
71
  }