<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Denner Vidal</title>
    <description>The latest articles on DEV Community by Denner Vidal (@dennervidal).</description>
    <link>https://dev.to/dennervidal</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4196324%2F62f8b719-0804-4371-adae-b80d7dcfebdd.jpg</url>
      <title>DEV Community: Denner Vidal</title>
      <link>https://dev.to/dennervidal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dennervidal"/>
    <language>en</language>
    <item>
      <title>PortalProvider and Shadow DOM</title>
      <dc:creator>Denner Vidal</dc:creator>
      <pubDate>Tue, 20 Oct 2026 15:56:47 +0000</pubDate>
      <link>https://dev.to/dennervidal/portalprovider-and-shadow-dom-3dh5</link>
      <guid>https://dev.to/dennervidal/portalprovider-and-shadow-dom-3dh5</guid>
      <description>&lt;p&gt;Your popup escaped the Shadow DOM. And the obvious fix broke the host page.&lt;/p&gt;

&lt;p&gt;We ship a portal menu as a UMD web component embedded in JSF apps. FloatingPortal-based components (Tooltip, Select, Autocomplete, PhoneInput) render into document.body by default, which is outside the shadow root, so unstyled.&lt;/p&gt;

&lt;p&gt;The workaround was injecting a global stylesheet. Side effect: the whole Tailwind preflight leaked onto the host page and clobbered PrimeFaces and Bootstrap inputs.&lt;/p&gt;

&lt;p&gt;The fix is an optional PortalProvider. Each component takes a &lt;code&gt;root&lt;/code&gt; prop; if omitted it uses the nearest provider's root; with no provider it falls back to document.body. Nothing changes for anyone who doesn't opt in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useResolvedPortalRoot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="nx"&gt;PortalRoot&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;portalRoot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;usePortalRoot&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="c1"&gt;// undefined = herdar do provider; null = opt-out explícito&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;root&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;portalRoot&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The detail that matters most: &lt;code&gt;root={null}&lt;/code&gt; has to mean "ignore the provider". With &lt;code&gt;root ?? portalRoot&lt;/code&gt;, null collapses into the fallback and the escape hatch is gone. So undefined and null behave differently on purpose.&lt;/p&gt;

&lt;p&gt;I left Uploader/Modal out on purpose. They still use createPortal, no consumer asked for it, and the fix pattern is different.&lt;/p&gt;

&lt;p&gt;Have you ever had to decide whether null means "I don't know" or "I don't want it" in a component API?&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
