toss / overlay-kit

The simplest and most intuitive way to manage overlays in React.
https://overlay-kit.slash.page
MIT License
295 stars 30 forks source link

[Bug] Unexpected Component Reset on Reopening Overlays without Unmounting #57

Closed jungpaeng closed 4 months ago

jungpaeng commented 4 months ago

Issue Description:

While working with the overlay system, I noticed an unexpected behavior where overlays do not maintain their state upon being reopened after a close action, despite not being removed from the DOM.

This behavior deviates from the expected functionality where overlays should retain their state between close and reopen actions when not explicitly unmounted.

Expected Behavior:

When an overlay is closed (without unmounting) and then reopened, it should retain its previous state and appear as it was before being closed. This expected behavior is demonstrated in the attached video.

https://github.com/user-attachments/assets/7437ac6d-5942-4445-af47-bf0f2621cd08

Current Behavior:

Currently, overlays reset to their initial state when reopened after being closed, regardless of whether they were removed from the DOM. This issue is evident as the component appears to reinitialize, losing any state it previously held. The problem is illustrated in the attached video.

https://github.com/user-attachments/assets/f5a82051-83f5-47a8-b6fa-8fa619d07d87

Steps to Reproduce:

  1. Open an overlay using overlay.open().
  2. Close the overlay without unmounting it.
  3. Reopen the same overlay.
  4. Observe that the overlay resets to its initial state instead of retaining the state from before the close.

Proposed Solution:

This issue may be stemming from an inadvertent update of overlayData within the overlayReducer during the reopening of an overlay. It is crucial to ensure that the overlayData remains unchanged if an overlay is closed but not unmounted, to maintain its state across open/close cycles.

Additional Context:

This issue was discovered while implementing a feature intended to reuse overlays efficiently. The expected and current behaviors have been documented through video examples to aid in understanding the issue clearly.

Originally posted by @jungpaeng in https://github.com/toss/overlay-kit/issues/55#issuecomment-2227301041