Skip to content

Regions

DOM ownership

Every node inside an island has one owner, so ogygia repairs only what Svelte's hydration reads and leaves a web component's own nodes alone. This page shows where to put a third-party widget inside an island so nothing fights over it.

On this page

An island’s DOM doesn’t belong to ogygia alone. Svelte binds parts of it when the island wakes. A web component rewrites its own children when it upgrades. A design-system script may strip whitespace while the island sleeps. To keep these from fighting, ogygia gives every node one owner, and everything ogygia does to the DOM starts by asking who owns the node.

This matters when you put a third-party widget inside an island, such as a web component or an embed, or when the devtools Hydration tab reports a conflict. The simplest fix is to mark the widget as yours, and ogygia never touches it:

<div class="map">
  <x-map
   data-ogygia-keep="map"
   lat="48.85"
    lng="2.35"
  ></x-map>
</div>

Owners

OwnerWhat it isWhat ogygia does with it
Svelte’s walkthe parts of the island’s markup Svelte’s hydration binds by positionbefore the wake, puts it back to the server’s shape if another script changed it
Staticmarkup Svelte never reads again: {@html} content, bind:innerHTML, a custom element whose children are staticleaves it alone before the wake; a hole answer or a live update still replaces it
Youan element you marked data-ogygia-keepnever touches it: not before the wake, not on a hole answer, not on a navigation
A web componentchildren and attributes a custom element added itselfkeeps them on a hole answer, a live update and a navigation
Lakewake: 'none' contentthe server’s HTML, lifted out of the way while the island hydrates
Slotchildren the page passes between an island’s tags, rendered in place and adopted by the islandnever repairs it; Svelte adopts it whole

You don’t mark static markup yourself. The compiler finds {@html}, bind:innerHTML and custom elements with static children, and stamps them in the server HTML with data-og-opaque. How ogygia restores the markup Svelte’s walk owns is in Client islands.

Third-party widgets

A widget that rewrites its own children has to sit somewhere Svelte never reads. Any of these works:

  1. Inside {@html}. Svelte takes the content whole and never walks into it.
  2. As a custom element whose children are static. Svelte never walks inside it.
  3. Marked data-ogygia-keep. ogygia never touches it, anywhere.

With {@html}, put the widget inside the HTML string, not as the element that holds it, because Svelte keeps its own markers as the direct children of that element. The {@html} can sit beside other content (<div><h3>{title}</h3>{@html markup}</div>); the elements of that <div> are then compared by position only and never entered. An {@html} at the very top of a component has no element around it, so wrap it in one.

To render a web component on the server so it paints before its JavaScript loads, see Web components.

<script>
  let { title } = $props();
  const markup = `<x-search><form action="/search"><input name="q" /></form></x-search>`;
</script>

<!-- 1. inside {@html} -->
<div class="search">
  <h3>{title}</h3>
  {@html markup}
</div>

<!-- 2. a custom element with static children -->
<x-search
  ><form action="/search"><input name="q" /></form></x-search
>

<!-- 3. marked as yours -->
<x-search data-ogygia-keep="search"
  ><form action="/search"><input name="q" /></form></x-search
>

Conflicts

If a web component changes its children in a place Svelte’s hydration does read, such as a custom element whose children use {expressions} or blocks, both can’t win. Svelte binds nodes by position, so ogygia removes the nodes the component added and lets the island hydrate.

It reports the conflict instead of hiding it. In development you get a console warning (ownership_conflict) and a conflict finding in the devtools Hydration tab, naming the element and the fix: one of the three placements above, or a lake.

<script>
  let { stars } = $props();
</script>

<!-- conflict: Svelte reads {stars} by position, and <x-rating> rewrites its children -->
<x-rating><span>{stars}</span></x-rating>

<!-- fine: the value goes in an attribute, the children stay static -->
<x-rating value={stars}><span>loading</span></x-rating>

data-ogygia-keep

On a plain element, data-ogygia-keep means the live DOM owns this subtree. Before the wake, on a hole answer, on a live update and on a navigation, ogygia matches the element and keeps it exactly as it is. With the SPA router, the same attribute carries layout chrome across navigations; see Keep layout chrome.

The keep import attribute on an island is related but different: the island survives a navigation. Svelte still owns that island, so it is repaired and hydrated like any other. See Client islands.