react-modal-global icon indicating copy to clipboard operation
react-modal-global copied to clipboard

Add a `keepMounted` option

Open FrameMuse opened this issue 2 years ago • 4 comments

Motivation

By default, all modals continue to be mounted even when they are closed. Despite of that it's giving some advantages, sometimes it may be required to unmount it.

For example, the modal can contain a state machine that will continue working after closure, which may be unintentional.

Description

keepMounted will be added to ModalParams, so developers can disable it for single modal or all modals by default.

Example 1

Modal.open(Component, { keepMounted: false })

Example 2

const Modal = new ModalController({
  default: { keepMounted: false }
})
Modal.open(Component)

These two modals will have the same behavior.

FrameMuse avatar Mar 29 '23 06:03 FrameMuse

This is related to caching.

FrameMuse avatar May 18 '23 20:05 FrameMuse

Hi! I really really need that feature, how can i help?

dientuki avatar Aug 24 '24 05:08 dientuki

@dientuki Hi, sorry for a late response, I actually wanted to work on this feature when new React Visibility API is fully there.

But we can start working on it now.

What we need is to make sure the component is mounted while not visible, we can probably use hidden attribute or display: none style.

But this feature will be a breaking change since, it makes ANY component to be always mounted, so I believe we should set keepMounted to false by default.

  • If this is overridden to true in the default settings, it should keep mounted all open components
  • If this is overridden to true in the local open params, it should keep mounted the opened component

Hope this helps, I'm currently busy with other staff, so hope you'll figure out how to implement this yourself. I will try to review the PR ASAP.

FrameMuse avatar Aug 25 '24 19:08 FrameMuse

Related to https://github.com/FrameMuse/react-modal-global/issues/258

FrameMuse avatar Aug 25 '24 19:08 FrameMuse