Skip to content

Commit b35ac6f

Browse files
authored
fix: state reset issue on overlay reopen (#58)
* 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
1 parent 6f3c26a commit b35ac6f

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

.changeset/tricky-grapes-bake.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"overlay-kit": patch
3+
---
4+
5+
fix: state reset issue on overlay reopen
6+
7+
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.
8+
The overlayReducer has been updated to maintain the state of overlays between close and open cycles, addressing an unintended state reset.
9+
10+
Related Issue: Fixes #57

packages/src/context/reducer.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ export function overlayReducer(state: OverlayData, action: OverlayReducerAction)
2323
* @description Brings the overlay to the front when reopened after closing without unmounting.
2424
*/
2525
overlayOrderList: [...state.overlayOrderList.filter((item) => item !== action.overlay.id), action.overlay.id],
26-
overlayData: {
27-
...state.overlayData,
28-
[action.overlay.id]: action.overlay,
29-
},
26+
overlayData: isExisted
27+
? state.overlayData
28+
: {
29+
...state.overlayData,
30+
[action.overlay.id]: action.overlay,
31+
},
3032
};
3133
}
3234
case 'OPEN': {

0 commit comments

Comments
 (0)