@zubyjs/react 1.0.40 → 1.0.42

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zubyjs/react",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "description": "Zuby.js JsxProvider for react",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/router.js CHANGED
@@ -2,8 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Router as WouterRouter, Route as WouterRoute, Switch as WouterSwitch } from 'wouter';
3
3
  export { useRoute, useRouter, useParams, useLocation, Link, Redirect, } from 'wouter';
4
4
  import { useParams } from 'wouter';
5
- import { Suspense, lazy } from 'react';
6
- import { createElement } from 'react';
5
+ import { createElement, Suspense, lazy } from 'react';
7
6
  import { useFetch } from './hooks/index.js';
8
7
  let pages;
9
8
  let apps;
@@ -44,10 +43,10 @@ export default function Router({ context }) {
44
43
  export function Page({ page, context }) {
45
44
  context.statusCode = 200;
46
45
  context.params = useParams();
47
- if (typeof window !== 'undefined') {
46
+ if (typeof window !== 'undefined' && !context.isInitialPath) {
48
47
  context.props = useFetch(`/_props${context.url.pathname}`);
49
48
  }
50
- return _jsx(page.component, { context: context });
49
+ return _jsx(page.component, { ...context.props, context: context });
51
50
  }
52
51
  export function Error({ error, context }) {
53
52
  context.statusCode = 404;
@@ -5,7 +5,9 @@ import { hydrateRoot, createRoot } from 'react-dom/client';
5
5
  import Router from '@zubyjs/react/router.js';
6
6
  import { ZubyPageContext } from 'zuby/pageContext/index.js';
7
7
  if (typeof window !== 'undefined') {
8
- const pageContext = new ZubyPageContext();
8
+ const pageContext = new ZubyPageContext({
9
+ ...(globalThis?.initialPageContext || {}),
10
+ });
9
11
  const appElement = document.getElementById('app');
10
12
  if (appElement.hasChildNodes()) {
11
13
  hydrateRoot(appElement, _jsx(Router, { context: pageContext }));
@@ -1,3 +1,5 @@
1
- export default function InnerLayout({ innerHtml }: {
1
+ import { ZubyPageContext } from 'zuby/pageContext/index.js';
2
+ export default function InnerLayout({ innerHtml, context, }: {
2
3
  innerHtml: string;
4
+ context: ZubyPageContext;
3
5
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,9 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- export default function InnerLayout({ innerHtml }) {
3
- return _jsx("div", { id: "app", dangerouslySetInnerHTML: { __html: innerHtml } });
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ export default function InnerLayout({ innerHtml, context, }) {
3
+ return (_jsxs(_Fragment, { children: [_jsx("div", { id: "app", dangerouslySetInnerHTML: { __html: innerHtml } }), _jsx("script", { type: "text/javascript", dangerouslySetInnerHTML: {
4
+ __html: `globalThis.initialPageContext=${JSON.stringify({
5
+ props: context.props,
6
+ initialPath: context.url.pathname,
7
+ })};`,
8
+ } })] }));
4
9
  }