@etsoo/toolpad 1.0.35 → 1.0.37

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.
@@ -58,18 +58,13 @@ const PageContentHeader = (0, styles_1.styled)("div")(({ theme }) => ({
58
58
  justifyContent: "space-between",
59
59
  gap: theme.spacing(2)
60
60
  }));
61
+ function jsonSerialize(obj) {
62
+ return JSON.stringify(obj, (_key, value) => value == null ? undefined : value);
63
+ }
61
64
  exports.PageDataContext = React.createContext({ state: {}, dispatch: (value) => value });
62
65
  function reducer(state, action) {
63
66
  // Check if the action is the same as the current state
64
- let key;
65
- let isSame = true;
66
- for (key in action) {
67
- if (action[key] != state[key]) {
68
- isSame = false;
69
- break;
70
- }
71
- }
72
- if (isSame) {
67
+ if (jsonSerialize(state) === jsonSerialize(action)) {
73
68
  return state;
74
69
  }
75
70
  return { ...state, ...action };
@@ -101,13 +96,7 @@ function PageContainerBar(props) {
101
96
  const breadcrumbs = [...(state.breadcrumbs ?? activePage?.breadcrumbs ?? [])];
102
97
  const title = state.title ?? activePage?.title ?? "";
103
98
  const pageHeader = state.pageHeader ?? activePage?.pageHeader ?? null;
104
- React.useEffect(() => {
105
- // Reset the state
106
- state.breadcrumbs = undefined;
107
- state.page = undefined;
108
- state.pageHeader = undefined;
109
- state.title = undefined;
110
- }, [activePage?.sourcePath]);
99
+ console.log("PageContainerBar", activePage?.sourcePath, title, state);
111
100
  // No page header
112
101
  if (pageHeader === false)
113
102
  return undefined;
@@ -17,18 +17,13 @@ const PageContentHeader = styled("div")(({ theme }) => ({
17
17
  justifyContent: "space-between",
18
18
  gap: theme.spacing(2)
19
19
  }));
20
+ function jsonSerialize(obj) {
21
+ return JSON.stringify(obj, (_key, value) => value == null ? undefined : value);
22
+ }
20
23
  export const PageDataContext = React.createContext({ state: {}, dispatch: (value) => value });
21
24
  function reducer(state, action) {
22
25
  // Check if the action is the same as the current state
23
- let key;
24
- let isSame = true;
25
- for (key in action) {
26
- if (action[key] != state[key]) {
27
- isSame = false;
28
- break;
29
- }
30
- }
31
- if (isSame) {
26
+ if (jsonSerialize(state) === jsonSerialize(action)) {
32
27
  return state;
33
28
  }
34
29
  return { ...state, ...action };
@@ -60,13 +55,7 @@ function PageContainerBar(props) {
60
55
  const breadcrumbs = [...(state.breadcrumbs ?? activePage?.breadcrumbs ?? [])];
61
56
  const title = state.title ?? activePage?.title ?? "";
62
57
  const pageHeader = state.pageHeader ?? activePage?.pageHeader ?? null;
63
- React.useEffect(() => {
64
- // Reset the state
65
- state.breadcrumbs = undefined;
66
- state.page = undefined;
67
- state.pageHeader = undefined;
68
- state.title = undefined;
69
- }, [activePage?.sourcePath]);
58
+ console.log("PageContainerBar", activePage?.sourcePath, title, state);
70
59
  // No page header
71
60
  if (pageHeader === false)
72
61
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/toolpad",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "author": "ETSOO",
5
5
  "description": "Dashboard framework extention based on Toolpad Core",
6
6
  "main": "build/cjs/index.js",
@@ -63,7 +63,7 @@
63
63
  "@testing-library/jest-dom": "^6.6.3",
64
64
  "@testing-library/react": "^16.3.0",
65
65
  "@types/invariant": "2.2.37",
66
- "@types/node": "^22.15.3",
66
+ "@types/node": "^22.15.8",
67
67
  "@types/react": "19.1.2",
68
68
  "@types/react-dom": "19.1.3",
69
69
  "@vitejs/plugin-react": "4.4.1",
@@ -53,6 +53,12 @@ export type PageData = {
53
53
 
54
54
  type PageDataAction = PageData;
55
55
 
56
+ function jsonSerialize(obj: unknown) {
57
+ return JSON.stringify(obj, (_key, value) =>
58
+ value == null ? undefined : value
59
+ );
60
+ }
61
+
56
62
  export const PageDataContext = React.createContext<{
57
63
  state: PageData;
58
64
  dispatch: React.Dispatch<PageDataAction>;
@@ -60,16 +66,7 @@ export const PageDataContext = React.createContext<{
60
66
 
61
67
  function reducer(state: PageData, action: PageDataAction) {
62
68
  // Check if the action is the same as the current state
63
- let key: keyof PageDataAction;
64
- let isSame = true;
65
- for (key in action) {
66
- if (action[key] != state[key]) {
67
- isSame = false;
68
- break;
69
- }
70
- }
71
-
72
- if (isSame) {
69
+ if (jsonSerialize(state) === jsonSerialize(action)) {
73
70
  return state;
74
71
  }
75
72
 
@@ -130,13 +127,7 @@ function PageContainerBar(props: PageContainerBarProps) {
130
127
  const title = state.title ?? activePage?.title ?? "";
131
128
  const pageHeader = state.pageHeader ?? activePage?.pageHeader ?? null;
132
129
 
133
- React.useEffect(() => {
134
- // Reset the state
135
- state.breadcrumbs = undefined;
136
- state.page = undefined;
137
- state.pageHeader = undefined;
138
- state.title = undefined;
139
- }, [activePage?.sourcePath]);
130
+ console.log("PageContainerBar", activePage?.sourcePath, title, state);
140
131
 
141
132
  // No page header
142
133
  if (pageHeader === false) return undefined;