[#720] Add strict mode compatibility by stefcameron · Pull Request #721 · focus-trap/focus-trap-react (original) (raw)
Fixes #720
In React strict mode, the trap gets immediately unmounted and remounted after first mount. The trap deactivates automatically on unmount, so on remount, we try to restore the trap to its previous active/paused state based on the component's existing state.
React does not re-render the component, nor does it call callback refs again, so we have no choice but to assume the DOM hasn't changed and the existing trap's container elements are still in the DOM...
Way to go React for strict mode violating the assumption of
componentWillUnmount(), "Once a component is unmounted, it will
never be mounted again." Not a fan.
Also bumped react-dom to 18.2.0 since react was already there, and set NODE_ENV for different builds.