Skip to content

Conversation

@jungpaeng
Copy link
Member

@jungpaeng jungpaeng commented Jul 7, 2025

Description

This PR fixes a bug where overlays could not be reopened after being closed when using the same overlay ID. The issue occurred because the overlay state management didn't properly handle the case where an overlay was closed and then reopened with the same identifier.

Related Issue: Fixes #186

Changes

  • Added isMounted property to OverlayItem type to track overlay mounting state
  • Modified the ADD action in reducer to handle reopening of existing closed overlays
  • Added state comparison logic in OverlayProvider to detect overlay state changes and trigger proper reopening
  • Updated OPEN action to set isMounted: true when opening overlays
  • Added useRef to track previous overlay state for comparison
  • Restructured overlay controller props order and import statements for consistency
  • Added comprehensive test case for overlay close and reopen functionality

Motivation and Context

Previously, when an overlay was closed and then reopened with the same overlay ID, the overlay would not properly display again. This was because the overlay state management system didn't distinguish between completely new overlays and overlays that were being reopened after being closed. The system would skip the reopening process for existing overlay IDs, even if they were in a closed state.

This fix ensures that:

  1. Overlays can be properly reopened after being closed
  2. The mounting state is correctly tracked and managed
  3. State transitions are properly handled through animation frames to ensure smooth UI updates

How Has This Been Tested?

  • Added a comprehensive unit test that verifies overlay close and reopen functionality
  • The test creates an overlay, opens it, verifies it's visible, closes it, verifies it's hidden, then reopens it with the same ID and verifies it's visible again
  • Tested with multiple overlay scenarios to ensure no regression in existing functionality
  • Verified that overlay state management works correctly across different React versions (16, 17, 18, 19)
  • Manual testing confirmed smooth transitions and proper overlay behavior

Screenshots (if appropriate):

N/A - This is a functional bug fix without visual changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have performed a self-review of my own code.
  • My code is commented, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • Any dependent changes have been merged and published in downstream modules.

Further Comments

This fix addresses a critical issue that could affect user experience when working with modal/overlay patterns. The solution maintains backward compatibility while ensuring proper state management for overlay reopening scenarios.

@jungpaeng jungpaeng self-assigned this Jul 7, 2025
@changeset-bot
Copy link

changeset-bot bot commented Jul 7, 2025

🦋 Changeset detected

Latest commit: 5681fe1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
overlay-kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jul 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
overlay-kit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 7, 2025 9:03am

@codecov-commenter
Copy link

codecov-commenter commented Jul 7, 2025

Codecov Report

Attention: Patch coverage is 92.10526% with 3 lines in your changes missing coverage. Please review.

Project coverage is 93.55%. Comparing base (cc91ab2) to head (5681fe1).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #187      +/-   ##
==========================================
- Coverage   93.99%   93.55%   -0.44%     
==========================================
  Files          12       12              
  Lines         333      357      +24     
  Branches       80       88       +8     
==========================================
+ Hits          313      334      +21     
- Misses         19       22       +3     
  Partials        1        1              
Components Coverage Δ
overlay-kit 93.55% <92.10%> (-0.44%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jungpaeng jungpaeng marked this pull request as ready for review July 7, 2025 08:47
@jungpaeng jungpaeng force-pushed the fix/close-modal-reopen branch from 6677660 to 5681fe1 Compare July 7, 2025 09:02
@jungpaeng jungpaeng merged commit c3dfcf1 into main Jul 7, 2025
8 checks passed
@jungpaeng jungpaeng deleted the fix/close-modal-reopen branch July 7, 2025 09:03
@github-actions github-actions bot mentioned this pull request Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Overlay closed with close cannot be reopened.

3 participants