Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 4, 2025

The TOCTree constructor created a stylesheet element via createStyleSheet(container) but never tracked it for disposal, leaking DOM elements and memory.

Changes

  • Pass DisposableStore to createStyleSheet() to track the stylesheet lifecycle
  • Reuse single stylesheet instance in styleController factory instead of creating new ones
  • Register the store with this.disposables for cleanup on tree disposal

Before:

styleController: id => new DefaultStyleController(domStylesheetsJs.createStyleSheet(container), id)

After:

const disposableStore = new DisposableStore();
const styleElement = domStylesheetsJs.createStyleSheet(container, undefined, disposableStore);
// ...
styleController: id => new DefaultStyleController(styleElement, id)
// ...
this.disposables.add(disposableStore);

Added test with ensureNoDisposablesAreLeakedInTestSuite() to verify fix.

Original prompt

Check for disposable leaks in tocTree and fix any that are there.

Created from VS Code.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: rzhao271 <7199958+rzhao271@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix disposable leaks in tocTree Fix disposable leak in TOCTree stylesheet creation Dec 4, 2025
Copilot AI requested a review from rzhao271 December 4, 2025 22:50
Copilot finished work on behalf of rzhao271 December 4, 2025 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants