<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Sketch widget in Expand breaks React DOM lifecycle (ArcGIS JS API + React) in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketch-widget-in-expand-breaks-react-dom-lifecycle/m-p/1681259#M88106</link>
    <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I am working with &lt;STRONG&gt;ArcGIS API for JavaScript 4.34&lt;/STRONG&gt; in a &lt;STRONG&gt;React + Vite (TypeScript)&lt;/STRONG&gt; project.&lt;/P&gt;&lt;P&gt;I was able without any issue to:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;initialize a MapView,&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;add a GraphicsLayer,&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;display the &lt;STRONG&gt;Sketch widget&lt;/STRONG&gt; directly on the map.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;In order to better manage screen space, I then tried to &lt;STRONG&gt;place the Sketch widget inside an Expand widget&lt;/STRONG&gt;.&lt;BR /&gt;This is where the difficulties started.&lt;/P&gt;&lt;HR /&gt;&lt;H3&gt;Issue encountered&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Most of the time, the Expand appears &lt;STRONG&gt;empty&lt;/STRONG&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;After several attempts, I managed to &lt;STRONG&gt;make the Sketch widget appear inside the Expand&lt;/STRONG&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;However, this then leads to &lt;STRONG&gt;DOM-related errors on the React side&lt;/STRONG&gt;, such as:&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Uncaught NotFoundError: Failed to execute 'insertBefore' on 'Node':
