theKashey / react-focus-lock

It is a trap! A lock for a Focus. 🔓
MIT License
1.27k stars 67 forks source link

react-focus-lock with focus-lock@0.11.5 throws when focus taken from cross-origin iframe #241

Closed chekrd closed 1 year ago

chekrd commented 1 year ago

Hi, go to https://codesandbox.io/s/focus-lock-fail-4gkvyx?file=/src/App.tsx and press Click.

In react-focus-lock@2.9.2 nothing happens, but in @2.9.3 because of this, I assume, it throws and can break the app.

How can I achieve some kind of "try and swallow" approach?

theKashey commented 1 year ago

Yep, you cannot and that's a serious regression. Look like I've broken internet one another time 🎉

nebrius commented 1 year ago

We ran into this issue too, but pinning focus-lock to version 0.11.3 worked around the issue for us. Looking forward to the fix when you get a chance, and thanks for your work!

chekrd commented 1 year ago

Yes, because react-focus-lock has dependency "focus-lock": "^0.doesNotMatter", all versions of react-focus-lock can be affected. The issue should be moved into the focus-lock repository.

The workaround is to install explicit versions in your package.json: "react-focus-lock": "2.9.2", (react-focus-lock@2.9.3 requires focus-lock of version ^0.11.5) "focus-lock": "0.11.4"

theKashey commented 1 year ago

An update to focus-lock(0.11.6) and react-focus-lock(2.9.4) has been released.

There is still no test securing the right behaviour as JSDOM does not support cross-origin security concerns - https://github.com/jsdom/jsdom/issues/1892

I will add real Browser tests, at least a few, shortly - https://github.com/theKashey/react-focus-lock/issues/242