Skip to content

fix: delegated event listener#1278

Open
danielbarion wants to merge 1 commit into
masterfrom
fix/delegated-event-listener
Open

fix: delegated event listener#1278
danielbarion wants to merge 1 commit into
masterfrom
fix/delegated-event-listener

Conversation

@danielbarion
Copy link
Copy Markdown
Member

@danielbarion danielbarion commented Jun 1, 2026

fix #1277

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced tooltip event handling with stricter runtime type validation to ensure robust behavior when events target non-standard DOM elements, preventing potential errors.
    • Improved tooltip anchor resolution logic to safely handle broader element types while maintaining safe property access.
  • Tests

    • Extended test coverage for tooltip interaction behavior, including edge cases where events are dispatched on the document.

@danielbarion danielbarion self-assigned this Jun 1, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 43d586c9-a104-47e9-9ca2-619e052bef05

📥 Commits

Reviewing files that changed from the base of the PR and between af0a01a and 58511a9.

📒 Files selected for processing (3)
  • src/components/Tooltip/use-tooltip-events.tsx
  • src/test/tooltip-interaction-behavior.spec.js
  • src/utils/resolve-data-tooltip-anchor.ts

📝 Walkthrough

Walkthrough

The PR hardens tooltip event handling to safely ignore synthetic events targeting document. It adds type guards in the event listener and anchor resolution utility to prevent crashes from accessing dataset on non-HTMLElement nodes, validated by a new test case.

Changes

Document-safe tooltip event handling

Layer / File(s) Summary
Type-safe event target handling
src/components/Tooltip/use-tooltip-events.tsx, src/utils/resolve-data-tooltip-anchor.ts
Event listener entry point adds instanceof Element check before isConnected validation. Anchor resolution utility widens parameter type to Element and adds instanceof HTMLElement guard before accessing dataset.tooltipId, preventing crashes when synthetic events target document.
Test coverage for document-targeted events
src/test/tooltip-interaction-behavior.spec.js
New test case dispatches a synthetic mouseover event on document and verifies the tooltip listener does not throw and does not render the associated tooltip.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • gabrieljablonski

Poem

🐰 A document clicked, then it crashed with a cry,
"dataset is missing!" the poor tooltip did sigh.
But now we check types with a guard so precise,
No more synthetic event surprises—how nice! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: delegated event listener' directly addresses the main change: fixing the delegated event listener crash when document is the event target.
Linked Issues check ✅ Passed The pull request fully implements the suggested fixes from issue #1277: adding Element type checks and isConnected guards in use-tooltip-events.tsx, and instanceof HTMLElement checks before dataset access in resolve-data-tooltip-anchor.ts.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the delegated event listener crash: updates to event target validation, type constraints, and defensive instanceof checks align with issue #1277 requirements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/delegated-event-listener

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/components/Tooltip/use-tooltip-events.tsx

Oops! Something went wrong! :(

ESLint: 10.2.0

TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module "file:///.eslintrc.json?mtime=1780321010692" needs an import attribute of "type: json"
at validateAttributes (node:internal/modules/esm/assert:88:15)
at defaultLoadSync (node:internal/modules/esm/load:164:3)
at #loadAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:776:12)
at #loadSync (node:internal/modules/esm/loader:796:49)
at ModuleLoader.load (node:internal/modules/esm/loader:762:26)
at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:504:31)
at #getOrCreateModuleJobAfterResolve (node:internal/modules/esm/loader:555:36)
at afterResolve (node:internal/modules/esm/loader:603:52)
at ModuleLoader.getOrCreateModuleJob (node:internal/modules/esm/loader:609:12)
at node:internal/modules/esm/loader:628:32

src/test/tooltip-interaction-behavior.spec.js

Oops! Something went wrong! :(

ESLint: 10.2.0

TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module "file:///.eslintrc.json?mtime=1780321010692" needs an import attribute of "type: json"
at validateAttributes (node:internal/modules/esm/assert:88:15)
at defaultLoadSync (node:internal/modules/esm/load:164:3)
at #loadAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:776:12)
at #loadSync (node:internal/modules/esm/loader:796:49)
at ModuleLoader.load (node:internal/modules/esm/loader:762:26)
at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:504:31)
at #getOrCreateModuleJobAfterResolve (node:internal/modules/esm/loader:555:36)
at afterResolve (node:internal/modules/esm/loader:603:52)
at ModuleLoader.getOrCreateModuleJob (node:internal/modules/esm/loader:609:12)
at node:internal/modules/esm/loader:628:32

src/utils/resolve-data-tooltip-anchor.ts

Oops! Something went wrong! :(

ESLint: 10.2.0

TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module "file:///.eslintrc.json?mtime=1780321010692" needs an import attribute of "type: json"
at validateAttributes (node:internal/modules/esm/assert:88:15)
at defaultLoadSync (node:internal/modules/esm/load:164:3)
at #loadAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:776:12)
at #loadSync (node:internal/modules/esm/loader:796:49)
at ModuleLoader.load (node:internal/modules/esm/loader:762:26)
at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:504:31)
at #getOrCreateModuleJobAfterResolve (node:internal/modules/esm/loader:555:36)
at afterResolve (node:internal/modules/esm/loader:603:52)
at ModuleLoader.getOrCreateModuleJob (node:internal/modules/esm/loader:609:12)
at node:internal/modules/esm/loader:628:32


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

Beta version released with the last commit 🚀

yarn add react-tooltip@6.0.5-beta.1278.rc.0

or

npm install react-tooltip@6.0.5-beta.1278.rc.0

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Delegated mouseover listener crashes on synthetic events targeting document (dataset is undefined)

1 participant