Skip to content

fix: wait a longer tick before checking slots #8999

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

Draft
wants to merge 1 commit into
base: svelte-4
Choose a base branch
from
Draft
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/tiny-walls-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: wait a longer tick before checking slots
5 changes: 3 additions & 2 deletions packages/svelte/src/runtime/internal/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ if (typeof HTMLElement === 'function') {
this.$$cn = true;
if (!this.$$c) {
// We wait one tick to let possible child slot elements be created/mounted
await Promise.resolve();
await new Promise((f) => setTimeout(f)); // don't do Promise.resolve() as that fires too soon
if (!this.$$cn) {
return;
}
Expand Down Expand Up @@ -316,7 +316,8 @@ if (typeof HTMLElement === 'function') {
disconnectedCallback() {
this.$$cn = false;
// In a microtask, because this could be a move within the DOM
Promise.resolve().then(() => {
// don't do Promise.resolve() as that fires too soon
new Promise((f) => setTimeout(f)).then(() => {
if (!this.$$cn) {
this.$$c.$destroy();
this.$$c = undefined;
Expand Down