@ensembleapp/client-sdk 0.0.45 → 0.0.46

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.
package/dist/index.js CHANGED
@@ -26609,15 +26609,19 @@ function renderError(container, message) {
26609
26609
  errorDiv.textContent = message;
26610
26610
  container.appendChild(errorDiv);
26611
26611
  }
26612
- function defer(callback) {
26613
- setTimeout(callback, 0);
26614
- }
26615
26612
  function WidgetRenderer({ widget, payload, enriched, messageContext, invokeTool }) {
26616
26613
  const containerRef = useRef4(null);
26617
26614
  const rootRef = useRef4(null);
26615
+ const pendingRootUnmountRef = useRef4(null);
26618
26616
  const customerReactDOMRef = useRef4(void 0);
26619
26617
  const isRenderedRef = useRef4(false);
26620
26618
  const isSdk = isSDKWidget(widget);
26619
+ const cancelPendingRootUnmount = () => {
26620
+ if (pendingRootUnmountRef.current) {
26621
+ clearTimeout(pendingRootUnmountRef.current);
26622
+ pendingRootUnmountRef.current = null;
26623
+ }
26624
+ };
26621
26625
  if (!isSdk) {
26622
26626
  customerReactDOMRef.current = widget.reactDOM;
26623
26627
  }
@@ -26627,13 +26631,17 @@ function WidgetRenderer({ widget, payload, enriched, messageContext, invokeTool
26627
26631
  return () => {
26628
26632
  if (rootRef.current) {
26629
26633
  const root2 = rootRef.current;
26630
- rootRef.current = null;
26631
- defer(() => root2.unmount());
26634
+ cancelPendingRootUnmount();
26635
+ pendingRootUnmountRef.current = setTimeout(() => {
26636
+ root2.unmount();
26637
+ if (rootRef.current === root2) {
26638
+ rootRef.current = null;
26639
+ }
26640
+ pendingRootUnmountRef.current = null;
26641
+ }, 0);
26632
26642
  } else if (isRenderedRef.current && containerRef.current && customerReactDOMRef.current) {
26633
26643
  if (customerReactDOMRef.current.unmountComponentAtNode) {
26634
- const container = containerRef.current;
26635
- const reactDOM = customerReactDOMRef.current;
26636
- defer(() => reactDOM.unmountComponentAtNode?.(container));
26644
+ customerReactDOMRef.current.unmountComponentAtNode(containerRef.current);
26637
26645
  } else {
26638
26646
  console.warn(
26639
26647
  `Widget unmounting but unmountComponentAtNode is missing. This may cause a memory leak.`
@@ -26645,6 +26653,7 @@ function WidgetRenderer({ widget, payload, enriched, messageContext, invokeTool
26645
26653
  }, []);
26646
26654
  useEffect5(() => {
26647
26655
  if (isSdk) return;
26656
+ cancelPendingRootUnmount();
26648
26657
  try {
26649
26658
  if (!containerRef.current) {
26650
26659
  console.error(`WidgetRenderer: Container ref is null for widget "${widget.widgetType}"`);