@zubyjs/react 1.0.41 → 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.41",
3
+ "version": "1.0.42",
4
4
  "description": "Zuby.js JsxProvider for react",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/router.d.ts CHANGED
@@ -7,10 +7,9 @@ import { ZubyPageContext } from 'zuby/pageContext/index.js';
7
7
  export default function Router({ context }: {
8
8
  context: ZubyPageContext;
9
9
  }): import("react/jsx-runtime").JSX.Element;
10
- export declare function Page({ page, context, initialPath, }: {
10
+ export declare function Page({ page, context }: {
11
11
  page: LazyTemplate;
12
12
  context: ZubyPageContext;
13
- initialPath?: boolean;
14
13
  }): import("react/jsx-runtime").JSX.Element;
15
14
  export declare function Error({ error, context }: {
16
15
  error: LazyTemplate;
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, useEffect, useState } 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;
@@ -13,14 +12,6 @@ let errors;
13
12
  */
14
13
  export default function Router({ context }) {
15
14
  const isProduction = import.meta?.env?.MODE === 'production';
16
- const [initialPath, setInitialPath] = useState(true);
17
- useEffect(() => {
18
- const onPathChange = () => setInitialPath(false);
19
- window.addEventListener('popstate', onPathChange);
20
- return () => {
21
- window.removeEventListener('popstate', onPathChange);
22
- };
23
- }, [initialPath, setInitialPath]);
24
15
  const loadTemplates = (templates) => templates?.map((pageTemplate) => ({
25
16
  ...pageTemplate,
26
17
  component: lazy(pageTemplate.component),
@@ -41,7 +32,7 @@ export default function Router({ context }) {
41
32
  return pathRegex.test(context.url.pathname ?? '');
42
33
  });
43
34
  const routes = [
44
- ...pages.map((page) => (_jsx(WouterRoute, { path: page.path, children: _jsx(Page, { context: context, page: page, initialPath: initialPath }) }, page.path))),
35
+ ...pages.map((page) => (_jsx(WouterRoute, { path: page.path, children: _jsx(Page, { context: context, page: page }) }, page.path))),
45
36
  _jsx(WouterRoute, { children: error?.component && _jsx(Error, { context: context, error: error }) }, "error"),
46
37
  ];
47
38
  const page = _jsx(WouterSwitch, { children: routes });
@@ -49,10 +40,10 @@ export default function Router({ context }) {
49
40
  children: page,
50
41
  }) }) }));
51
42
  }
52
- export function Page({ page, context, initialPath, }) {
43
+ export function Page({ page, context }) {
53
44
  context.statusCode = 200;
54
45
  context.params = useParams();
55
- if (typeof window !== 'undefined' && !initialPath) {
46
+ if (typeof window !== 'undefined' && !context.isInitialPath) {
56
47
  context.props = useFetch(`/_props${context.url.pathname}`);
57
48
  }
58
49
  return _jsx(page.component, { ...context.props, context: context });
@@ -6,7 +6,7 @@ import Router from '@zubyjs/react/router.js';
6
6
  import { ZubyPageContext } from 'zuby/pageContext/index.js';
7
7
  if (typeof window !== 'undefined') {
8
8
  const pageContext = new ZubyPageContext({
9
- props: global._props,
9
+ ...(globalThis?.initialPageContext || {}),
10
10
  });
11
11
  const appElement = document.getElementById('app');
12
12
  if (appElement.hasChildNodes()) {
@@ -1,6 +1,9 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  export default function InnerLayout({ innerHtml, context, }) {
3
3
  return (_jsxs(_Fragment, { children: [_jsx("div", { id: "app", dangerouslySetInnerHTML: { __html: innerHtml } }), _jsx("script", { type: "text/javascript", dangerouslySetInnerHTML: {
4
- __html: `global._props=${JSON.stringify(context.props)};`,
4
+ __html: `globalThis.initialPageContext=${JSON.stringify({
5
+ props: context.props,
6
+ initialPath: context.url.pathname,
7
+ })};`,
5
8
  } })] }));
6
9
  }