fix(live): variant observer detects wrappers added as descendants

startVariantObserver's "dominated" check only matched when the variant
wrapper was added directly as a mutation's addedNode. SvelteKit (and any
framework whose HMR replaces a whole subtree on edit) adds the wrapper as
a descendant of an added <main> or similar — the observer ignored those
mutations and the session stayed in GENERATING forever even with all 3
variants present in the DOM.

Surfaced by the LLM-agent E2E run on vite8-sveltekit. The fake-agent path
masked the issue because its splice timing happened before Vite's reload
finalized; the slower LLM call shifted timing into the failure window.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Paul Bakaus
2026-04-25 01:05:28 -07:00
co-authored by Claude Opus 4.7
parent 89ffd73d4b
commit 4310352423
12 changed files with 120 additions and 12 deletions
@@ -2011,7 +2011,16 @@
for (const m of mutations) {
if (m.target.closest?.('[data-impeccable-variants]')) { dominated = true; break; }
for (const n of m.addedNodes) {
if (n.nodeType === 1 && (n.dataset?.impeccableVariants || n.dataset?.impeccableVariant)) {
if (n.nodeType !== 1) continue;
// Direct hit: the added node itself is the wrapper or a variant.
if (n.dataset?.impeccableVariants || n.dataset?.impeccableVariant) {
dominated = true; break;
}
// Subtree hit: framework HMR (notably SvelteKit) sometimes replaces
// a whole subtree where the wrapper is a descendant of the added
// node. Without this check, the observer ignores those mutations
// and the session stays in GENERATING forever.
if (n.querySelector?.('[data-impeccable-variants],[data-impeccable-variant]')) {
dominated = true; break;
}
}