Destroying AccessibilitySystem before attaching its canvas leaves a live MutationObserver that crashes later
Current behavior
When accessibility is activated while the renderer canvas is detached, AccessibilitySystem installs a MutationObserver that waits for the canvas to enter the DOM.
If the system is destroyed before that happens, the observer remains active. Appending the retained canvas afterward executes the stale callback and throws:
TypeError: can't access property "ensureAttached", this._canvasObserver is nullThe failure reproduces on the current dev branch at commit 27071aa0096d8749bfdb189857c58178c30cd153 in a headed Firefox runtime.
Expected behavior
Destroying the accessibility system should disconnect every lifecycle-owned observer. Appending a previously detached canvas after destruction should not execute callbacks against nulled system state.
Reproduction
- Create a renderer whose canvas has no parent node.
- Initialize
AccessibilitySystemwithenabledByDefault: true. - Confirm the system is active.
- Destroy the system before inserting the canvas into the DOM.
- Append the retained canvas to
document.body. - Observe the asynchronous uncaught
TypeErrorfrom the stale observer callback.
Observed result in headed Firefox:
{
"errors": [
"TypeError: can't access property \"ensureAttached\", this._canvasObserver is null"
],
"reproduced": true
}Controls:
- Activating the system and attaching the live canvas without destroying it produces no error.
- Starting with an attached canvas, then destroying the system, produces no error.
Root cause
Affected code: src/accessibility/AccessibilitySystem.ts.
_activate() creates a function-local MutationObserver when canvas.parentNode is absent:
const observer = new MutationObserver(() =>
{
if (canvas.parentNode)
{
observer.disconnect();
this._canvasObserver.ensureAttached();
this._initAccessibilitySetup();
}
});The observer is not retained on the system instance. Consequently, destroy() cannot disconnect it before clearing:
this._canvasObserver = null;
this._renderer = null;A later DOM insertion satisfies the callback condition and dereferences cleared lifecycle state.
The stale callback also retains the destroyed system and canvas until it fires, or indefinitely if the canvas is never attached.
Environment
- PixiJS branch:
dev - Commit:
27071aa0096d8749bfdb189857c58178c30cd153 - Runtime: headed Firefox via Camoufox
- Accessibility: explicitly enabled; this is an opt-in subsystem
- Node.js:
v22.22.2
Duplicate review
I searched open and closed issues and pull requests for:
- AccessibilitySystem + destroy
- accessibility + detached canvas
- MutationObserver + accessibility
ensureAttached+ crash
PR #11700 fixes bound event-listener cleanup. PR #12220 fixes fresh-page Tab activation. Neither retains or disconnects the detached-canvas MutationObserver.
Suggested fix direction
Store the pending DOM-attachment observer on the AccessibilitySystem instance, disconnect and clear it during destroy(), and clear it after its callback runs. A destroyed-state guard in the callback can provide defense in depth, but lifecycle ownership should be resolved by disconnecting the observer.
Please consider assigning a bounty if this issue meets the program's impact criteria. I can provide a focused regression test and patch after triage.
Public runnable reproduction
- Repository: https://github.com/mf3493297-png/pixijs-bug-reproductions
- Reproduction: https://github.com/mf3493297-png/pixijs-bug-reproductions/tree/main/accessibility
Run npm ci && npm start, then open http://127.0.0.1:4173/accessibility/ in Firefox. The page prints REPRODUCED: when the bug occurs. The repository includes the exact binary fixtures where applicable and was verified in headed Camoufox.
Source: pixijs/pixijs