Skip to content

Fix dom.unbind calling nonexistent removeEventListeners - #868

Merged
jonobr1 merged 2 commits into
jonobr1:devfrom
SahinurDEV:fix/dom-unbind-remove-event-listener
Oct 10, 2026
Merged

jonobr1 merged 2 commits into
jonobr1:devfrom
SahinurDEV:fix/dom-unbind-remove-event-listener

Conversation

@SahinurDEV

Copy link
Copy Markdown
Contributor

Problem

dom.unbind (src/utils/dom.js) calls elem.removeEventListeners(...) in its modern branch. That method does not exist on DOM elements, so any call throws TypeError: elem.removeEventListeners is not a function instead of detaching the listener.

Cause

Typo: plural removeEventListeners instead of the DOM API removeEventListener.

Fix

Call elem.removeEventListener(event, func, !!bool) so dom.unbind symmetrically undoes dom.bind. The legacy detachEvent fallback is unchanged.

Tests

  • Added tests/suite/dom.js (loaded from tests/index.html as a module so it can import the internal dom helper): binds a click handler, dispatches, unbinds, dispatches again and asserts the handler is no longer called and that unbind returns dom without throwing.
  • Without the fix the two dom.unbind assertions fail; with the fix they pass. Ran the suite in headless Chrome: the other results are unchanged (the 5 makeImage / bounding-box failures happen on dev without this change in my headless setup too).
  • npx eslint src/utils/dom.js tests/suite/dom.js and npm run types:check pass.

Fixes #850

dom.unbind called elem.removeEventListeners (plural), which does not
exist on DOM elements, so unbinding threw a TypeError instead of
detaching the listener. Call removeEventListener and add a QUnit test
that binds, unbinds and dispatches to verify the handler is detached.

Fixes #850

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The fix is correct, scoped, and directly covered by a regression test.

0 open findings

What changed in this PR

Fixes dom.unbind so it correctly removes modern DOM event listeners.

Changes:

  • Corrects the DOM API method name.
  • Adds a focused browser regression test.
  • Registers the test in the QUnit runner.
File Description
src/​utils/​dom.js Uses removeEventListener.
tests/​suite/​dom.js Tests binding and unbinding behavior.
tests/​index.html Loads the new test suite.

🧠 Review effort: Balanced


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

@jonobr1

jonobr1 commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Wow, thank you! This was a bonehead move on my part 🤷‍♂️

@jonobr1 jonobr1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Appreciate you added tests as well! Everything passes and looks good.

@jonobr1
jonobr1 merged commit 84ad8a9 into jonobr1:dev Oct 10, 2026
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.

dom.unbind calls nonexistent removeEventListeners method

3 participants