@pack/react 0.0.11 → 0.0.13

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/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAqClD,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,4BA8B9C"}
1
+ {"version":3,"file":"render-sections.d.ts","sourceRoot":"","sources":["../src/render-sections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAwClD,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,4BA8B9C"}
@@ -11,6 +11,8 @@ function Sections({ sections }) {
11
11
  // Normalize section data
12
12
  const key = section.id || section.clientId;
13
13
  const data = section.data || section;
14
+ // Attach dataSource to the provided cms data
15
+ data.dataSource = section.dataSource;
14
16
  const schemaKey = data._template;
15
17
  const Component = sectionMap.get(schemaKey);
16
18
  if (!Component)
@@ -1 +1 @@
1
- {"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,mFAM5B,GAAG;;;CAoHL,CAAC"}
1
+ {"version":3,"file":"use-customizer-shell.d.ts","sourceRoot":"","sources":["../src/use-customizer-shell.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,mFAM5B,GAAG;;;CAiIL,CAAC"}
@@ -5,9 +5,16 @@ export const useCustomizerShell = ({ environment = "production", isPreview, sect
5
5
  const [content, setContent] = useState(data.content);
6
6
  const [storefrontSettings, setStorefrontSettings] = useState(null);
7
7
  const [parentConnection, setParentConnection] = useState(null);
8
+ const [shouldConnectToParent, setShouldConnectToParent] = useState(false);
8
9
  const navigate = (path) => {
9
10
  window.location.href = path;
10
11
  };
12
+ useEffect(() => {
13
+ const isIframe = window.self !== window.top;
14
+ if (!isIframe)
15
+ return;
16
+ setShouldConnectToParent(true);
17
+ }, []);
11
18
  useEffect(() => {
12
19
  setLocation(window.location);
13
20
  }, [data.handle]);
@@ -35,12 +42,19 @@ export const useCustomizerShell = ({ environment = "production", isPreview, sect
35
42
  if (!storefrontSettingsSchema || !parentConnection || !sectionComponents) {
36
43
  return [];
37
44
  }
38
- parentConnection.setStorefrontSettingsSchema(JSON.stringify(storefrontSettingsSchema));
45
+ try {
46
+ parentConnection.setStorefrontSettingsSchema(JSON.stringify(storefrontSettingsSchema));
47
+ }
48
+ catch (error) {
49
+ if (error.code !== ErrorCode.ConnectionDestroyed) {
50
+ parentConnection?.displayError("Something went wrong parsing sections");
51
+ }
52
+ }
39
53
  return;
40
54
  // eslint-disable-next-line react-hooks/exhaustive-deps
41
55
  }, [data.handle, parentConnection, storefrontSettingsSchema]);
42
56
  useEffect(() => {
43
- if (!isPreview || !location?.pathname)
57
+ if (!isPreview || !location?.pathname || !shouldConnectToParent)
44
58
  return;
45
59
  const connection = connectToParent({
46
60
  methods: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pack/react",
3
3
  "description": "React",
4
- "version": "0.0.11",
4
+ "version": "0.0.13",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "engines": {
@@ -22,7 +22,6 @@
22
22
  "dist"
23
23
  ],
24
24
  "devDependencies": {
25
- "@shopify/remix-oxygen": "^1.1.3",
26
25
  "@types/react": "^18.2.20",
27
26
  "react": "^18.2.0",
28
27
  "react-dom": "^18.2.0"