{"record":{"id":"54e90bf8c70008cc","repo":"siyuan-note/siyuan","slug":"cannot-track-a-range-in-a-destroyed-protyle-instan","errorCode":null,"errorMessage":"Cannot track a range in a destroyed Protyle instance","messagePattern":"Cannot track a range in a destroyed Protyle instance","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/src/protyle/util/trackedRange.ts","lineNumber":1134,"sourceCode":"        removeInputListeners(protyle);\n    }\n    if (state.owner) {\n        const handles = ownedHandles.get(state.owner);\n        handles?.forEach(item => {\n            if (item.protyle === protyle && item.handle === handle) {\n                handles.delete(item);\n            }\n        });\n        if (handles?.size === 0) {\n            ownedHandles.delete(state.owner);\n        }\n    }\n};\n\nexport const trackRange = (protyle: IProtyle, range: Range,\n                           options: ITrackRangeOptions): ITrackedRangeHandle => {\n    if (destroyedProtyles.has(protyle)) {\n        throw new Error(\"Cannot track a range in a destroyed Protyle instance\");\n    }\n    if (!options?.owner || ![\"function\", \"object\"].includes(typeof options.owner)) {\n        throw new TypeError(\"The tracked range owner is required\");\n    }\n    if (options.affinity && ![\"after\", \"before\"].includes(options.affinity)) {\n        throw new TypeError(\"The tracked range affinity must be before or after\");\n    }\n    if (unloadingPlugins.has(options.owner)) {\n        throw new Error(\"Cannot track a range for an unloaded plugin\");\n    }\n    const rangeSnapshot = getRangeSnapshot(protyle, range);\n    if (!rangeSnapshot) {\n        throw new TypeError(\"The range must be inside one editable source block of this Protyle instance\");\n    }\n    const targetTokens = rangeSnapshot.stream.tokens.slice(rangeSnapshot.start, rangeSnapshot.end);\n    if (!range.collapsed && targetTokens.length === 0) {\n        throw new TypeError(\"The tracked range must contain semantic content\");\n    }","sourceCodeStart":1116,"sourceCodeEnd":1152,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/app/src/protyle/util/trackedRange.ts#L1116-L1152","documentation":"Thrown by trackRange before creating a range handle when the given IProtyle instance has previously been destroyed (registered in destroyedProtyles). Range tracking against a destroyed editor is meaningless because its DOM and model are gone; the caller must hold a live Protyle instance or drop the tracking call after destroy.","triggerScenarios":"Thrown at app/src/protyle/util/trackedRange.ts:1134 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Track ranges only while the Protyle instance is alive","Re-create the Protyle instance before tracking","Guard plugin code against operating on a destroyed editor"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}