The node before which the new node is to be inserted is not a child of this node.&lt;/LI-CODE&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;or:&lt;/FONT&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Uncaught DOMException: Node.insertBefore: Child to insert before is not a child of this node
React 32
performWorkUntilDeadline scheduler.development.js:45
react-dom_client.js:9714:50&lt;/LI-CODE&gt;&lt;P&gt;These errors usually occur:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;after a React re-render,&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;or during the mount / unmount lifecycle of the Sketch widget,&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;even though the widget initially appears to work correctly inside the Expand.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H3&gt;Technical context&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;React 19.0.0&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Vite 7.3.0&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;TypeScript&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;ArcGIS JS API 4.34&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Usage of useEffect, useRef&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Sketch widget instantiated using the container property&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;It seems I am facing a &lt;STRONG&gt;conflict between ArcGIS’ imperative DOM management and React’s virtual DOM&lt;/STRONG&gt;, especially when the widget is hosted inside an Expand.&lt;/P&gt;&lt;H3&gt;Question&lt;/H3&gt;&lt;P&gt;Is there:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;an &lt;STRONG&gt;officially recommended Esri pattern&lt;/STRONG&gt; to properly integrate the Sketch widget inside an Expand in a React environment?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;a known limitation or documented constraint regarding Expand + React?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;a best practice to avoid these insertBefore errors in this specific scenario?&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Here is the relevant code:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Widget Sketch
useEffect(() =&amp;gt; {
  const view = viewRef.current;
  const panel = stylerPanelRef.current;
  const layer = sketchLayerRef.current;

  if (!view || !panel || !layer) return;

  // créer le container Sketch
  const sketchContainer = document.createElement("div");
  sketchContainer.className =
    "w-full h-auto border border-slate-300 dark:border-slate-700 rounded-md mb-2";

  // point d’ancrage STABLE géré par React (le bouton)
  const clearButton = panel.querySelector("button");

  if (clearButton &amp;amp;&amp;amp; clearButton.parentNode === panel) {
    // solution StackOverflow : insertBefore(parent, nextSibling)
    panel.insertBefore(sketchContainer, clearButton);
  } else {
    // fallback ultra-sécurisé
    panel.appendChild(sketchContainer);
  }

  // init Sketch
  const sketch = new Sketch({
    view,
    layer,
    container: sketchContainer,
    creationMode: "single",
    visibleElements: {
      createTools: {
        point: false,
        polyline: true,
        polygon: true,
        rectangle: true,
        circle: true,
      },
      selectionTools: {
        "lasso-selection": true,
        "rectangle-selection": true,
      },
      settingsMenu: true,
    },
  });

  const createHandle = sketch.on("create", (event) =&amp;gt; {
    if (event.state === "complete" &amp;amp;&amp;amp; event.graphic?.geometry) {
      selectBySketchGeometry(event.graphic.geometry);
    }
  });

  sketchWidgetRef.current = sketch;

  return () =&amp;gt; {
    createHandle.remove();
    sketch.destroy();
    sketchWidgetRef.current = null;

    // nettoyage DOM sécurisé
    if (panel.contains(sketchContainer)) {
      panel.removeChild(sketchContainer);
    }
  };
}, [selectBySketchGeometry]);&lt;/LI-CODE&gt;&lt;P&gt;JSX:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;      {/* Styler Panel (utilisé par le widget Expand ArcGIS) */}
     
      &amp;lt;div ref={stylerPanelRef} className="p-3 space-y-2 text-sm bg-white dark:bg-slate-800 h-auto"&amp;gt;
        &amp;lt;h3 className="font-bold text-slate-700 dark:text-slate-200"&amp;gt;Sketch Styler&amp;lt;/h3&amp;gt;
        {/* Le conteneur Sketch est ajouté dynamiquement via JavaScript */}
        &amp;lt;button
          type="button"
          className="px-3 py-1.5 text-sm font-medium text-white transition-colors bg-blue-600 rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-slate-800"
          onClick={() =&amp;gt; sketchLayerRef.current?.removeAll()}
        &amp;gt;
          Clear Sketches
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;Thank you in advance for your help and feedback.&lt;/P&gt;</description>
    <pubDate>Sat, 31 Jan 2026 01:35:07 GMT</pubDate>
    <dc:creator>Med-Karim-Rouissi</dc:creator>
    <dc:date>2026-01-31T01:35:07Z</dc:date>
    <item>
      <title>Sketch widget in Expand breaks React DOM lifecycle (ArcGIS JS API + React)</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketch-widget-in-expand-breaks-react-dom-lifecycle/m-p/1681259#M88106</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I am working with &lt;STRONG&gt;ArcGIS API for JavaScript 4.34&lt;/STRONG&gt; in a &lt;STRONG&gt;React + Vite (TypeScript)&lt;/STRONG&gt; project.&lt;/P&gt;&lt;P&gt;I was able without any issue to:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;initialize a MapView,&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;add a GraphicsLayer,&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;display the &lt;STRONG&gt;Sketch widget&lt;/STRONG&gt; directly on the map.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;In order to better manage screen space, I then tried to &lt;STRONG&gt;place the Sketch widget inside an Expand widget&lt;/STRONG&gt;.&lt;BR /&gt;This is where the difficulties started.&lt;/P&gt;&lt;HR /&gt;&lt;H3&gt;Issue encountered&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Most of the time, the Expand appears &lt;STRONG&gt;empty&lt;/STRONG&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;After several attempts, I managed to &lt;STRONG&gt;make the Sketch widget appear inside the Expand&lt;/STRONG&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;However, this then leads to &lt;STRONG&gt;DOM-related errors on the React side&lt;/STRONG&gt;, such as:&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Uncaught NotFoundError: Failed to execute 'insertBefore' on 'Node':
