@zubyjs/react 1.0.65 → 1.0.67
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/contexts/pageContext.d.ts +2 -0
- package/contexts/pageContext.js +3 -0
- package/hooks/index.d.ts +2 -0
- package/hooks/index.js +2 -0
- package/hooks/usePageContext.d.ts +1 -0
- package/hooks/usePageContext.js +5 -0
- package/hooks/useProps.d.ts +1 -1
- package/hooks/useProps.js +1 -1
- package/package.json +1 -1
- package/router.js +12 -6
- package/templates/entry.js +1 -3
package/hooks/index.d.ts
CHANGED
package/hooks/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function usePageContext(): import("zuby/contexts/pageContext.js").PageContext;
|
package/hooks/useProps.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function useProps(path: string, priority?: 'low' | 'high' | 'auto'): string | Object;
|
package/hooks/useProps.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useFetch } from './useFetch.js';
|
|
2
2
|
import { getGlobalContext } from 'zuby/contexts/index.js';
|
|
3
|
-
export
|
|
3
|
+
export function useProps(path, priority = 'auto') {
|
|
4
4
|
const { buildId } = getGlobalContext();
|
|
5
5
|
path = `/_props${path}/?${buildId}`;
|
|
6
6
|
path = path.replace(/\/+/g, '/');
|
package/package.json
CHANGED
package/router.js
CHANGED
|
@@ -5,7 +5,8 @@ import { useParams } from 'wouter';
|
|
|
5
5
|
import { createElement, Suspense } from 'react';
|
|
6
6
|
import { preloadPage } from 'zuby/preload/index.js';
|
|
7
7
|
import lazyWithPreload from './components/lazyWithPreload.js';
|
|
8
|
-
import useProps from './hooks/useProps.js';
|
|
8
|
+
import { useProps } from './hooks/useProps.js';
|
|
9
|
+
import { pageContext } from './contexts/pageContext.js';
|
|
9
10
|
let pages;
|
|
10
11
|
let apps;
|
|
11
12
|
let errors;
|
|
@@ -35,15 +36,20 @@ export default function Router({ context }) {
|
|
|
35
36
|
_jsx(WouterRoute, { children: error?.component && _jsx(Error, { context: context, error: error }) }, "error"),
|
|
36
37
|
];
|
|
37
38
|
const page = _jsx(WouterSwitch, { children: routes });
|
|
38
|
-
return (_jsx(WouterRouter, { ssrPath: context.url.pathname, children: _jsx(Suspense, { fallback: loader?.component && _jsx(loader.component, {}), children: createElement(app?.component, {
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
return (_jsx(pageContext.Provider, { value: context, children: _jsx(WouterRouter, { ssrPath: context.url.pathname, children: _jsx(Suspense, { fallback: loader?.component && _jsx(loader.component, {}), children: createElement(app?.component, {
|
|
40
|
+
children: page,
|
|
41
|
+
}) }) }) }));
|
|
41
42
|
}
|
|
42
43
|
export function Page({ page, context }) {
|
|
43
44
|
context.statusCode = 200;
|
|
44
45
|
context.params = useParams();
|
|
45
|
-
if (typeof window !== 'undefined'
|
|
46
|
-
|
|
46
|
+
if (typeof window !== 'undefined') {
|
|
47
|
+
if (context.isInitialPath) {
|
|
48
|
+
context.props = globalThis.initialPageContext || {};
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
context.props = useProps(context.url.pathname);
|
|
52
|
+
}
|
|
47
53
|
}
|
|
48
54
|
return _jsx(page.component, { ...context.props, context: context });
|
|
49
55
|
}
|
package/templates/entry.js
CHANGED
|
@@ -5,9 +5,7 @@ import { hydrateRoot, createRoot } from 'react-dom/client';
|
|
|
5
5
|
import Router from '@zubyjs/react/router.js';
|
|
6
6
|
import { PageContext } from 'zuby/contexts/index.js';
|
|
7
7
|
if (typeof window !== 'undefined') {
|
|
8
|
-
const pageContext = new PageContext(
|
|
9
|
-
...(globalThis?.initialPageContext || {}),
|
|
10
|
-
});
|
|
8
|
+
const pageContext = new PageContext();
|
|
11
9
|
const appElement = document.getElementById('app');
|
|
12
10
|
if (appElement.hasChildNodes()) {
|
|
13
11
|
hydrateRoot(appElement, _jsx(Router, { context: pageContext }));
|