@pack/react 4.2.0 → 4.2.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"AAeA,eAAO,MAAM,kBAAkB,YA2R9B,CAAC"}
1
+ {"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"AAeA,eAAO,MAAM,kBAAkB,YAiT9B,CAAC"}
@@ -13,8 +13,8 @@ export const useCustomizerShell = () => {
13
13
  description: liveContent?.description,
14
14
  };
15
15
  const [hasInit, setHasInit] = useState(false);
16
+ const [currentPath, setCurrentPath] = useState(undefined);
16
17
  const pendingMessagesRef = useRef(new Map());
17
- const currentPathRef = useRef(undefined);
18
18
  const parentLocaleIdRef = useRef(null);
19
19
  const sendToParent = useCallback(async (type, data) => {
20
20
  const messageId = crypto.randomUUID();
@@ -179,28 +179,46 @@ export const useCustomizerShell = () => {
179
179
  return;
180
180
  // eslint-disable-next-line react-hooks/exhaustive-deps
181
181
  }, [data.handle, sendToParent, storefrontSettingsSchema]);
182
- // Update the ref whenever pathname changes
182
+ // Track all pathname changes (client-side routing, popstate, hard navs)
183
+ // so SET_CURRENT_ROUTE fires even between pages that both lack CMS content.
183
184
  useEffect(() => {
184
- currentPathRef.current = window.location.pathname;
185
- }, [data.handle]);
185
+ setCurrentPath(window.location.pathname);
186
+ const updatePath = () => setCurrentPath(window.location.pathname);
187
+ // Intercept pushState/replaceState for client-side routing (e.g. React Router)
188
+ const originalPushState = history.pushState.bind(history);
189
+ const originalReplaceState = history.replaceState.bind(history);
190
+ history.pushState = (...args) => {
191
+ originalPushState(...args);
192
+ updatePath();
193
+ };
194
+ history.replaceState = (...args) => {
195
+ originalReplaceState(...args);
196
+ updatePath();
197
+ };
198
+ // Handle back/forward navigation
199
+ window.addEventListener("popstate", updatePath);
200
+ return () => {
201
+ window.removeEventListener("popstate", updatePath);
202
+ history.pushState = originalPushState;
203
+ history.replaceState = originalReplaceState;
204
+ };
205
+ }, []);
186
206
  // Tell the parent window about the current route
187
207
  useEffect(() => {
188
208
  const { template, templateType, handle, title, description } = data;
189
- if (!hasInit ||
190
- !currentPathRef.current ||
191
- (!template && !templateType && !handle && !title && !description)) {
209
+ if (!hasInit || !currentPath) {
192
210
  return;
193
211
  }
194
212
  sendToParent("SET_CURRENT_ROUTE", {
195
213
  environment: environment || "",
196
- currentPath: currentPathRef.current,
197
- template,
198
- templateType,
199
- handle,
200
- title,
201
- description,
214
+ currentPath,
215
+ template: template || null,
216
+ templateType: templateType || null,
217
+ handle: handle || null,
218
+ title: title || null,
219
+ description: description || null,
202
220
  });
203
- }, [hasInit, environment, data.handle, sendToParent]);
221
+ }, [hasInit, environment, currentPath, data.handle, sendToParent]);
204
222
  // Notify parent when locale changes (but not when it came from parent)
205
223
  useEffect(() => {
206
224
  if (!hasInit)
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "4.2.0";
1
+ export const VERSION = "4.2.1";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pack/react",
3
3
  "description": "React",
4
- "version": "4.2.0",
4
+ "version": "4.2.1",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "engines": {