{"record":{"id":"fb45d30ef2c1ab27","repo":"pbakaus/impeccable","slug":"impeccable-svelte-component-abort-cleanup-failed","errorCode":null,"errorMessage":"[impeccable] Svelte component abort cleanup failed:","messagePattern":"\\[impeccable\\] Svelte component abort cleanup failed:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"skill/scripts/live-browser.js","lineNumber":6159,"sourceCode":"    if (state !== 'CYCLING') setLiveState('GENERATING');\n    injectSvelteComponentsFromManifest(manifestPath, sessionId);\n  }\n\n  // Tear down a component preview that could not mount, WITHOUT touching\n  // session identity. The old version cleared localStorage, nulled\n  // currentSessionId, and reset to PICKING, which orphaned a session the server\n  // still had in its journal and made every recovery path unreachable. The DOM\n  // teardown and observer cleanup are still right; the state wipe never was.\n  function abortSvelteComponentInjection(sessionId, details) {\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 abort cleanup failed:', err);\n    }\n    hideShaderOverlay();\n    if (pendingSvelteComponentRetryObserver) { pendingSvelteComponentRetryObserver.disconnect(); pendingSvelteComponentRetryObserver = null; }\n    if (pendingVariantAnchorRetryObserver) { pendingVariantAnchorRetryObserver.disconnect(); pendingVariantAnchorRetryObserver = null; }\n    // The generate submit armed a scroll lock and a variant observer; a page\n    // the user cannot scroll, watched by a stale observer, is exactly the\n    // wrong place to show a card asking them to act.\n    stopScrollLock();\n    if (variantObserver) { variantObserver.disconnect(); variantObserver = null; }\n    removeVariantStateStylesheet();\n    hideBar(true);\n    // currentSessionId, the saved session, and the file metadata all survive on\n    // purpose: Retry, a republish from the agent, and a page reload all need\n    // them. saveSession keeps the localStorage cache in step with the server.\n    saveSession();\n    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.' });","sourceCodeStart":6141,"sourceCodeEnd":6177,"githubUrl":"https://github.com/pbakaus/impeccable/blob/f2c7051853848826aac2f4646581d62a732155ad/skill/scripts/live-browser.js#L6141-L6177","documentation":"When a Svelte component generation session is aborted, the cleanup path (teardown or orphan DOM removal) threw; the warning logs it. The rest of the abort path (hiding the shader overlay, disconnecting retry observers) still runs afterwards, so the failure is contained.","triggerScenarios":"Svelte component session abort handler runs teardownSvelteComponentSession(true) or removes the [data-impeccable-variants] orphan node; either throws (e.g. detached DOM, null session internals) and is caught at skill/scripts/live-browser.js:6136.","commonSituations":"User aborts generation while the component tree is mid-mount/unmount; hot-module-reload replaces the DOM between session start and abort; duplicated session IDs in the DOM.","solutions":["Reload the page to reset the live-mode session state.","Retry the Svelte component generation after reload.","If reproducible, check for duplicate data-impeccable-variants attributes matching the sessionId in the DOM.","Report if it persists; the leftover overlay/observers are cleaned in the following lines."],"exampleFix":"// before\nif (orphan) orphan.remove();\n// after (guard against already-detached nodes throwing)\nif (orphan && orphan.isConnected) orphan.remove();","handlingStrategy":"try-catch","validationCode":"function orphanStillThere(sessionId) {\n  return !!document.querySelector('[data-impeccable-variants=\"' + sessionId + '\"]');\n}","typeGuard":null,"tryCatchPattern":"try {\n  teardownSvelteComponentSession(true);\n} catch (err) {\n  console.warn('[impeccable] Svelte component abort cleanup failed:', err);\n} finally {\n  hideShaderOverlay();\n}","preventionTips":["Make teardown idempotent so a second abort/reset cannot throw","Guard DOM removal with isConnected checks","Null out session references immediately after teardown"],"tags":["svelte","cleanup","browser","dom"],"backgroundTag":"invalid-state-transition","analyzedSha":"f2c7051853848826aac2f4646581d62a732155ad","analyzedAt":"2026-09-08T04:51:14.109Z","contentChangedAt":"2026-09-08T04:51:14.109Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}