Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

fix: conditional rendering causes issues in React 16.3+ #632

Conversation

swquinn
Copy link

@swquinn swquinn commented Jun 18, 2022

Removes conditional rendering in favor of passing down the isOpen
property to the React <Modal> component.

In more recent versions of React, conditional rendering through the use
of portals creates an issue that appears (from my anecdotal experience)
related to #589 ("Loading icon gets stuck..."). Tracking this down in
the React Modal issue tracker, led me to: reactjs/react-modal#808

... in which the following statement was made:

It's recommended to not use modal with conditional rendering. There
is a problem with createPortal when using this way (need to check if
it still happening. It starts happening on version +16.3 of react).

Are you all using conditional rendering?

Since react-modal recommends against using conditional rendering,
I'm submitting a patch that should hopefully complement other fixes for
#589 and also bring the usage of the <Modal /> in this project closer
to what is recommended by the upstream project maintainers.

Remove conditional rendering in favor of passing down the isOpen
property to the React <Modal> component.
Copy link

@LordRonz LordRonz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@igordanchenko
Copy link

I wouldn't keep my hopes too high for this PR to get merged. I submitted a trivial PR for the issue you mentioned above almost 3 months ago, but it still didn't get any attention from the maintainers. So I ended up releasing yet-another-react-lightbox.

@swquinn
Copy link
Author

swquinn commented Jun 29, 2022

@igordanchenko I'm happy to make this same PR against your yet-another-react-lightbox project as well.

I found it easier just to pull the code for this into the current Next.js blog project I have rather than rely on additional dependencies so this not getting merged in isn't a blocker for me--but I thought I would contribute back to the community. Hopefully someone sees the value in this and approves the CI workflow and merges it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants