Fix race when replacing views during fade

This commit is contained in:
Jordan Wages 2025-09-17 00:09:00 -05:00
commit 371ed5a2b0

View file

@ -69,14 +69,18 @@
async function replace(view) { async function replace(view) {
const el = ensureViewEl(view); const el = ensureViewEl(view);
if (currentBase) { const prev = currentBase;
await fadeOut(currentBase.el); if (prev) {
$uxRoot.removeChild(currentBase.el); const prevEl = prev.el;
if (typeof currentBase.view.destroy === 'function') currentBase.view.destroy(); if (prevEl && prevEl.isConnected) {
await fadeOut(prevEl);
if (prevEl.parentNode === $uxRoot) $uxRoot.removeChild(prevEl);
}
if (prev.view && typeof prev.view.destroy === 'function') prev.view.destroy();
} }
$uxRoot.appendChild(el); $uxRoot.appendChild(el);
await fadeIn(el);
currentBase = { view, el }; currentBase = { view, el };
await fadeIn(el);
if (typeof view.onShow === 'function') view.onShow(); if (typeof view.onShow === 'function') view.onShow();
} }