Skip to content

fix: ensure custom elements do not sync flush on mount #12787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cool-turtles-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: ensure custom elements do not sync flush on mount
5 changes: 4 additions & 1 deletion packages/svelte/src/legacy/legacy-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ class Svelte4Component {
recover: options.recover
});

flush_sync();
// We don't flush_sync for custom element wrappers
if (!options?.props?.$$host) {
flush_sync();
}

this.#events = props.$$events;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { test } from '../../assert';
const tick = () => Promise.resolve();

export default test({
async test({ assert, target }) {
let changed = false;

target.innerHTML = '<child-element></child-element>';

await tick(); // wait for element to upgrade

target.addEventListener('change', () => {
changed = true;
});

await tick(); // wait for effect

assert.equal(changed, true);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<svelte:options customElement="child-element" />

<script>
$effect(() => {
$host().dispatchEvent(new CustomEvent('change', { bubbles: true }));
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default test({
async test({ assert, target }) {
target.innerHTML = '<custom-element></custom-element>';
await tick();
await tick();
/** @type {any} */
const ce = target.querySelector('custom-element');
const icon = ce.shadowRoot.querySelector('.icon');
Expand Down
Loading