@ensembleapp/client-sdk 0.0.44 → 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
@@ -26612,9 +26612,16 @@ function renderError(container, message) {
26612
26612
  function WidgetRenderer({ widget, payload, enriched, messageContext, invokeTool }) {
26613
26613
  const containerRef = useRef4(null);
26614
26614
  const rootRef = useRef4(null);
26615
+ const pendingRootUnmountRef = useRef4(null);
26615
26616
  const customerReactDOMRef = useRef4(void 0);
26616
26617
  const isRenderedRef = useRef4(false);
26617
26618
  const isSdk = isSDKWidget(widget);
26619
+ const cancelPendingRootUnmount = () => {
26620
+ if (pendingRootUnmountRef.current) {
26621
+ clearTimeout(pendingRootUnmountRef.current);
26622
+ pendingRootUnmountRef.current = null;
26623
+ }
26624
+ };
26618
26625
  if (!isSdk) {
26619
26626
  customerReactDOMRef.current = widget.reactDOM;
26620
26627
  }
@@ -26623,8 +26630,15 @@ function WidgetRenderer({ widget, payload, enriched, messageContext, invokeTool
26623
26630
  useEffect5(() => {
26624
26631
  return () => {
26625
26632
  if (rootRef.current) {
26626
- rootRef.current.unmount();
26627
- rootRef.current = null;
26633
+ const root2 = rootRef.current;
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);
26628
26642
  } else if (isRenderedRef.current && containerRef.current && customerReactDOMRef.current) {
26629
26643
  if (customerReactDOMRef.current.unmountComponentAtNode) {
26630
26644
  customerReactDOMRef.current.unmountComponentAtNode(containerRef.current);
@@ -26639,6 +26653,7 @@ function WidgetRenderer({ widget, payload, enriched, messageContext, invokeTool
26639
26653
  }, []);
26640
26654
  useEffect5(() => {
26641
26655
  if (isSdk) return;
26656
+ cancelPendingRootUnmount();
26642
26657
  try {
26643
26658
  if (!containerRef.current) {
26644
26659
  console.error(`WidgetRenderer: Container ref is null for widget "${widget.widgetType}"`);