Skip to content

Commit 06b7b57

Browse files
committed
fix: prevent hydration error for overlays in elements not allowing <div> children
Replaces the container `<div>` with a custom element which is similar to svelte changing to the `svelte-css-wrapper` (sveltejs/svelte#13499) custom element when injecting component style props.
1 parent 5015bd0 commit 06b7b57

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

src/lib/internal/Overlay.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
const { getTranslation } = getInternalFluentContext();
2323
2424
const applyTranslation: Action<
25-
HTMLDivElement,
25+
HTMLElement,
2626
{ translation: Translation; templateNode?: HTMLTemplateElement }
2727
> = (node, { translation, templateNode }) => {
2828
const observer = new MutationObserver(() => updateContent(translation, templateNode));
@@ -72,7 +72,7 @@
7272
<template bind:this={templateElem}>{@render children?.()}</template>
7373
</svelte:head>
7474

75-
<div
75+
<svelte-fluent-overlay
7676
style:display="contents"
7777
use:applyTranslation={{ translation: getTranslation(id, args, true), templateNode: templateElem }}
78-
></div>
78+
></svelte-fluent-overlay>

src/lib/internal/OverlaySSR.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function OverlaySSR($$payload: Payload, $$props: Props) {
3131
const headFragment = JSDOM.fragment($$payload.head.out);
3232
const bodyFragment = JSDOM.fragment($$payload.out);
3333
const templateNode = headFragment.firstElementChild as HTMLTemplateElement | null;
34-
const rootNode = bodyFragment.firstElementChild as HTMLDivElement | null;
34+
const rootNode = bodyFragment.firstElementChild as HTMLElement | null;
3535
if (templateNode && rootNode && translation) {
3636
rootNode.innerHTML = '';
3737
rootNode.appendChild(templateNode.content.cloneNode(true));

src/tests/dom/__snapshots__/svelte@5/examples.test.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ exports[`Example localized-legacy/attributes/App.svelte > should render 1`] = `
137137

138138
exports[`Example overlay/dynamic-text/App.svelte > should render 1`] = `
139139
<div>
140-
<div
140+
<svelte-fluent-overlay
141141
style="display: contents;"
142142
>
143143
You can download "⁨Example Product⁩" by clicking
@@ -156,14 +156,14 @@ the
156156
release notes
157157
</a>
158158
to learn more.
159-
</div>
159+
</svelte-fluent-overlay>
160160
161161
</div>
162162
`;
163163

164164
exports[`Example overlay/static-text/App.svelte > should render 1`] = `
165165
<div>
166-
<div
166+
<svelte-fluent-overlay
167167
style="display: contents;"
168168
>
169169
Read the
@@ -174,7 +174,7 @@ exports[`Example overlay/static-text/App.svelte > should render 1`] = `
174174
documentation
175175
</a>
176176
for more information.
177-
</div>
177+
</svelte-fluent-overlay>
178178
179179
</div>
180180
`;

src/tests/ssr/__snapshots__/svelte@5/examples.test.js.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,21 @@ exports[`Example localized-legacy/attributes/App.svelte > should render 1`] = `
7474

7575
exports[`Example overlay/dynamic-text/App.svelte > should render 1`] = `
7676
{
77-
"body": "<!--[--><div style="display: contents;">You can download "Example Product" by clicking
77+
"body": "<!--[--><svelte-fluent-overlay style="display: contents;">You can download "Example Product" by clicking
7878
on the <strong>Download</strong> button or read
79-
the <a data-l10n-name="release-notes" href="https://example.com/" target="_blank" rel="noreferrer">release notes</a> to learn more.</div><!--]-->",
79+
the <a data-l10n-name="release-notes" href="https://example.com/" target="_blank" rel="noreferrer">release notes</a> to learn more.</svelte-fluent-overlay><!--]-->",
8080
"head": "<!--[--><template><a data-l10n-name="release-notes" href="https://example.com/" target="_blank" rel="noreferrer"></a><!----></template><!--]-->",
81-
"html": "<!--[--><div style="display: contents;">You can download "Example Product" by clicking
81+
"html": "<!--[--><svelte-fluent-overlay style="display: contents;">You can download "Example Product" by clicking
8282
on the <strong>Download</strong> button or read
83-
the <a data-l10n-name="release-notes" href="https://example.com/" target="_blank" rel="noreferrer">release notes</a> to learn more.</div><!--]-->",
83+
the <a data-l10n-name="release-notes" href="https://example.com/" target="_blank" rel="noreferrer">release notes</a> to learn more.</svelte-fluent-overlay><!--]-->",
8484
}
8585
`;
8686

8787
exports[`Example overlay/static-text/App.svelte > should render 1`] = `
8888
{
89-
"body": "<!--[--><div style="display: contents;">Read the <a data-l10n-name="link" href="https://example.com/">documentation</a> for more information.</div><!--]-->",
89+
"body": "<!--[--><svelte-fluent-overlay style="display: contents;">Read the <a data-l10n-name="link" href="https://example.com/">documentation</a> for more information.</svelte-fluent-overlay><!--]-->",
9090
"head": "<!--[--><template><a data-l10n-name="link" href="https://example.com/"></a><!----></template><!--]-->",
91-
"html": "<!--[--><div style="display: contents;">Read the <a data-l10n-name="link" href="https://example.com/">documentation</a> for more information.</div><!--]-->",
91+
"html": "<!--[--><svelte-fluent-overlay style="display: contents;">Read the <a data-l10n-name="link" href="https://example.com/">documentation</a> for more information.</svelte-fluent-overlay><!--]-->",
9292
}
9393
`;
9494

0 commit comments

Comments
 (0)