Skip to content

fix: preventFocus TypeError on window focus/blur during a press - #10592

Open
microbit-matt-hillsdon wants to merge 1 commit into
adobe:mainfrom
microbit-matt-hillsdon:preventfocus-window-target-fix
Open

fix: preventFocus TypeError on window focus/blur during a press#10592
microbit-matt-hillsdon wants to merge 1 commit into
adobe:mainfrom
microbit-matt-hillsdon:preventfocus-window-target-fix

Conversation

@microbit-matt-hillsdon

Copy link
Copy Markdown

preventFocus attaches focus and blur listeners to the window. When the window itself gains or loses focus the target is Window not a Node. Both helpers passed it straight into nodeContains, so Node.contains threw:

TypeError: Failed to execute 'contains' on 'Node': parameter 1 is not of type 'Node'.

Guard both calls with isNode and add a usePress test.

Fixes #10591

Closes

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices
  • I understand every change in this PR and can explain why it's there.
  • If AI-assisted, I followed our AI contribution guidance and pointed my assistant at CLAUDE.md.

📝 Test Instructions:

I clicked around some storybook cases that exercise preventFocus (e.g. number field +/-) but that's for the happy path not so much the bug which was hard to reproduce, likely due to RAF timing, but seen in error logs.

🧢 Your Project:

micro:bit Python Editor

preventFocus attaches focus and blur listeners to the window. When the
window itself gains or loses focus the target is Window not a Node.
Both helpers passed it straight into nodeContains, so Node.contains
threw:

  TypeError: Failed to execute 'contains' on 'Node': parameter 1 is not of type 'Node'.

Guard both calls with isNode and add a usePress test.

Fixes adobe#10591
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.

preventFocus() TypeError when the window is the target focus or blur

2 participants