@contentstack/studio-react-editor 1.4.0 → 1.5.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.
Files changed (58) hide show
  1. package/dist/components/BuildingIllustration.js +8 -0
  2. package/dist/components/BuildingIllustration.js.map +1 -0
  3. package/dist/components/EditableRenderer.js +29 -4
  4. package/dist/components/EditableRenderer.js.map +1 -1
  5. package/dist/components/Element.js +70 -22
  6. package/dist/components/Element.js.map +1 -1
  7. package/dist/components/PreviewRenderer.js +7 -0
  8. package/dist/components/PreviewRenderer.js.map +1 -1
  9. package/dist/components/Slot.js +26 -4
  10. package/dist/components/Slot.js.map +1 -1
  11. package/dist/components/WelcomeState.js +67 -0
  12. package/dist/components/WelcomeState.js.map +1 -0
  13. package/dist/components/elements/ConditionBlock.js +7 -0
  14. package/dist/components/elements/ConditionBlock.js.map +1 -1
  15. package/dist/components/elements/Repeater.js +11 -38
  16. package/dist/components/elements/Repeater.js.map +1 -1
  17. package/dist/components/elements/SectionComposition.js +226 -0
  18. package/dist/components/elements/SectionComposition.js.map +1 -0
  19. package/dist/components/elements/SectionSlot.js +199 -0
  20. package/dist/components/elements/SectionSlot.js.map +1 -0
  21. package/dist/components/elements/Symbol.js +9 -2
  22. package/dist/components/elements/Symbol.js.map +1 -1
  23. package/dist/components/styles.js +72 -0
  24. package/dist/components/styles.js.map +1 -1
  25. package/dist/contexts/providers/edit-context.provider.js +14 -0
  26. package/dist/contexts/providers/edit-context.provider.js.map +1 -0
  27. package/dist/contexts/providers/renderer.provider.js +1 -0
  28. package/dist/contexts/providers/renderer.provider.js.map +1 -1
  29. package/dist/contexts/providers/section-mode.provider.js +15 -0
  30. package/dist/contexts/providers/section-mode.provider.js.map +1 -0
  31. package/dist/contexts/providers/symbol-ui.provider.js +21 -6
  32. package/dist/contexts/providers/symbol-ui.provider.js.map +1 -1
  33. package/dist/hooks/use-active-node-path.hook.js +8 -1
  34. package/dist/hooks/use-active-node-path.hook.js.map +1 -1
  35. package/dist/hooks/use-condition-block-context.js +8 -1
  36. package/dist/hooks/use-condition-block-context.js.map +1 -1
  37. package/dist/hooks/use-design-preview.hook.js +8 -1
  38. package/dist/hooks/use-design-preview.hook.js.map +1 -1
  39. package/dist/hooks/use-edit-context-listener.hook.js +48 -0
  40. package/dist/hooks/use-edit-context-listener.hook.js.map +1 -0
  41. package/dist/hooks/use-preview-mode.hook.js +8 -1
  42. package/dist/hooks/use-preview-mode.hook.js.map +1 -1
  43. package/dist/hooks/use-register-section.hook.js +110 -0
  44. package/dist/hooks/use-register-section.hook.js.map +1 -0
  45. package/dist/hooks/use-renderer.hook.js +8 -1
  46. package/dist/hooks/use-renderer.hook.js.map +1 -1
  47. package/dist/hooks/use-repeater.hook.js +8 -1
  48. package/dist/hooks/use-repeater.hook.js.map +1 -1
  49. package/dist/hooks/use-section-events.hook.js +63 -0
  50. package/dist/hooks/use-section-events.hook.js.map +1 -0
  51. package/dist/hooks/use-should-show-design.hook.js +48 -2
  52. package/dist/hooks/use-should-show-design.hook.js.map +1 -1
  53. package/dist/hooks/use-spec-data-listener.hook.js +402 -12
  54. package/dist/hooks/use-spec-data-listener.hook.js.map +1 -1
  55. package/dist/hooks/use-symbol-events.hook.js +13 -0
  56. package/dist/hooks/use-symbol-events.hook.js.map +1 -1
  57. package/dist/index.d.ts +3 -3
  58. package/package.json +11 -15
@@ -1,14 +1,21 @@
1
1
  import { useContext } from 'react';
2
2
  import '../contexts/providers/renderer.provider.js';
3
+ import '../contexts/providers/edit-context.provider.js';
3
4
  import '../contexts/providers/active-node.provider.js';
4
5
  import 'react/jsx-runtime';
5
6
  import '@contentstack/studio-client';
6
7
  import '@contentstack/studio-messenger';
7
8
  import '@contentstack/studio-react-components/contexts';
8
9
  import 'immer';
10
+ import './use-edit-context-listener.hook.js';
11
+ import '@contentstack/studio-internal';
12
+ import '@contentstack/studio-core';
13
+ import '@contentstack/studio-react-components/basic-components';
9
14
  import '@contentstack/studio-react-components/hooks';
10
- import '@contentstack/studio-registry';
15
+ import 'goober';
11
16
  import '../components/Element.js';
17
+ import '../contexts/providers/section-mode.provider.js';
18
+ import '@contentstack/studio-registry';
12
19
  import '../contexts/providers/use-design-preview.provider.js';
13
20
  import { RepeaterContext } from '../contexts/providers/use-repeater.provider.js';
14
21
  import '../contexts/providers/use-condition-block.provider.js';
