Working with Slotted Content

circle-info

Webflow's implementation of React components appears to be tightly restricted, so that;

  • Code component content can only be

<code-island ...>
  #shadow-root
    ... code-component can only access this SSR ... 
  <div slot="slot">
    ... slotted elements ...
  </div>
</code-island>

Limitations

  • Code components can only access and manipulate the Shadow DOM which is inside the #shadow-root

  • Slots exist outside of that root, which means

    • Slotted elements get the benefit of the website's CSS

    • The Code Component cannot see or manipulate slotted content

Workarounds

Currently, the only workaround we've found it to have the code component generate <script> that is injected into the page scope, which can find and

  • Code component;

    • Generates a unique ID

    • Applies it to the <code-island> ?

Code Component Rendering Limitations regarding Slots

The slot content in Webflow components renders outside the shadow DOM as direct children of the <code-island> element. The React component itself runs inside the shadow DOM and cannot directly access or manipulate the slot content using refs or standard React DOM manipulation.

Considering this HTML:

This <div slot="slot"> exists outside the React component's shadow DOM boundary. The React component can only render a <slot> element that references this content, but cannot directly manipulate it with useRef or query it with standard DOM methods.

The script approach is used because:

  1. It runs in the global scope (outside shadow DOM)

  2. It can access the actual slot content DOM nodes

  3. It can find the specific code-island and manipulate its slot children

Can this be done server-side during SSR before it reaches the browser?

In Webflow's component system, the slot content is assembled by Webflow itself, not by our React component during SSR. By the time our component renders, the slot content structure is already determined by Webflow.

Slot contents aren’t available during SSR

In Webflow Code Components, each slotted child renders in its own Shadow DOM/React root; SSR only renders your component’s shell, then the browser projects the slotted content at hydration. Webflow Developersarrow-up-right

Workable patterns:

  1. Need server-side manipulation → don’t use a slot. Use a prop that serializes content (e.g., Text Node/Rich Text) so your React component receives a ReactNode on the server and you can transform it before returning HTML. Webflow Developersarrow-up-right

Example (SSR-safe transform):

  1. Must keep a slot → manipulate client-side after hydration via the slot API:

assignedElements() only exists in the browser; it won’t run on the server. MDN Web Docsarrow-up-right

  1. If the goal is structural changes to what’s inside the slot, push that logic into the child component you place into the slot, not the parent. Parent/child can’t share React context across slots due to isolation. Webflow Developersarrow-up-right

Summary: SSR cannot “see” or modify slot content; use content props for SSR transformations, or manipulate slotted nodes on the client with assignedElements(). Webflow Developers+2Webflow Developers+2arrow-up-right

Last updated