-
Notifications
You must be signed in to change notification settings - Fork 809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for React & Node 18 (as easy as adding startTransition() on each setState) #1019
Comments
do you think someone supports this library? |
@AnderUstarroz It seems easy. Would you like to make a contribution? |
@AnderUstarroz can you provide an eample? I installed correctly a basic example with react 18 yesterday |
@multivoltage Would you like to make a contribution? |
Maybe it's related to the weird Probably, something like this: <suspense fallback="...">
<modal />
</suspense> will trigger this behavior. |
I'm guessing to fix this isse the solution is to wrap the function toggleModal() {
startTransition(() => {
setIsOpen(!isOpen);
});
} |
Is it only necessary to set |
@diasbruno yes but as I said before in my example all work great so... |
Thanks, @multivoltage. As @multivoltage said, this feature it released on react 18+, so if we need to make a fix for it, we need to be careful to not break for older versions. |
Maybe we can add "peerDependencies" react >=18 ? |
It's already a peer dependency. |
@AnderUstarroz please can you provide a demo?
Using demo example on homepage here https://www.npmjs.com/package/react-modal seem to work without errors |
@multivoltage with respect to your comment:
To build on what you and @diasbruno have been saying, this would require all projects using react-modal to be on React v18+, no? This would generally be considered a breaking change requiring a new major version release as you pointed out above. :) Given the popularity of this project, I don't think supporting only the latest version of React is a reasonable peer dependency even if there was a major release. |
@doeg
In my experience this is normal. People who install for some reason 4.x in a project with react 17 (or 16) will read a red warning in the console after |
@multivoltage I opened a separate issue here to address which versions of React should be supported: #1041 |
I've spent some time in CodeSandbox trying to reproduce the error noted above:
This issue in the React repo goes into some detail about the error: facebook/react#25629 The simplest reproduction I've gotten so far is attempting to lazy load a component and render it within a modal without wrapping it in a CodeSandbox link: https://codesandbox.io/p/sandbox/react-18-react-modal-suspense-error-vq79xg import "./styles.css";
import ReactModal from "react-modal";
import { useState, lazy, Suspense } from "react";
const ExampleComponent = lazy(() => import("./ExampleComponent"));
export default function App() {
const [showModal, setShowModal] = useState(false);
return (
<div className="App">
<button onClick={() => setShowModal(true)}>Open Modal</button>
<ReactModal isOpen={showModal} onRequestClose={() => setShowModal(false)}>
{/* Uncomment the Suspense boundary below to resolve the error */}
{/* <Suspense fallback={<div>Loading...</div>}> */}
<ExampleComponent />
{/* </Suspense> */}
</ReactModal>
</div>
);
} In this case, adding a I've yet to find a way to reproduce the I've also yet to find anything that would suggest React Modal won't work with React v18, though as mentioned in #1040 I'm going to do some experimentation with React Modal + React v18 in our very complex codebase next week. :) The only other potentially related issue with React Modal + Suspense could be #982. @AnderUstarroz as others have mentioned, it would be super useful to get a reproducible example of what's producing this error for you. 🙇 Otherwise, @diasbruno, it seems like this one could perhaps be closed out as "not a bug"...? |
Maybe README can be edited with some details to help developer in this use-case? |
Bom trabalho, @doeg. 👍 Some notes:
@itsjesusmacias Feel free to jump in anytime. The more people, more ideas. |
Summary:
Current react modal doesn't work with latest version of React + Node v18
Steps to reproduce:
Expected behavior:
Should work normally
Example of issue:
Breaks with the following error message:
Solution:
Simply add
startTransition()
wrapping each of the calls for setting the state.startTransition(() => setState("something))
The text was updated successfully, but these errors were encountered: