Skip to content

Commit

Permalink
fix: state reset issue on overlay reopen (#58)
Browse files Browse the repository at this point in the history
* fix: state reset issue on overlay reopen

This commit modifies the overlayReducer to ensure that the overlayData does not get reset when an overlay is reopened without unmounting.

* Create tricky-grapes-bake.md
  • Loading branch information
jungpaeng authored Jul 14, 2024
1 parent 6f3c26a commit b35ac6f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 10 additions & 0 deletions .changeset/tricky-grapes-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"overlay-kit": patch
---

fix: state reset issue on overlay reopen

This change fixes an issue where overlays did not retain their state when reopened without unmounting, even though they were not removed from the DOM.
The overlayReducer has been updated to maintain the state of overlays between close and open cycles, addressing an unintended state reset.

Related Issue: Fixes #57
10 changes: 6 additions & 4 deletions packages/src/context/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ export function overlayReducer(state: OverlayData, action: OverlayReducerAction)
* @description Brings the overlay to the front when reopened after closing without unmounting.
*/
overlayOrderList: [...state.overlayOrderList.filter((item) => item !== action.overlay.id), action.overlay.id],
overlayData: {
...state.overlayData,
[action.overlay.id]: action.overlay,
},
overlayData: isExisted
? state.overlayData
: {
...state.overlayData,
[action.overlay.id]: action.overlay,
},
};
}
case 'OPEN': {
Expand Down

0 comments on commit b35ac6f

Please sign in to comment.