Skip to content

Fix: Remove leaked child change listener in HotgraphicModel (fixes #372) - #373

Merged
oliverfoster merged 1 commit into
masterfrom
issue/372
Aug 19, 2026
Merged

oliverfoster merged 1 commit into
masterfrom
issue/372

Conversation

@oliverfoster

@oliverfoster oliverfoster commented Jul 27, 2026

Copy link
Copy Markdown
Member

fixes #372

Fix

  • Replaced child.on('change', ...) with this.listenTo(child, 'change', ...) in HotgraphicModel.setUpItems() so the listener is tracked against the component model and automatically removed via stopListening() when the model is torn down, instead of leaking on the child item indefinitely.

Testing

  1. Add a Hot Graphic component with tooltips enabled.
  2. Trigger setUpItems() multiple times for the same items (e.g. switch language / reset course).
  3. Confirm only one change listener is attached per item (no growth in event listener count on the child model).
  4. Confirm tooltip content still updates correctly when the item's attributes change (position, visited state, classes).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the listener leak described in #372 by switching tooltip-sync item listeners from being attached directly to child models to being tracked by the parent HotgraphicModel, so they can be cleaned up via stopListening() when the component model is torn down.

Changes:

  • Replace child.on('change', ...) with this.listenTo(child, 'change', ...) inside HotgraphicModel.setUpItems() to ensure listener cleanup on teardown.
Suppressed comments (1)

js/hotgraphicModel.js:41

  • listenTo ensures cleanup on model teardown, but setUpItems() can run multiple times on the same HotgraphicModel instance. As written, each call will add another change listener (now tracked on this), so the child’s change listener count can still grow during the model’s lifetime. Consider de-duping by storing the per-child handler and stopListening(child, 'change', prevHandler) before binding a new one.
      this.listenTo(child, 'change', () => {
        tooltipModel.set({
          ...child.toJSON(),
          ...tooltip,
          _classes: tooltipModel.get('_classes')

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@oliverfoster
oliverfoster merged commit dc8fbb3 into master Aug 19, 2026
2 checks passed
@oliverfoster
oliverfoster deleted the issue/372 branch August 19, 2026 14:55
@github-project-automation github-project-automation Bot moved this from Needs Reviewing to Recently Released in adapt_framework: The TODO Board Aug 19, 2026
github-actions Bot pushed a commit that referenced this pull request Aug 19, 2026
## [6.21.1](v6.21.0...v6.21.1) (2026-08-19)

### Fix

* Remove leaked child change listener in HotgraphicModel (fixes #372) (#373) ([dc8fbb3](dc8fbb3)), closes [#372](#372) [#373](#373)
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 6.21.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Recently Released

Development

Successfully merging this pull request may close these issues.

Memory leak: child.on('change') listener never removed in HotgraphicModel.setUpItems()

4 participants