@pack/react 4.3.3 → 4.3.4

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":"render-sections.d.ts","sourceRoot":"","sources":["../../src/pack/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAgD,MAAM,OAAO,CAAC;AAMrE,UAAU,kBAAkB;IAC1B,sDAAsD;IACtD,OAAO,EAAE,GAAG,CAAC;CACd;AAuCD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,EAAE,OAAO,EAAE,EAAE,kBAAkB,4BAG5D;AAGD,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,GAAG,EAAE,uCAYnD;AAUD,UAAU,mBAAmB;IAC3B,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AA8BD,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,4BAKxD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,mBAAmB,uCAOrD"}
1
+ {"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../../src/pack/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwD,MAAM,OAAO,CAAC;AAM7E,UAAU,kBAAkB;IAC1B,sDAAsD;IACtD,OAAO,EAAE,GAAG,CAAC;CACd;AAuCD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,EAAE,OAAO,EAAE,EAAE,kBAAkB,4BAG5D;AAGD,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,GAAG,EAAE,uCAYnD;AAUD,UAAU,mBAAmB;IAC3B,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAkED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,4BAKxD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,mBAAmB,uCAOrD"}
@@ -1,4 +1,4 @@
1
- import React, { useMemo, useEffect } from "react";
1
+ import React, { useMemo, useEffect, useRef } from "react";
2
2
  import { usePackContext } from "./pack-context";
3
3
  import { sectionMap } from "../register-section";
4
4
  import { generateSectionStylesheet } from "../lib/style-utils";
@@ -57,12 +57,43 @@ function Sections({ sections }) {
57
57
  }
58
58
  function useRenderSections({ content }) {
59
59
  const { isPreview, liveContent, setLiveContent } = usePackContext();
60
- // Update content in context for preview mode
60
+ // The loader `content` object we last pushed into liveContent. While
61
+ // liveContent is still that object, nothing has been received from the
62
+ // customizer for this page, so keep following loader data (navigation and
63
+ // ordinary preview links stay fresh). Once the customizer replaces it via
64
+ // SET_PAGE_DATA, a loader update for the *same page* must not win: any
65
+ // React Router action (e.g. a fetcher POST) revalidates every loader and
66
+ // hands us a fresh `content` object holding the persisted page, which used
67
+ // to silently overwrite unsaved customizer changes — a just-shown section
68
+ // rendered for a beat, then vanished.
69
+ //
70
+ // "Same page" is the handle (localized variants share a handle but not an
71
+ // id, see ff67a5a) plus the pathname the customizer payload arrived on.
72
+ // Handles are only unique per content type, so a client-side navigation
73
+ // from /products/hats to /collections/hats changes the pathname and hands
74
+ // ownership back to loader data instead of pinning the stale product page.
75
+ const syncedLoaderContentRef = useRef(null);
76
+ const customizerContentRef = useRef(null);
77
+ const customizerPathnameRef = useRef(null);
61
78
  useEffect(() => {
62
- if (isPreview && setLiveContent) {
63
- setLiveContent(content);
79
+ if (!isPreview || !setLiveContent)
80
+ return;
81
+ if (liveContent === content)
82
+ return;
83
+ const pathname = typeof window === "undefined" ? null : window.location.pathname;
84
+ const fromCustomizer = !!liveContent && liveContent !== syncedLoaderContentRef.current;
85
+ if (fromCustomizer && liveContent !== customizerContentRef.current) {
86
+ customizerContentRef.current = liveContent;
87
+ customizerPathnameRef.current = pathname;
64
88
  }
65
- }, [content, isPreview, setLiveContent]);
89
+ const customizerOwnsPage = fromCustomizer &&
90
+ liveContent?.handle === content?.handle &&
91
+ customizerPathnameRef.current === pathname;
92
+ if (customizerOwnsPage)
93
+ return;
94
+ syncedLoaderContentRef.current = content;
95
+ setLiveContent(content);
96
+ }, [content, isPreview, liveContent, setLiveContent]);
66
97
  // Smart content selection: prefer current content when it changes (navigation),
67
98
  // but allow liveContent to take precedence when it's updated by customizer
68
99
  const contentToRender = useMemo(() => {
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "4.3.3";
1
+ export const VERSION = "4.3.4";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pack/react",
3
3
  "description": "React",
4
- "version": "4.3.3",
4
+ "version": "4.3.4",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "engines": {