fix(useFocusVisible): use Reflect.defineProperty to wrap HTMLElement.prototype.focus#10041
fix(useFocusVisible): use Reflect.defineProperty to wrap HTMLElement.prototype.focus#10041antododo wants to merge 3 commits into
Conversation
1300068 to
6fbb592
Compare
|
At this point, why override at all instead of using an apply trap? |
@nwidynski The bug is the install mechanism (getter-only focus accessor breaks plain assignment), not the wrapper shape, so a Proxy would still need the same |
|
@antododo Not with a Proxy, but via Reflect API. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty That wont throw when failing to install the override. |
|
@nwidynski thanks for the suggestion, PR updated. |
snowystinger
left a comment
There was a problem hiding this comment.
I'm fine with this, hopefully userEvent gets their act together soon
|
@snowystinger Hello and thanks for the approval. How can we get a second one? Thanks in advance! |
Closes #9649
✅ Pull Request Checklist:
📝 Test Instructions:
yarn jest packages/react-aria/test/interactions/useFocusVisible.test.js— all 18 tests pass, including the new regression testdoes not throw when HTMLElement.prototype.focus is an accessor-only property.src/change, keep the new test, and rerun the command above. The new test should fail withTypeError: Cannot set property focus of [object HTMLElement] which has only a getter. Re-apply thesrc/change and the test passes.yarn jest packages/react-aria/test/interactions/— all 237 tests pass.Reflect.definePropertycall is equivalent to the previous assignment against the defaultHTMLElement.prototype.focusdata descriptor).🧢 Your Project:
While building components on
react-aria-componentsfor Swissquote.ch internal design system where consumers' Jest+JSDOM test suites using@testing-library/user-event'ssetup()crash on import of any RAC-using component.