The node before which the new node is to be inserted is not a child of this node.&lt;/LI-CODE&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;or:&lt;/FONT&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Uncaught DOMException: Node.insertBefore: Child to insert before is not a child of this node
React 32
performWorkUntilDeadline scheduler.development.js:45
react-dom_client.js:9714:50&lt;/LI-CODE&gt;&lt;P&gt;These errors usually occur:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;after a React re-render,&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;or during the mount / unmount lifecycle of the Sketch widget,&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;even though the widget initially appears to work correctly inside the Expand.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H3&gt;Technical context&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;React 19.0.0&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Vite 7.3.0&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;TypeScript&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;ArcGIS JS API 4.34&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Usage of useEffect, useRef&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Sketch widget instantiated using the container property&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;It seems I am facing a &lt;STRONG&gt;conflict between ArcGIS’ imperative DOM management and React’s virtual DOM&lt;/STRONG&gt;, especially when the widget is hosted inside an Expand.&lt;/P&gt;&lt;H3&gt;Question&lt;/H3&gt;&lt;P&gt;Is there:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;an &lt;STRONG&gt;officially recommended Esri pattern&lt;/STRONG&gt; to properly integrate the Sketch widget inside an Expand in a React environment?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;a known limitation or documented constraint regarding Expand + React?&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;a best practice to avoid these insertBefore errors in this specific scenario?&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Here is the relevant code:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Widget Sketch
useEffect(() =&amp;gt; {
  const view = viewRef.current;
  const panel = stylerPanelRef.current;
  const layer = sketchLayerRef.current;

  if (!view || !panel || !layer) return;

  // créer le container Sketch
  const sketchContainer = document.createElement("div");
  sketchContainer.className =
    "w-full h-auto border border-slate-300 dark:border-slate-700 rounded-md mb-2";

  // point d’ancrage STABLE géré par React (le bouton)
  const clearButton = panel.querySelector("button");

  if (clearButton &amp;amp;&amp;amp; clearButton.parentNode === panel) {
    // solution StackOverflow : insertBefore(parent, nextSibling)
    panel.insertBefore(sketchContainer, clearButton);
  } else {
    // fallback ultra-sécurisé
    panel.appendChild(sketchContainer);
  }

  // init Sketch
  const sketch = new Sketch({
    view,
    layer,
    container: sketchContainer,
    creationMode: "single",
    visibleElements: {
      createTools: {
        point: false,
        polyline: true,
        polygon: true,
        rectangle: true,
        circle: true,
      },
      selectionTools: {
        "lasso-selection": true,
        "rectangle-selection": true,
      },
      settingsMenu: true,
    },
  });

  const createHandle = sketch.on("create", (event) =&amp;gt; {
    if (event.state === "complete" &amp;amp;&amp;amp; event.graphic?.geometry) {
      selectBySketchGeometry(event.graphic.geometry);
    }
  });

  sketchWidgetRef.current = sketch;

  return () =&amp;gt; {
    createHandle.remove();
    sketch.destroy();
    sketchWidgetRef.current = null;

    // nettoyage DOM sécurisé
    if (panel.contains(sketchContainer)) {
      panel.removeChild(sketchContainer);
    }
  };
}, [selectBySketchGeometry]);&lt;/LI-CODE&gt;&lt;P&gt;JSX:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;      {/* Styler Panel (utilisé par le widget Expand ArcGIS) */}
     
      &amp;lt;div ref={stylerPanelRef} className="p-3 space-y-2 text-sm bg-white dark:bg-slate-800 h-auto"&amp;gt;
        &amp;lt;h3 className="font-bold text-slate-700 dark:text-slate-200"&amp;gt;Sketch Styler&amp;lt;/h3&amp;gt;
        {/* Le conteneur Sketch est ajouté dynamiquement via JavaScript */}
        &amp;lt;button
          type="button"
          className="px-3 py-1.5 text-sm font-medium text-white transition-colors bg-blue-600 rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-slate-800"
          onClick={() =&amp;gt; sketchLayerRef.current?.removeAll()}
        &amp;gt;
          Clear Sketches
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;Thank you in advance for your help and feedback.&lt;/P&gt;</description>
      <pubDate>Sat, 31 Jan 2026 01:35:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/sketch-widget-in-expand-breaks-react-dom-lifecycle/m-p/1681259#M88106</guid>
      <dc:creator>Med-Karim-Rouissi</dc:creator>
      <dc:date>2026-01-31T01:35:07Z</dc:date>
    </item>
  </channel>
</rss>

