-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: Prevent ADD
action if the custom-id already exists.
#46
Comments
This issue occurs even if not calling 2024-07-11.22.50.36.movAs @jgjgill said, that is because every calling
|
I understand why this issue is occurring. Since While returning the state as-is when So, I think it would be better to throw an error to make it clear that this is not the correct usage. Additionally, we should update the documentation to inform users not to open the same custom ID multiple times. What do you think? |
Yeah, I agree with you. If returning the as-is state with the same overlay key, it could be possible. 🤔
Btw, this warning occurs when below senario:
I think this case could be correct and possible. As a video in my comment above, it shows the above case. How about this workaround? But I didn't try it so please check it out. case 'ADD': {
const isExisted = state.overlayOrderList.includes(action.overlay.id);
return {
current: action.overlay.id,
overlayOrderList: isExisted ? state.overlayOrderList : [...state.overlayOrderList, action.overlay.id],
overlayData: {
...state.overlayData,
[action.overlay.id]: action.overlay,
},
};
} |
Oh, I didn't think about the user and focused on eliminating errors. 😂 So maybe the code would look something like this? reducer.ts case 'ADD': {
if (state.overlayOrderList.includes(action.overlay.id)) {
throw new Error('The same overlayId exists.');
}
... Expected behavior 2024-07-12.5.39.59.mov |
@ojj1123 On the other hand, as the discussion progressed, I realized that the behavior of opening the same |
Yeah I don't think that "open and open repeatly" is the intended use case.
|
This seems to be an example of that comment. I think it's right to throw the error. |
I'm outside right now, so I can't write in detail, but I wanted to leave a brief note. Thank you very much for your interest and for proposing a solution. First, we need to prevent opening an overlay without closing it first. In this case, it seems appropriate to return an error. However, reopening an overlay without unmounting it after closing should work. There are cases where not unmounting intentionally is done for performance optimization reasons. Therefore, in the ADD phase of the reducer, we need to check if the overlay currently exists in overlayData and refer to the value of isOpen to make appropriate modifications. I'll revisit this issue later. Thank you once again. |
Ah, I understand. I was misunderstanding the problem situation (performance optimization) 😂. Thanks for the quick feedback. |
Problem situation
When specifying
custom-id
separately onoverlay.open
, multiple occurrences of that event will result in an error.Example code
Demo
2024-07-11.8.34.23.mov
Cause of the problem
This appears to be caused by the same
overlayId
already existing in theoverlayOrderList
.Workaround
I thought of adding the following code in the
ADD
action.If the
overlayId
already exists, return the existingstate
.reducer.ts
Expected behavior
2024-07-11.8.42.15.mov
If you think the suggestion is appropriate, would you mind if I add a feature fix and test code? 🧐
The text was updated successfully, but these errors were encountered: