const slotName = 'something';
const timeoutMs = 1000;
// Attach shadow DOM on #container...
const container = document.querySelector('#container');
const shadow = container.attachShadow({
mode: 'open',
});
// A named slot for the shadow DOM
const slot = document.createElement('slot');
slot.setAttribute('name', slotName);
const tombstoneSlotName = 'tombstone';
// tombstone.setAttribute('name', tombstoneSlotName);
// Populate the contents of the shadow DOM of #container.
window.setTimeout(() => {
// Put slot into a green div...
const bg = document.createElement('div');
bg.style.backgroundColor = 'green';
bg.style.width = '100%';
bg.style.height = '100%';
bg.appendChild(slot);
shadow.appendChild(bg);
}, timeoutMs);
// Removing this element *after* removing the slot, will trigger the issue.
const slotted = document.querySelector('#slotted');
// (You can also dynamically add the content, it doesn't seem to matter)
/*
let slotted = document.createElement('div');
slotted.innerText = 'Some content...';
slotted.setAttribute('slot', slotName);
container.appendChild(slotted);
*/
// This needs to happen first. Then...
window.setTimeout(() => {
slot.remove();
}, 2 * timeoutMs);
// This will make the whole #container lose layout/disappear. WAT?
window.setTimeout(() => {
const tombstone = document.createElement('slot');
shadow.appendChild(tombstone);
slotted.setAttribute('name', tombstoneSlotName);
slotted.remove();
tombstone.remove();
}, 3 * timeoutMs);
// If slot.remove and slotted.remove happen in the same timeout, the issue doesn't happen, regardless of their order
// If slotted.remove happens *before* slot.remove, the issue doesn't happen.
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.