@pack/react 0.0.8 → 0.0.9

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,5 +1,5 @@
1
1
  import { useCallback, useEffect, useState } from "react";
2
- import { connectToParent } from "penpal";
2
+ import { connectToParent, ErrorCode } from "penpal";
3
3
  export const useCustomizerShell = ({ environment = "production", isPreview, sectionComponents, data = {}, storefrontSettingsSchema, }) => {
4
4
  const [location, setLocation] = useState();
5
5
  const [content, setContent] = useState(data.content);
@@ -10,7 +10,7 @@ export const useCustomizerShell = ({ environment = "production", isPreview, sect
10
10
  };
11
11
  useEffect(() => {
12
12
  setLocation(window.location);
13
- }, []);
13
+ }, [data.handle]);
14
14
  const refreshSections = useCallback(() => {
15
15
  if (!sectionComponents || !parentConnection)
16
16
  return [];
@@ -22,13 +22,15 @@ export const useCustomizerShell = ({ environment = "production", isPreview, sect
22
22
  })
23
23
  .filter(Boolean);
24
24
  try {
25
- parentConnection.setSectionsSchemas(JSON.stringify(sectionSchemas));
25
+ parentConnection?.setSectionsSchemas(JSON.stringify(sectionSchemas));
26
26
  }
27
27
  catch (error) {
28
- parentConnection.displayError("Something went wrong parsing sections");
28
+ if (error.code !== ErrorCode.ConnectionDestroyed) {
29
+ parentConnection?.displayError("Something went wrong parsing sections");
30
+ }
29
31
  }
30
32
  return;
31
- }, [data, parentConnection, sectionComponents]);
33
+ }, [data.handle, parentConnection, sectionComponents]);
32
34
  const refreshStorefrontSettingsSchema = useCallback(() => {
33
35
  if (!storefrontSettingsSchema || !parentConnection || !sectionComponents) {
34
36
  return [];
@@ -36,9 +38,9 @@ export const useCustomizerShell = ({ environment = "production", isPreview, sect
36
38
  parentConnection.setStorefrontSettingsSchema(JSON.stringify(storefrontSettingsSchema));
37
39
  return;
38
40
  // eslint-disable-next-line react-hooks/exhaustive-deps
39
- }, [data, parentConnection, storefrontSettingsSchema]);
41
+ }, [data.handle, parentConnection, storefrontSettingsSchema]);
40
42
  useEffect(() => {
41
- if (!isPreview || !location)
43
+ if (!isPreview || !location?.pathname)
42
44
  return;
43
45
  const connection = connectToParent({
44
46
  methods: {
@@ -72,17 +74,15 @@ export const useCustomizerShell = ({ environment = "production", isPreview, sect
72
74
  });
73
75
  setParentConnection(parent);
74
76
  });
75
- return () => {
76
- connection.destroy();
77
- };
78
- }, [location]);
77
+ return () => connection.destroy();
78
+ }, [location?.pathname]);
79
79
  useEffect(() => {
80
80
  if (!isPreview)
81
81
  return;
82
82
  refreshSections();
83
83
  refreshStorefrontSettingsSchema();
84
84
  }, [
85
- data,
85
+ data.handle,
86
86
  isPreview,
87
87
  refreshSections,
88
88
  refreshStorefrontSettingsSchema,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pack/react",
3
3
  "description": "React",
4
- "version": "0.0.8",
4
+ "version": "0.0.9",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "engines": {