Skip to content

Commit 7ffa5f4

Browse files
committed
fix: wait a longer tick before checking slots
It seems that browser resolve "await Promise.resolve()" extra fast (close to synchronous) so the DOM isn't actually updated further. This fixes an issue where web component slots don't appear when the script registering the web components is invoked before them being added to the DOM fixes #8997
1 parent 657f113 commit 7ffa5f4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

.changeset/tiny-walls-brake.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: wait a longer tick before checking slots

packages/svelte/src/runtime/internal/Component.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ if (typeof HTMLElement === 'function') {
215215
this.$$cn = true;
216216
if (!this.$$c) {
217217
// We wait one tick to let possible child slot elements be created/mounted
218-
await Promise.resolve();
218+
await new Promise((f) => setTimeout(f)); // don't do Promise.resolve() as that fires too soon
219219
if (!this.$$cn) {
220220
return;
221221
}
@@ -316,7 +316,8 @@ if (typeof HTMLElement === 'function') {
316316
disconnectedCallback() {
317317
this.$$cn = false;
318318
// In a microtask, because this could be a move within the DOM
319-
Promise.resolve().then(() => {
319+
// don't do Promise.resolve() as that fires too soon
320+
new Promise((f) => setTimeout(f)).then(() => {
320321
if (!this.$$cn) {
321322
this.$$c.$destroy();
322323
this.$$c = undefined;

0 commit comments

Comments
 (0)