@uniweb/runtime 0.6.10 → 0.6.11
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/package.json +1 -1
- package/src/RuntimeProvider.jsx +20 -10
- package/src/index.jsx +4 -1
package/package.json
CHANGED
package/src/RuntimeProvider.jsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* RuntimeProvider
|
|
3
3
|
*
|
|
4
4
|
* Encapsulates the full React rendering tree for a Uniweb site:
|
|
5
|
-
* ErrorBoundary →
|
|
5
|
+
* ErrorBoundary → Router → Routes → WebsiteRenderer.
|
|
6
6
|
*
|
|
7
7
|
* The Uniweb singleton (globalThis.uniweb) must be set up BEFORE rendering
|
|
8
8
|
* this component. RuntimeProvider reads from the singleton — it does not
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
* @param {Object} props
|
|
13
13
|
* @param {string} [props.basename] - Router basename for subdirectory deployments
|
|
14
14
|
* @param {boolean} [props.development] - Enable React StrictMode
|
|
15
|
+
* @param {boolean} [props.externalRouter] - Skip creating a BrowserRouter — the
|
|
16
|
+
* consumer wraps RuntimeProvider in their own Router (e.g., MemoryRouter for
|
|
17
|
+
* srcdoc iframes). RuntimeProvider still renders ErrorBoundary, Routes, and
|
|
18
|
+
* WebsiteRenderer.
|
|
15
19
|
*/
|
|
16
20
|
|
|
17
21
|
import React from 'react'
|
|
@@ -19,7 +23,7 @@ import { BrowserRouter, Routes, Route } from 'react-router-dom'
|
|
|
19
23
|
import WebsiteRenderer from './components/WebsiteRenderer.jsx'
|
|
20
24
|
import ErrorBoundary from './components/ErrorBoundary.jsx'
|
|
21
25
|
|
|
22
|
-
export default function RuntimeProvider({ basename, development = false }) {
|
|
26
|
+
export default function RuntimeProvider({ basename, development = false, externalRouter = false }) {
|
|
23
27
|
const website = globalThis.uniweb?.activeWebsite
|
|
24
28
|
if (!website) return null
|
|
25
29
|
|
|
@@ -28,15 +32,21 @@ export default function RuntimeProvider({ basename, development = false }) {
|
|
|
28
32
|
website.setBasePath(basename || '')
|
|
29
33
|
}
|
|
30
34
|
|
|
31
|
-
const
|
|
32
|
-
<
|
|
33
|
-
<
|
|
34
|
-
|
|
35
|
-
<Route path="/*" element={<WebsiteRenderer />} />
|
|
36
|
-
</Routes>
|
|
37
|
-
</BrowserRouter>
|
|
38
|
-
</ErrorBoundary>
|
|
35
|
+
const routes = (
|
|
36
|
+
<Routes>
|
|
37
|
+
<Route path="/*" element={<WebsiteRenderer />} />
|
|
38
|
+
</Routes>
|
|
39
39
|
)
|
|
40
40
|
|
|
41
|
+
const app = externalRouter
|
|
42
|
+
? <ErrorBoundary>{routes}</ErrorBoundary>
|
|
43
|
+
: (
|
|
44
|
+
<ErrorBoundary>
|
|
45
|
+
<BrowserRouter basename={basename}>
|
|
46
|
+
{routes}
|
|
47
|
+
</BrowserRouter>
|
|
48
|
+
</ErrorBoundary>
|
|
49
|
+
)
|
|
50
|
+
|
|
41
51
|
return development ? <React.StrictMode>{app}</React.StrictMode> : app
|
|
42
52
|
}
|
package/src/index.jsx
CHANGED
|
@@ -173,9 +173,12 @@ async function start({ config, foundation, styles } = {}) {
|
|
|
173
173
|
|
|
174
174
|
if (data) {
|
|
175
175
|
// Dynamic backend mode - foundation loaded from URL, content from data
|
|
176
|
+
// The serving layer may inject config.base for subdirectory deployments
|
|
177
|
+
const base = data.content?.config?.base
|
|
178
|
+
const basename = base ? (base.endsWith('/') ? base.slice(0, -1) : base) : undefined
|
|
176
179
|
return initRuntime(
|
|
177
180
|
{ url: data.foundation.url, cssUrl: data.foundation.cssUrl },
|
|
178
|
-
{ configData: data.content }
|
|
181
|
+
{ configData: data.content, basename }
|
|
179
182
|
)
|
|
180
183
|
}
|
|
181
184
|
|