{"record":{"id":"fc82b144362316aa","repo":"pbakaus/impeccable","slug":"impeccable-svelte-component-reset-cleanup-failed","errorCode":null,"errorMessage":"[impeccable] Svelte component reset cleanup failed:","messagePattern":"\\[impeccable\\] Svelte component reset cleanup failed:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"skill/scripts/live-browser.js","lineNumber":6143,"sourceCode":"    if (details) showMountErrorCard(sessionId, details);\n    else if (!mountErrorState) {\n      showMountErrorCard(sessionId, { message: 'Variants could not be mounted. Retry, or ask the agent to republish.' });\n    }\n  }\n\n  // Hard reset for the one case that is not a mount failure: a cycling state\n  // with nothing to cycle. There is no variant to retry and no URL to report,\n  // so the session really is over.\n  function resetSvelteComponentSession(sessionId, message) {\n    try {\n      if (svelteComponentSession?.sessionId === sessionId) {\n        teardownSvelteComponentSession(true);\n      } else {\n        const orphan = document.querySelector('[data-impeccable-variants=\"' + sessionId + '\"]');\n        if (orphan) orphan.remove();\n      }\n    } catch (err) {\n      console.warn('[impeccable] Svelte component reset cleanup failed:', err);\n    }\n    hideShaderOverlay();\n    if (variantObserver) { variantObserver.disconnect(); variantObserver = null; }\n    if (pendingSvelteComponentRetryObserver) { pendingSvelteComponentRetryObserver.disconnect(); pendingSvelteComponentRetryObserver = null; }\n    if (pendingVariantAnchorRetryObserver) { pendingVariantAnchorRetryObserver.disconnect(); pendingVariantAnchorRetryObserver = null; }\n    stopScrollLock();\n    removeVariantStateStylesheet();\n    clearMountErrorCard();\n    clearSession();\n    clearHandled();\n    resetSessionFileMeta();\n    currentSessionId = null;\n    parameterGenerationState = 'idle';\n    parameterReadyAnnouncedSession = null;\n    expectedVariants = 0;\n    arrivedVariants = 0;\n    visibleVariant = 0;\n    selectedElement = null;","sourceCodeStart":6125,"sourceCodeEnd":6161,"githubUrl":"https://github.com/pbakaus/impeccable/blob/f88b2837a7d7c3182e46307bbbb091a1ed547571/skill/scripts/live-browser.js#L6125-L6161","documentation":"resetSvelteComponentSession is the hard reset for a svelte-component session that is cycling with nothing to cycle to: it tears down the session or removes the orphaned variants container, disconnects all observers, releases the scroll lock, clears the error card, and wipes session state. The teardown step is individually try/caught; if it throws (detached/foreign-owned DOM), the error is logged as 'reset cleanup failed:' and the rest of the reset still completes, including clearing currentSessionId.","triggerScenarios":"The app framework removed the variants container before the reset ran; reset racing a remount; the container's parent replaced by framework code that invalidates the cached reference.","commonSituations":"Session reset landing after a page navigation or hydration pass; repeated resets in quick succession; third-party scripts mutating the same DOM region.","solutions":["Benign in most cases — confirm the variants container, observers, and scroll lock are gone; reload if residue persists","Add isConnected guards before DOM teardown","Trigger the reset once per session end, not on every unrelated state change"],"exampleFix":"// before\nif (svelteComponentSession?.sessionId === sessionId) teardownSvelteComponentSession(true);\n// after\nif (svelteComponentSession?.sessionId === sessionId && document.contains(variantHostEl)) teardownSvelteComponentSession(true);","handlingStrategy":"fallback","validationCode":"if (svelteComponentSession?.sessionId === sessionId && !document.contains(sessionHostEl)) {\n  // host already removed by the app — skip DOM teardown, still clear state\n}","typeGuard":null,"tryCatchPattern":"try { teardownSvelteComponentSession(true); } catch (err) { console.warn('reset cleanup failed', err); } // proceed: observers, scroll lock, and session state must clear regardless","preventionTips":["Run the hard reset exactly once per terminal session state","Guard all cleanup DOM access with isConnected/contains checks","Verify after reset that currentSessionId is null and no variant stylesheet remains"],"tags":["dom-cleanup","svelte-preview","session-reset","race-condition"],"backgroundTag":"dom-cleanup-race-condition","analyzedSha":"f88b2837a7d7c3182e46307bbbb091a1ed547571","analyzedAt":"2026-08-18T04:58:36.608Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}