@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.
@@ -0,0 +1,2 @@
1
+ import { PageContext } from 'zuby/contexts/index.js';
2
+ export declare const pageContext: import("react").Context<PageContext>;
@@ -0,0 +1,3 @@
1
+ import { PageContext } from 'zuby/contexts/index.js';
2
+ import { createContext } from 'react';
3
+ export const pageContext = createContext(new PageContext({}));
package/hooks/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { useFetch } from './useFetch.js';
2
+ export { usePageContext } from './usePageContext.js';
3
+ export { useProps } from './useProps.js';
2
4
  export * from 'zuby/hooks/index.js';
package/hooks/index.js CHANGED
@@ -1,2 +1,4 @@
1
1
  export { useFetch } from './useFetch.js';
2
+ export { usePageContext } from './usePageContext.js';
3
+ export { useProps } from './useProps.js';
2
4
  export * from 'zuby/hooks/index.js';
@@ -0,0 +1 @@
1
+ export declare function usePageContext(): import("zuby/contexts/pageContext.js").PageContext;
@@ -0,0 +1,5 @@
1
+ import { useContext } from 'react';
2
+ import { pageContext } from '../contexts/pageContext.js';
3
+ export function usePageContext() {
4
+ return useContext(pageContext);
5
+ }
@@ -1 +1 @@
1
- export default function useProps(path: string, priority?: 'low' | 'high' | 'auto'): string | Object;
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 default function useProps(path, priority = 'auto') {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zubyjs/react",
3
- "version": "1.0.65",
3
+ "version": "1.0.67",
4
4
  "description": "Zuby.js JsxProvider for react",
5
5
  "type": "module",
6
6
  "main": "index.js",
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
- children: page,
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' && !context.isInitialPath) {
46
- context.props = useProps(context.url.pathname);
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
  }
@@ -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 }));