@@ -1 +1 @@
1
- {"version":3,"file":"use-repeater.hook.js","sources":["../../src/hooks/use-repeater.hook.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { RepeaterContext } from \"../contexts/providers\";\n\nexport const useRepeaterContext = () => useContext(RepeaterContext);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGO,MAAM,kBAAkB,GAAG,MAAM,UAAU,CAAC,eAAe;;;;"}
1
+ {"version":3,"file":"use-repeater.hook.js","sources":["../../src/hooks/use-repeater.hook.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { RepeaterContext } from \"../contexts/providers\";\n\nexport const useRepeaterContext = () => useContext(RepeaterContext);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGO,MAAM,kBAAkB,GAAG,MAAM,UAAU,CAAC,eAAe;;;;"}
@@ -0,0 +1,63 @@
1
+ import { clientRendererModeUtil, isCompositionBeingEdited } from '@contentstack/studio-client';
2
+ import { composableStudioEventManager, POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger';
3
+ import { useEffect } from 'react';
4
+
5
+ /**
6
+ * React hook that manages section composition events from the Studio.
7
+ * Pulls current sections after mount to avoid losing registrations during initial load,
8
+ * AND re-fetches whenever the spec UI references a section uid that isn't yet
9
+ * known locally (e.g. a section was just dropped in Studio).
10
+ *
11
+ * @param setState - State setter function to update the spec
12
+ * @param state - Current studio spec state
13
+ * @param composableUid - UID of the composition being edited
14
+ */
15
+ const useSectionEvents = (setState, state, composableUid) => {
16
+ // Register the catalog-update listener AS SOON AS the iframe is inside
17
+ // the Studio frame — independent of spec arrival. Studio's
18
+ // `useSectionCompositions` pushes the full catalog the moment its React
19
+ // Query resolves; that push can arrive before the iframe has received
20
+ // its first GET_COMPOSITION_SPEC response and populated `composableUid`,
21
+ // so gating the listener on the latter caused NO_REQUEST_LISTENER_FOUND
22
+ // on every fresh page load.
23
+ useEffect(() => {
24
+ if (!clientRendererModeUtil.isInsideStudioFrame())
25
+ return;
26
+ const catalogListener = composableStudioEventManager?.on(POST_MESSAGE_EVENTS.UPDATE_SECTIONS_CATALOG, (event) => {
27
+ if (!event.data?.sectionCompositions)
28
+ return;
29
+ setState((prevState) => ({
30
+ ...prevState,
31
+ sectionCompositions: event.data.sectionCompositions,
32
+ }));
33
+ });
34
+ return () => {
35
+ catalogListener?.unregister();
36
+ };
37
+ // Register once on mount; the handler reads via setState's prev so it
38
+ // doesn't need state in deps.
39
+ // eslint-disable-next-line react-hooks/exhaustive-deps
40
+ }, []);
41
+ // GET_SECTIONS one-shot fetch — runs after the composition is known so
42
+ // the initial section catalog is populated even when Studio's React
43
+ // Query was already resolved before the iframe mounted (no catalog push
44
+ // is fired in that case).
45
+ useEffect(() => {
46
+ if (!isCompositionBeingEdited(composableUid || ""))
47
+ return;
48
+ composableStudioEventManager
49
+ ?.send(POST_MESSAGE_EVENTS.GET_SECTIONS, {})
50
+ .then((data) => {
51
+ if (!data || !("sectionCompositions" in data))
52
+ return;
53
+ setState((prevState) => ({
54
+ ...prevState,
55
+ sectionCompositions: data.sectionCompositions,
56
+ }));
57
+ })
58
+ .catch(() => { });
59
+ }, [state?.compositionEntry?.uid, composableUid]);
60
+ };
61
+
62
+ export { useSectionEvents };
63
+ //# sourceMappingURL=use-section-events.hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-section-events.hook.js","sources":["../../src/hooks/use-section-events.hook.ts"],"sourcesContent":["import {\n SectionCompositionEntry,\n StudioSpec,\n clientRendererModeUtil,\n isCompositionBeingEdited,\n} from \"@contentstack/studio-client\";\nimport {\n composableStudioEventManager,\n POST_MESSAGE_EVENTS,\n} from \"@contentstack/studio-messenger\";\nimport { useEffect } from \"react\";\n\n/**\n * React hook that manages section composition events from the Studio.\n * Pulls current sections after mount to avoid losing registrations during initial load,\n * AND re-fetches whenever the spec UI references a section uid that isn't yet\n * known locally (e.g. a section was just dropped in Studio).\n *\n * @param setState - State setter function to update the spec\n * @param state - Current studio spec state\n * @param composableUid - UID of the composition being edited\n */\nexport const useSectionEvents = (\n setState: React.Dispatch<React.SetStateAction<StudioSpec>>,\n state?: StudioSpec,\n composableUid?: string,\n) => {\n // Register the catalog-update listener AS SOON AS the iframe is inside\n // the Studio frame — independent of spec arrival. Studio's\n // `useSectionCompositions` pushes the full catalog the moment its React\n // Query resolves; that push can arrive before the iframe has received\n // its first GET_COMPOSITION_SPEC response and populated `composableUid`,\n // so gating the listener on the latter caused NO_REQUEST_LISTENER_FOUND\n // on every fresh page load.\n useEffect(() => {\n if (!clientRendererModeUtil.isInsideStudioFrame()) return;\n const catalogListener = composableStudioEventManager?.on<{\n sectionCompositions: SectionCompositionEntry[];\n }>(POST_MESSAGE_EVENTS.UPDATE_SECTIONS_CATALOG, (event) => {\n if (!event.data?.sectionCompositions) return;\n setState((prevState: StudioSpec) => ({\n ...prevState,\n sectionCompositions: event.data.sectionCompositions,\n }));\n });\n return () => {\n catalogListener?.unregister();\n };\n // Register once on mount; the handler reads via setState's prev so it\n // doesn't need state in deps.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // GET_SECTIONS one-shot fetch — runs after the composition is known so\n // the initial section catalog is populated even when Studio's React\n // Query was already resolved before the iframe mounted (no catalog push\n // is fired in that case).\n useEffect(() => {\n if (!isCompositionBeingEdited(composableUid || \"\")) return;\n composableStudioEventManager\n ?.send<{ sectionCompositions: SectionCompositionEntry[] }>(\n POST_MESSAGE_EVENTS.GET_SECTIONS,\n {},\n )\n .then((data) => {\n if (!data || !(\"sectionCompositions\" in data)) return;\n setState((prevState: StudioSpec) => ({\n ...prevState,\n sectionCompositions: data.sectionCompositions,\n }));\n })\n .catch(() => {});\n }, [state?.compositionEntry?.uid, composableUid]);\n};\n"],"names":[],"mappings":";;;;AAYA;;;;;;;;;AASG;AACI,MAAM,gBAAgB,GAAG,CAC9B,QAA0D,EAC1D,KAAkB,EAClB,aAAsB,KACpB;;;;;;;;IAQF,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,sBAAsB,CAAC,mBAAmB,EAAE;YAAE;AACnD,QAAA,MAAM,eAAe,GAAG,4BAA4B,EAAE,EAAE,CAErD,mBAAmB,CAAC,uBAAuB,EAAE,CAAC,KAAK,KAAI;AACxD,YAAA,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,mBAAmB;gBAAE;AACtC,YAAA,QAAQ,CAAC,CAAC,SAAqB,MAAM;AACnC,gBAAA,GAAG,SAAS;AACZ,gBAAA,mBAAmB,EAAE,KAAK,CAAC,IAAI,CAAC,mBAAmB;AACpD,aAAA,CAAC,CAAC;AACL,QAAA,CAAC,CAAC;AACF,QAAA,OAAO,MAAK;YACV,eAAe,EAAE,UAAU,EAAE;AAC/B,QAAA,CAAC;;;;IAIH,CAAC,EAAE,EAAE,CAAC;;;;;IAMN,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,CAAC,wBAAwB,CAAC,aAAa,IAAI,EAAE,CAAC;YAAE;QACpD;AACE,cAAE,IAAI,CACJ,mBAAmB,CAAC,YAAY,EAChC,EAAE;AAEH,aAAA,IAAI,CAAC,CAAC,IAAI,KAAI;YACb,IAAI,CAAC,IAAI,IAAI,EAAE,qBAAqB,IAAI,IAAI,CAAC;gBAAE;AAC/C,YAAA,QAAQ,CAAC,CAAC,SAAqB,MAAM;AACnC,gBAAA,GAAG,SAAS;gBACZ,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;AAC9C,aAAA,CAAC,CAAC;AACL,QAAA,CAAC;AACA,aAAA,KAAK,CAAC,MAAK,EAAE,CAAC,CAAC;IACpB,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC;AACnD;;;;"}
@@ -1,15 +1,61 @@
1
- import { useConditionBlockContext } from './use-condition-block-context.js';
1
+ import { clientRendererModeUtil } from '@contentstack/studio-client';
2
+ import { useContext } from 'react';
3
+ import '../contexts/providers/renderer.provider.js';
4
+ import '../contexts/providers/edit-context.provider.js';
5
+ import '../contexts/providers/active-node.provider.js';
6
+ import 'react/jsx-runtime';
7
+ import '@contentstack/studio-messenger';
8
+ import '@contentstack/studio-react-components/contexts';
9
+ import 'immer';
10
+ import './use-edit-context-listener.hook.js';
11
+ import '@contentstack/studio-internal';
12
+ import '@contentstack/studio-core';
13
+ import '@contentstack/studio-react-components/basic-components';
14
+ import '@contentstack/studio-react-components/hooks';
15
+ import 'goober';
16
+ import '../components/Element.js';
17
+ import { SectionModeContext } from '../contexts/providers/section-mode.provider.js';
2
18
  import { useDesignPreviewContext } from './use-design-preview.hook.js';
3
19
  import { useRenderer } from './use-renderer.hook.js';
20
+ import '@contentstack/studio-registry';
4
21
  import { useRepeaterContext } from './use-repeater.hook.js';
22
+ import { useConditionBlockContext } from './use-condition-block-context.js';
23
+ import '../contexts/providers/use-design-preview.provider.js';
24
+ import '../contexts/providers/use-repeater.provider.js';
25
+ import '../contexts/providers/use-condition-block.provider.js';
26
+ import '../contexts/providers/preview-mode.provider.js';
5
27
 
6
28
  function useShouldShowDesign(mode) {
7
29
  const { isCompositionBeingEdited } = useRenderer();
8
30
  const { isInsideRepeater } = useRepeaterContext();
9
31
  const { isInsideConditionBlock } = useConditionBlockContext();
10
32
  const designPreviewContext = useDesignPreviewContext();
11
- if (!isCompositionBeingEdited)
33
+ const sectionMode = useContext(SectionModeContext);
34
+ // Treat the Studio editor frame as design-mode-eligible from the very first
35
+ // render — even before `isCompositionBeingEdited` has resolved — to avoid a
36
+ // one-frame preview render that would inject items[0] context. Use
37
+ // `isInsideStudioFrame()` (URL-param-gated) so Visual Builder's iframe
38
+ // (which should render preview) is correctly excluded.
39
+ const isInsideStudio = clientRendererModeUtil.isInsideStudioFrame();
40
+ if (!isCompositionBeingEdited && !isInsideStudio)
41
+ return false;
42
+ // A placed section forces the mode of everything inside it — a single
43
+ // per-placement switch that overrides each inner node's own `mode`. Only set
44
+ // inside a section placement in the editor; null everywhere else.
45
+ // - PREVIEW always wins → render preview.
46
+ // - DESIGN keeps the section's own drop-zones visible, BUT when the section
47
+ // is itself nested inside an enclosing PREVIEW repeater its internal data
48
+ // repeaters must still iterate — otherwise a data-bound slot child can
49
+ // never resolve its per-iteration context (SP7.1: a slot-bearing section
50
+ // defaults to design via COMS-1595, which froze its inner repeaters). So
51
+ // defer to the enclosing preview context in that case. At the page root
52
+ // designPreviewContext is "none", so design is preserved (the slot's own
53
+ // drop-zone-vs-collapsed rendering reads SectionModeContext directly and
54
+ // is unaffected either way).
55
+ if (sectionMode === "preview")
12
56
  return false;
57
+ if (sectionMode === "design")
58
+ return designPreviewContext !== "preview";
13
59
  if (isInsideRepeater || isInsideConditionBlock) {
14
60
  // If composition is being edited and current node(Repeater or Condition Block) inside another repeater or condition block,
15
61
  // and no designPreviewContext is provided, then show design
@@ -1 +1 @@
1
- {"version":3,"file":"use-should-show-design.hook.js","sources":["../../src/hooks/use-should-show-design.hook.ts"],"sourcesContent":["import { useConditionBlockContext } from \"./use-condition-block-context\";\nimport { useDesignPreviewContext } from \"./use-design-preview.hook\";\nimport { useRenderer } from \"./use-renderer.hook\";\nimport { useRepeaterContext } from \"./use-repeater.hook\";\n\nexport function useShouldShowDesign(mode: \"design\" | \"preview\") {\n const { isCompositionBeingEdited } = useRenderer();\n const { isInsideRepeater } = useRepeaterContext();\n const { isInsideConditionBlock } = useConditionBlockContext();\n const designPreviewContext = useDesignPreviewContext();\n if (!isCompositionBeingEdited) return false;\n\n if (isInsideRepeater || isInsideConditionBlock) {\n // If composition is being edited and current node(Repeater or Condition Block) inside another repeater or condition block,\n // and no designPreviewContext is provided, then show design\n if (!designPreviewContext) return true;\n // If designPreviewContext is provided,\n // then show design based on designPreviewContext\n return designPreviewContext === \"design\";\n }\n // if no mode is provided, then show design\n if (!mode) {\n return true;\n }\n // If mode is provided, then show design based on mode\n return mode === \"design\";\n}\n"],"names":[],"mappings":";;;;;AAKM,SAAU,mBAAmB,CAAC,IAA0B,EAAA;AAC5D,IAAA,MAAM,EAAE,wBAAwB,EAAE,GAAG,WAAW,EAAE;AAClD,IAAA,MAAM,EAAE,gBAAgB,EAAE,GAAG,kBAAkB,EAAE;AACjD,IAAA,MAAM,EAAE,sBAAsB,EAAE,GAAG,wBAAwB,EAAE;AAC7D,IAAA,MAAM,oBAAoB,GAAG,uBAAuB,EAAE;AACtD,IAAA,IAAI,CAAC,wBAAwB;AAAE,QAAA,OAAO,KAAK;AAE3C,IAAA,IAAI,gBAAgB,IAAI,sBAAsB,EAAE;;;AAG9C,QAAA,IAAI,CAAC,oBAAoB;AAAE,YAAA,OAAO,IAAI;;;QAGtC,OAAO,oBAAoB,KAAK,QAAQ;IAC1C;;IAEA,IAAI,CAAC,IAAI,EAAE;AACT,QAAA,OAAO,IAAI;IACb;;IAEA,OAAO,IAAI,KAAK,QAAQ;AAC1B;;;;"}
1
+ {"version":3,"file":"use-should-show-design.hook.js","sources":["../../src/hooks/use-should-show-design.hook.ts"],"sourcesContent":["import { clientRendererModeUtil } from \"@contentstack/studio-client\";\nimport { useContext } from \"react\";\nimport { SectionModeContext } from \"../contexts/providers\";\nimport { useConditionBlockContext } from \"./use-condition-block-context\";\nimport { useDesignPreviewContext } from \"./use-design-preview.hook\";\nimport { useRenderer } from \"./use-renderer.hook\";\nimport { useRepeaterContext } from \"./use-repeater.hook\";\n\nexport function useShouldShowDesign(mode: \"design\" | \"preview\") {\n const { isCompositionBeingEdited } = useRenderer();\n const { isInsideRepeater } = useRepeaterContext();\n const { isInsideConditionBlock } = useConditionBlockContext();\n const designPreviewContext = useDesignPreviewContext();\n const sectionMode = useContext(SectionModeContext);\n // Treat the Studio editor frame as design-mode-eligible from the very first\n // render — even before `isCompositionBeingEdited` has resolved — to avoid a\n // one-frame preview render that would inject items[0] context. Use\n // `isInsideStudioFrame()` (URL-param-gated) so Visual Builder's iframe\n // (which should render preview) is correctly excluded.\n const isInsideStudio = clientRendererModeUtil.isInsideStudioFrame();\n if (!isCompositionBeingEdited && !isInsideStudio) return false;\n\n // A placed section forces the mode of everything inside it — a single\n // per-placement switch that overrides each inner node's own `mode`. Only set\n // inside a section placement in the editor; null everywhere else.\n // - PREVIEW always wins → render preview.\n // - DESIGN keeps the section's own drop-zones visible, BUT when the section\n // is itself nested inside an enclosing PREVIEW repeater its internal data\n // repeaters must still iterate — otherwise a data-bound slot child can\n // never resolve its per-iteration context (SP7.1: a slot-bearing section\n // defaults to design via COMS-1595, which froze its inner repeaters). So\n // defer to the enclosing preview context in that case. At the page root\n // designPreviewContext is \"none\", so design is preserved (the slot's own\n // drop-zone-vs-collapsed rendering reads SectionModeContext directly and\n // is unaffected either way).\n if (sectionMode === \"preview\") return false;\n if (sectionMode === \"design\") return designPreviewContext !== \"preview\";\n\n if (isInsideRepeater || isInsideConditionBlock) {\n // If composition is being edited and current node(Repeater or Condition Block) inside another repeater or condition block,\n // and no designPreviewContext is provided, then show design\n if (!designPreviewContext) return true;\n // If designPreviewContext is provided,\n // then show design based on designPreviewContext\n return designPreviewContext === \"design\";\n }\n // if no mode is provided, then show design\n if (!mode) {\n return true;\n }\n // If mode is provided, then show design based on mode\n return mode === \"design\";\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAQM,SAAU,mBAAmB,CAAC,IAA0B,EAAA;AAC5D,IAAA,MAAM,EAAE,wBAAwB,EAAE,GAAG,WAAW,EAAE;AAClD,IAAA,MAAM,EAAE,gBAAgB,EAAE,GAAG,kBAAkB,EAAE;AACjD,IAAA,MAAM,EAAE,sBAAsB,EAAE,GAAG,wBAAwB,EAAE;AAC7D,IAAA,MAAM,oBAAoB,GAAG,uBAAuB,EAAE;AACtD,IAAA,MAAM,WAAW,GAAG,UAAU,CAAC,kBAAkB,CAAC;;;;;;AAMlD,IAAA,MAAM,cAAc,GAAG,sBAAsB,CAAC,mBAAmB,EAAE;AACnE,IAAA,IAAI,CAAC,wBAAwB,IAAI,CAAC,cAAc;AAAE,QAAA,OAAO,KAAK;;;;;;;;;;;;;;IAe9D,IAAI,WAAW,KAAK,SAAS;AAAE,QAAA,OAAO,KAAK;IAC3C,IAAI,WAAW,KAAK,QAAQ;QAAE,OAAO,oBAAoB,KAAK,SAAS;AAEvE,IAAA,IAAI,gBAAgB,IAAI,sBAAsB,EAAE;;;AAG9C,QAAA,IAAI,CAAC,oBAAoB;AAAE,YAAA,OAAO,IAAI;;;QAGtC,OAAO,oBAAoB,KAAK,QAAQ;IAC1C;;IAEA,IAAI,CAAC,IAAI,EAAE;AACT,QAAA,OAAO,IAAI;IACb;;IAEA,OAAO,IAAI,KAAK,QAAQ;AAC1B;;;;"}
@@ -1,7 +1,8 @@
1
- import { isCompositionBeingEdited, applyOperation } from '@contentstack/studio-client';
1
+ import { clientRendererModeUtil, SECTION_COMPOSITIONS_KEY, applyOperation, NODE_TO_PARENT, NODE_TO_PATH_NODE } from '@contentstack/studio-client';
2
2
  import { composableStudioEventManager, POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger';
3
3
  import { DATA_SOURCES_PREFIX } from '@contentstack/studio-registry';
4
- import { useEffect } from 'react';
4
+ import { seedSectionInstanceBindings } from '@contentstack/studio-react-components/utils';
5
+ import { useRef, useEffect } from 'react';
5
6
  import { setAutoFreeze, produce } from 'immer';
6
7
 
7
8
  // NOTE: Immer (produce) automatically freezes the state to prevent mutations.
@@ -10,39 +11,342 @@ import { setAutoFreeze, produce } from 'immer';
10
11
  // Since the state is frozen by default, this throws an error.
11
12
  // To work around this, we disable auto-freezing here.
12
13
  setAutoFreeze(false);
13
- const useSpecDataListener = (setState, state, composableUid) => {
14
+ /**
15
+ * Walk a fresh UI tree (post-Immer-produce) and populate the NODE_TO_PARENT
16
+ * and NODE_TO_PATH_NODE WeakMaps for every node. These maps are normally
17
+ * populated during React render (in Element.tsx). After APPLY_OPERATION
18
+ * produces a brand-new tree via Immer, the maps still hold entries for
19
+ * stale node refs — `findPath` (used to compute hover/highlight paths sent
20
+ * back to Studio) returns stale paths until the next React commit. Calling
21
+ * this immediately after applyOperation closes that window.
22
+ */
23
+ function refreshNodeWeakMaps(root) {
24
+ if (!root || typeof root !== "object")
25
+ return;
26
+ NODE_TO_PARENT.set(root, undefined);
27
+ const visit = (parent) => {
28
+ const slots = parent?.slots || {};
29
+ for (const slotUid of Object.keys(slots)) {
30
+ const children = slots[slotUid] || [];
31
+ for (let idx = 0; idx < children.length; idx++) {
32
+ const child = children[idx];
33
+ if (!child || typeof child !== "object")
34
+ continue;
35
+ NODE_TO_PARENT.set(child, parent);
36
+ NODE_TO_PATH_NODE.set(child, [slotUid, idx]);
37
+ visit(child);
38
+ }
39
+ }
40
+ };
41
+ visit(root);
42
+ }
43
+ const useSpecDataListener = (setState,
44
+ // Read into `stateRef` only — listener bodies use `stateRef.current` (not
45
+ // `state` directly) so the effect's deps don't include `state.data`, which
46
+ // would force re-register on every data change and create a window with
47
+ // zero handlers between unregister/re-register (the original
48
+ // `NO_REQUEST_LISTENER_FOUND` cause).
49
+ state, composableUid) => {
50
+ // Keep a ref to the latest state so the listener registrations don't have
51
+ // to depend on state.data — they can read latest via stateRef.current
52
+ // synchronously. Without this, every state.data change tore down + re-registered
53
+ // the listeners, creating a window where Studio's UPDATE_SECTION_CONTEXTS
54
+ // message was dropped with NO_REQUEST_LISTENER_FOUND.
55
+ const stateRef = useRef(state);
56
+ stateRef.current = state;
57
+ // Rebuild section_scoped_data entries for instances whose binding metadata
58
+ // (selectedField / uidRemapping / parentRepeaterUID) is present in the
59
+ // legacy section_compositions slice. Mirrors build-scoped-data.ts logic
60
+ // inline so the hook can rebuild without re-running the full fetchSpec
61
+ // pipeline. Needed because Studio's fresh per-instance bindings arrive via
62
+ // UPDATE_SPEC_DATA (and UPDATE_SECTION_CONTEXTS), while the provider only
63
+ // reads from section_scoped_data — without this rebuild, sections render
64
+ // the stale pre-computed scope from the initial fetchSpec (selectedField
65
+ // missing from UI metadata on cold load → scoped template = whole page
66
+ // template → placeholder text).
67
+ const rebuildScopedFromBindings = (prevData, incomingBindings) => {
68
+ const dataSources = prevData?.dataSources || {};
69
+ const sectionBindings = incomingBindings && Object.keys(incomingBindings).length
70
+ ? {
71
+ ...(dataSources[SECTION_COMPOSITIONS_KEY] || {}),
72
+ ...incomingBindings,
73
+ }
74
+ : dataSources[SECTION_COMPOSITIONS_KEY] || {};
75
+ const pageTemplate = dataSources.template;
76
+ const prevScoped = prevData?.section_scoped_data || {};
77
+ const nextScoped = { ...prevScoped };
78
+ const getScopedData = (obj, selectedField) => {
79
+ if (!selectedField)
80
+ return obj;
81
+ return (selectedField.split(".").reduce((val, seg) => {
82
+ if (val == null)
83
+ return val;
84
+ const arrayMatch = seg.match(/^(.*?)\[(\d+)\]$/);
85
+ if (arrayMatch) {
86
+ const [, name, idxStr] = arrayMatch;
87
+ const next = name ? val[name] : val;
88
+ return next == null ? next : next[Number(idxStr)];
89
+ }
90
+ // Non-indexed field access landing on an ARRAY → default to the first
91
+ // element so an un-indexed array-ancestor path (e.g.
92
+ // "navigation_menu_3.menu_subitems", where navigation_menu_3 is a
93
+ // multiple group) still resolves instead of `array[field]` →
94
+ // undefined → null. Indexed pushes (`navigation_menu_3[1]…`) override
95
+ // this with the picked instance.
96
+ if (Array.isArray(val)) {
97
+ const first = val[0];
98
+ return first == null ? null : first[seg];
99
+ }
100
+ return val[seg];
101
+ }, obj) ?? null);
102
+ };
103
+ const applyUidRemapping = (scoped, uidRemapping = {}) => {
104
+ if (!scoped ||
105
+ typeof scoped !== "object" ||
106
+ Object.keys(uidRemapping).length === 0) {
107
+ return scoped;
108
+ }
109
+ if (Array.isArray(scoped)) {
110
+ return scoped.map((item) => applyUidRemapping(item, uidRemapping));
111
+ }
112
+ const remapped = {};
113
+ const pageKeyValues = new Set(Object.values(uidRemapping));
114
+ for (const [sectionKey, pageKey] of Object.entries(uidRemapping)) {
115
+ remapped[sectionKey] = applyUidRemapping(scoped[pageKey], uidRemapping);
116
+ }
117
+ for (const key of Object.keys(scoped)) {
118
+ if (!pageKeyValues.has(key) && !(key in uidRemapping)) {
119
+ remapped[key] = applyUidRemapping(scoped[key], uidRemapping);
120
+ }
121
+ }
122
+ return remapped;
123
+ };
124
+ let changed = false;
125
+ for (const [instanceUid, bindingUnknown] of Object.entries(sectionBindings)) {
126
+ const binding = bindingUnknown;
127
+ // Skip context-only legacy shape — no selectedField to re-scope from.
128
+ if (binding && "context" in binding && !("selectedField" in binding)) {
129
+ continue;
130
+ }
131
+ const scopedTemplate = applyUidRemapping(getScopedData(pageTemplate, binding?.selectedField), binding?.uidRemapping);
132
+ let repeater;
133
+ if (binding?.parentRepeaterUID) {
134
+ const ctx = dataSources.repeater?.[binding.parentRepeaterUID];
135
+ if (ctx !== undefined) {
136
+ repeater = { [binding.parentRepeaterUID]: ctx };
137
+ }
138
+ }
139
+ const prev = prevScoped[instanceUid] || {};
140
+ // Refresh contentstack / contentstack_queries from the live page
141
+ // dataSources every time we rebuild. The initial scoped data built
142
+ // during fetchSpec may have stale (or empty) entries because the
143
+ // iframe loaded with getSpecFromParent and never fetched the section's
144
+ // data sources itself — the studio pushes them later via
145
+ // UPDATE_SPEC_DATA. Pool-keyed maps would be ideal but the listener
146
+ // doesn't have access to them; copying the full page slice is a safe
147
+ // superset (same composite-key format the resolver expects).
148
+ const refreshedContentstack = dataSources.contentstack && typeof dataSources.contentstack === "object"
149
+ ? { ...dataSources.contentstack }
150
+ : prev.contentstack || {};
151
+ const refreshedQueries = dataSources.contentstack_queries &&
152
+ typeof dataSources.contentstack_queries === "object"
153
+ ? { ...dataSources.contentstack_queries }
154
+ : prev.contentstack_queries || {};
155
+ const next = {
156
+ ...prev,
157
+ template: scopedTemplate,
158
+ contentstack: refreshedContentstack,
159
+ contentstack_queries: refreshedQueries,
160
+ page: dataSources,
161
+ repeater: repeater ?? prev.repeater,
162
+ // Carry binding metadata so SectionCompositionProvider can re-scope the
163
+ // template from the LIVE per-iteration repeater item. The scopedTemplate
164
+ // above is page-root-scoped and shared across every iteration of this
165
+ // instance, so it can't represent per-iteration values on its own.
166
+ parentRepeaterUID: binding?.parentRepeaterUID ?? null,
167
+ selectedField: binding?.selectedField,
168
+ uidRemapping: binding?.uidRemapping,
169
+ componentPropsFallback: binding?.componentPropsFallback,
170
+ };
171
+ if (prev.template !== next.template ||
172
+ prev.page !== next.page ||
173
+ prev.repeater !== next.repeater ||
174
+ prev.contentstack !== next.contentstack ||
175
+ prev.contentstack_queries !== next.contentstack_queries ||
176
+ prev.componentPropsFallback !== next.componentPropsFallback) {
177
+ nextScoped[instanceUid] = next;
178
+ changed = true;
179
+ }
180
+ }
181
+ if (!changed)
182
+ return prevData;
183
+ return { ...prevData, section_scoped_data: nextScoped };
184
+ };
185
+ // Self-heal when the section catalog arrives after the initial seed.
186
+ // `sectionCompositions` (each section's `linked_schemas` + authored UI) is
187
+ // fetched asynchronously (GET_SECTIONS / UPDATE_SECTIONS_CATALOG) and can land
188
+ // AFTER the first `seedSectionInstanceBindings` run (on GET_COMPOSITION_SPEC).
189
+ // A root section seeded without the catalog gets `selectedField=""` → its
190
+ // scoped template resolves to the whole page (renders the page root, e.g. the
191
+ // page title, instead of its bound field) and stays wedged unless Studio's
192
+ // UPDATE_SECTION_CONTEXTS push wins the race. This is especially visible after
193
+ // a preview-entry switch, which re-navigates the canvas iframe (a fresh cold
194
+ // load). Re-run the seeder — which now heals empty root scopes from the
195
+ // freshly-available `linked_schemas` — and rebuild `section_scoped_data` so the
196
+ // render picks up the corrected scope without depending on the timing of
197
+ // Studio's push. No-op when the seeder heals nothing (`seeded === prev`), so
198
+ // working specs are unaffected and this can't loop.
199
+ useEffect(() => {
200
+ // Editor-only heal — mirror every other effect in this hook, which
201
+ // early-returns outside the Studio frame. No reason to re-seed/commit in a
202
+ // standalone or published render.
203
+ if (!clientRendererModeUtil.isInsideStudioFrame())
204
+ return;
205
+ if (!state?.sectionCompositions?.length)
206
+ return;
207
+ setState((prev) => {
208
+ if (!prev?.ui || !prev?.data)
209
+ return prev;
210
+ const seeded = seedSectionInstanceBindings(prev);
211
+ // Gate the rebuild + commit on the seeder's own no-op signal.
212
+ // `rebuildScopedFromBindings` re-spreads the live `contentstack` /
213
+ // `contentstack_queries` slices on every call, so for a page that has
214
+ // sections it never returns its input unchanged — testing its result
215
+ // would commit a fresh state (extra render + full scoped rebuild) on
216
+ // every `sectionCompositions` ref change (Studio re-pushes the catalog on
217
+ // refetch/refocus), not just when a cold-load scope actually heals.
218
+ if (seeded === prev)
219
+ return prev;
220
+ return { ...seeded, data: rebuildScopedFromBindings(seeded.data) };
221
+ });
222
+ // Re-run whenever EITHER input the root-scope heal depends on lands:
223
+ // • `sectionCompositions` — the section catalog (`linked_schemas`), and
224
+ // • `connected_content_type` — the page CT that selects which linked
225
+ // schema supplies the anchor field.
226
+ // Both arrive asynchronously after a (re)load and in either order; keying on
227
+ // only one leaves a race where the heal runs before the other is present,
228
+ // computes an empty scope, and never retries — re-wedging the section.
229
+ // The setState above changes neither dep, so this can't self-trigger.
230
+ // eslint-disable-next-line react-hooks/exhaustive-deps
231
+ }, [
232
+ state?.sectionCompositions,
233
+ state?.compositionEntry?.connected_content_type,
234
+ ]);
14
235
  // HOOK TO UPDATE THE STATE WITH THE LATEST SPEC DATA
236
+ // Listeners are registered as soon as we're inside the Studio frame, before
237
+ // spec has been fetched. Studio decides when to push UPDATE_SECTION_CONTEXTS
238
+ // and UPDATE_SPEC_DATA based on its own readiness signal; the SDK can't
239
+ // gate on `isCompositionBeingEdited(composableUid)` because that requires the
240
+ // spec — and the parent reaches "ready" before the SDK's setState effect
241
+ // has propagated, producing NO_REQUEST_LISTENER_FOUND.
242
+ // The handlers themselves still defensively check `stateRef.current?.data`
243
+ // before acting, so registering early is safe.
15
244
  useEffect(() => {
16
- if (!isCompositionBeingEdited(composableUid || ""))
245
+ if (!clientRendererModeUtil.isInsideStudioFrame())
17
246
  return;
18
247
  const specDataChangeListener = composableStudioEventManager?.on(POST_MESSAGE_EVENTS.UPDATE_SPEC_DATA, async (event) => {
19
248
  const { data } = event;
20
- if (!data || !state?.data)
249
+ if (!data || !stateRef.current?.data)
21
250
  return;
22
251
  setState((state) => {
23
252
  if (!state)
24
253
  return state;
254
+ // Merge incoming over existing — never replace dataSources
255
+ // wholesale. Studio's UPDATE_SPEC_DATA pushes can carry only
256
+ // a subset of slices (e.g., only `template` + `section_compositions`),
257
+ // and a naive overwrite would wipe slices the SDK relied on
258
+ // (e.g., the `repeater` item context populated earlier from
259
+ // preview data resolution). Result was a visible flicker as
260
+ // sections inside a Repeater suddenly lost their item context.
261
+ // Also merge section_compositions key-by-key so SDK-seeded
262
+ // per-instance bindings survive when Studio's push is partial.
263
+ const incomingSections = data?.dataSources?.[SECTION_COMPOSITIONS_KEY] || {};
264
+ const existingSections = state.data?.dataSources?.[SECTION_COMPOSITIONS_KEY] ||
265
+ {};
266
+ const mergedDataSources = {
267
+ ...(state.data?.dataSources || {}),
268
+ ...(data?.dataSources || {}),
269
+ [SECTION_COMPOSITIONS_KEY]: {
270
+ ...existingSections,
271
+ ...incomingSections,
272
+ },
273
+ };
274
+ const mergedData = {
275
+ ...state.data,
276
+ ...data,
277
+ dataSources: mergedDataSources,
278
+ };
279
+ const rebuilt = rebuildScopedFromBindings(mergedData);
25
280
  return {
26
281
  ...state,
27
- data: data,
282
+ data: rebuilt,
28
283
  };
29
284
  });
30
285
  });
31
286
  const previewEntryChangeListener = composableStudioEventManager?.on(POST_MESSAGE_EVENTS.REPLACE_PREVIEW_ENTRY, async (event) => {
32
287
  const { data } = event;
33
- if (!data?.dataSources || !state?.data)
288
+ if (!data?.dataSources || !stateRef.current?.data)
34
289
  return;
35
290
  setState((prevState) => {
36
291
  if (!prevState)
37
292
  return prevState;
38
- return {
39
- ...prevState,
40
- data: { ...state?.data, [DATA_SOURCES_PREFIX]: data?.dataSources },
293
+ // REPLACE_PREVIEW_ENTRY pushes dataSources for the preview-entry change
294
+ // (typically just `template`/`contentstack` slices). Merge into existing
295
+ // dataSources — don't wipe sibling slices like `repeater` or
296
+ // `section_compositions`, which would cause a flicker for sections
297
+ // inside a Repeater (their item context would disappear).
298
+ const mergedData = {
299
+ ...prevState?.data,
300
+ [DATA_SOURCES_PREFIX]: {
301
+ ...(prevState?.data?.[DATA_SOURCES_PREFIX] || {}),
302
+ ...data?.dataSources,
303
+ },
41
304
  };
305
+ // The merge updates dataSources.template, but each section's SCOPED
306
+ // template in section_scoped_data is derived from it — re-scope here,
307
+ // else a section keeps its stale (often null) scope and renders the
308
+ // empty placeholder after the preview entry is set/switched. (The
309
+ // UPDATE_SPEC_DATA handler already rebuilds; this is the equivalent for
310
+ // the preview-entry change path that EntryPickerBtn sends.)
311
+ const rebuilt = rebuildScopedFromBindings(mergedData);
312
+ return { ...prevState, data: rebuilt };
42
313
  });
43
314
  });
44
315
  const applyOperationListener = composableStudioEventManager?.on(POST_MESSAGE_EVENTS.APPLY_OPERATION, (event) => {
45
316
  const { data } = event;
317
+ // Self-heal section catalog: if any op inserts a section-composition
318
+ // node whose compositionUID isn't in the locally-known catalog
319
+ // (race between Studio's section store hydration and the iframe's
320
+ // initial GET_SECTIONS reply), re-fetch the catalog and merge.
321
+ // Without this the section renders with "Component … is not
322
+ // registered" until the page is saved + reloaded.
323
+ const newSectionUids = new Set();
324
+ for (const op of data?.operations || []) {
325
+ const node = op?.node;
326
+ if (op &&
327
+ op.type === "insert_node" &&
328
+ node &&
329
+ typeof node === "object" &&
330
+ node.type === "section-composition" &&
331
+ typeof node.metadata?.compositionUID === "string") {
332
+ newSectionUids.add(node.metadata.compositionUID);
333
+ }
334
+ }
335
+ const known = new Set((stateRef.current?.sectionCompositions || []).map((s) => s.uid));
336
+ const unknown = [...newSectionUids].filter((u) => !known.has(u));
337
+ if (unknown.length > 0) {
338
+ composableStudioEventManager
339
+ ?.send(POST_MESSAGE_EVENTS.GET_SECTIONS, {})
340
+ .then((resp) => {
341
+ if (!resp?.sectionCompositions)
342
+ return;
343
+ setState((prevState) => ({
344
+ ...prevState,
345
+ sectionCompositions: resp.sectionCompositions,
346
+ }));
347
+ })
348
+ .catch(() => { });
349
+ }
46
350
  setState((prevState) => {
47
351
  if (!prevState?.ui || !data?.operations)
48
352
  return prevState;
@@ -50,15 +354,101 @@ const useSpecDataListener = (setState, state, composableUid) => {
50
354
  const operations = data.operations;
51
355
  return applyOperation(ui, operations);
52
356
  });
53
- return { ...prevState, ui: newUI };
357
+ // Eagerly refresh the NODE_TO_PARENT / NODE_TO_PATH_NODE WeakMaps for
358
+ // the new tree. These WeakMaps are otherwise only populated during
359
+ // React render (Element.tsx) and `findPath` (used by hover/highlight
360
+ // postMessages back to Studio) reads from them. Without this refresh
361
+ // there is a window between APPLY_OPERATION and the next React commit
362
+ // where mouse-move events emit paths derived from old node refs —
363
+ // those paths don't exist in Studio's now-updated slate editor and
364
+ // surface as "Cannot find a descendant at path" errors.
365
+ refreshNodeWeakMaps(newUI);
366
+ // Re-seed per-instance section bindings ONLY when the slate op might
367
+ // have moved/inserted/removed a section-composition node. Property /
368
+ // style / text-content ops can't change the section-instance graph,
369
+ // so the seeder's full UI walk on those is wasted work. The seeder
370
+ // itself is idempotent (it short-circuits when nothing mutated), but
371
+ // skipping the walk altogether keeps interactive ops (typing, style
372
+ // edits) cheap on large pages.
373
+ const ops = data.operations;
374
+ const opAffectsSectionInstances = ops.some((op) => op?.type === "insert_node" ||
375
+ op?.type === "remove_node" ||
376
+ op?.type === "move_node" ||
377
+ op?.type === "merge_node" ||
378
+ op?.type === "split_node");
379
+ if (!opAffectsSectionInstances) {
380
+ return { ...prevState, ui: newUI };
381
+ }
382
+ return seedSectionInstanceBindings({ ...prevState, ui: newUI });
54
383
  });
55
384
  });
385
+ // Studio pushes only the section_compositions slice when section contexts
386
+ // are recomputed (e.g. after a section node is added/moved/removed). We
387
+ // patch just that slice on top of existing dataSources so other data
388
+ // (template, contentstack, query results) isn't clobbered.
389
+ //
390
+ // We ALSO rebuild the matching `section_scoped_data[instanceUid].template`
391
+ // (and repeater slot) using the fresh selectedField / uidRemapping /
392
+ // parentRepeaterUID Studio just sent. Without this, SectionCompositionProvider
393
+ // would keep rendering the stale pre-computed scoped data from fetchSpec
394
+ // (which can be wrong on cold load if the UI node lacked
395
+ // metadata.selectedField), because the provider prefers section_scoped_data
396
+ // and never falls back to the legacy section_compositions slot when it
397
+ // exists.
398
+ const sectionContextsListener = composableStudioEventManager?.on(POST_MESSAGE_EVENTS.UPDATE_SECTION_CONTEXTS, (event) => {
399
+ const { data } = event;
400
+ if (!data?.sectionCompositions)
401
+ return;
402
+ // Merge key-by-key on top of SDK-seeded defaults. Studio only pushes
403
+ // user-driven overrides for specific instance nodes; replacing the whole
404
+ // slice would wipe the SDK's seeded baseline for all other instances.
405
+ setState((prevState) => {
406
+ if (!prevState?.data)
407
+ return prevState;
408
+ const existing = prevState.data?.dataSources?.[SECTION_COMPOSITIONS_KEY] ||
409
+ {};
410
+ const mergedData = {
411
+ ...prevState.data,
412
+ dataSources: {
413
+ ...prevState.data?.dataSources,
414
+ [SECTION_COMPOSITIONS_KEY]: {
415
+ ...existing,
416
+ ...data.sectionCompositions,
417
+ },
418
+ },
419
+ };
420
+ const finalData = rebuildScopedFromBindings(mergedData, data.sectionCompositions);
421
+ return {
422
+ ...prevState,
423
+ data: finalData,
424
+ };
425
+ });
426
+ });
427
+ // Signal to Studio that our editor→iframe post-message listeners are now
428
+ // in the handler map. Studio gates UPDATE_SPEC_DATA (and similar) on this
429
+ // event because earlier readiness signals (SDK_SPEC_RESOLVED, INIT_STUDIO)
430
+ // fire before EditableRenderer commits its first render and race against
431
+ // the .on(...) calls above.
432
+ composableStudioEventManager
433
+ ?.send(POST_MESSAGE_EVENTS.LISTENERS_READY, { composableUid })
434
+ .then(() => { })
435
+ .catch(() => {
436
+ // Studio may not have its LISTENERS_READY handler registered yet on
437
+ // very first paint — the bridge resolves this via its message queue,
438
+ // so a dropped first emit is harmless. Not an error worth surfacing.
439
+ });
56
440
  return () => {
57
441
  applyOperationListener?.unregister();
58
442
  specDataChangeListener?.unregister();
59
443
  previewEntryChangeListener?.unregister();
444
+ sectionContextsListener?.unregister();
60
445
  };
61
- }, [state?.compositionEntry?.uid, state?.data, composableUid]);
446
+ // Deps deliberately exclude state.data — see stateRef above. Re-registering
447
+ // on every data change creates a window where Studio's pushes are dropped
448
+ // with NO_REQUEST_LISTENER_FOUND. We do re-register on composableUid change
449
+ // (e.g. switching to a different composition without unmount); the
450
+ // LISTENERS_READY emit above re-signals Studio after each rebind.
451
+ }, [composableUid]);
62
452
  };
63
453
 
64
454
  export { useSpecDataListener };