Replies: 3 comments 1 reply
-
This is most likely a bug in your code which tries to assign a value to |
Beta Was this translation helpful? Give feedback.
-
Hello, I am facing the exact same problem with different library so I would like to add on to this. Here is the error on my case {
stack: 'TypeError: Cannot set property focus of [object HTMLElement] which has only a getter\n' +
' at setupGlobalFocusEvents (file:///home/runner/work/the-sorter/the-sorter/node_modules/@zag-js/focus-visible/dist/index.mjs:75:35)\n' +
' at trackFocusVisible (file:///home/runner/work/the-sorter/the-sorter/node_modules/@zag-js/focus-visible/dist/index.mjs:149:3)\n' +
' at trackFocusVisible (file:///home/runner/work/the-sorter/the-sorter/node_modules/@zag-js/checkbox/dist/index.mjs:198:18)\n' +
' at Machine.executeActivities (file:///home/runner/work/the-sorter/the-sorter/node_modules/@zag-js/core/dist/index.mjs:477:25)\n' +
' at Machine.start (file:///home/runner/work/the-sorter/the-sorter/node_modules/@zag-js/core/dist/index.mjs:221:12)\n' +
' at file:///home/runner/work/the-sorter/the-sorter/node_modules/@zag-js/react/dist/index.mjs:163:13\n' +
' at Object.react-stack-bottom-frame (/home/runner/work/the-sorter/the-sorter/node_modules/react-dom/cjs/react-dom-client.development.js:22509:20)\n' +
' at runWithFiberInDEV (/home/runner/work/the-sorter/the-sorter/node_modules/react-dom/cjs/react-dom-client.development.js:543:16)\n' +
' at commitHookEffectListMount (/home/runner/work/the-sorter/the-sorter/node_modules/react-dom/cjs/react-dom-client.development.js:10758:29)\n' +
' at commitHookLayoutEffects (/home/runner/work/the-sorter/the-sorter/node_modules/react-dom/cjs/react-dom-client.development.js:10710:11)',
message: 'Cannot set property focus of [object HTMLElement] which has only a getter',
...
} The root cause I found is that the new feature introduced in version 14.6.1 patched HTMLElement.prototype (#1252) but it didn't include a setter, which prevents @zag-js/focus-visible from also patching the object. Object.defineProperties(HTMLElement.prototype, {
focus: {
configurable: true,
get: () => patchedFocus,
// no setter here
},
...
}) code from @zag/focus-visible let focus = win.HTMLElement.prototype.focus
win.HTMLElement.prototype.focus = function () {
currentModality = "virtual"
triggerChangeHandlers("virtual", null)
hasEventBeforeFocus = true
focus.apply(this, arguments as unknown as [options?: FocusOptions | undefined])
} For now I keep @testing-library/user-event at 14.5.2 so that I could run my test. I'm not really sure how to fix this as the two library is trying to patch the same object, but I believe when setting Object.prototype it is somehow inherited so there is a chance it might work together. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I want to file a bug report, but I need to figure out how to create a minimal reproducible CodeSandBox. However, at this point, I don't know exactly where the error is coming from.
It definitely started with the latest version (14.6.0) -- I rolled back to 14.5.2, and the errors went away -- and these are the errors I get in my tests:
I guess it's related to #1252 somehow? But I need help in trying to track down exactly where in my codebase this error is being triggered from. The subsequent stack traces aren't really helpful. Also, I'm not entirely sure what the error means, or how the problem manifests, or even how to fix it.
If anyone can give me some debugging tips, that'll be great!
Beta Was this translation helpful? Give feedback.
All reactions