-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
useDisplayOrder: clears incorrect #6000
Comments
Thanks for the report. I improved closeOnEscape logic on a few components including this one. |
Thanks @melloware , this fixes the problem for me. I think the useDisplayOrder code should be fixed too, since it could still happen when closeOnEscape is true. |
well what is weird is I can't reproduce your error with the showcase. Now showcase is Next.Js not sure if that makes a difference or not. Want to suggest a PR? |
Changing the I think it should work by changing I could create a PR later today if you want. |
let me try that. And no in using the showcase i can't get it to error! |
@Manizuca can you check out my new PR it refactors how that is done...
This version should be cleaner and more concise while maintaining the same functionality. |
Describe the bug
The useDisplayOrder hooks clears out an incorrect id when unmounting, so very simple Dialogs configurations throw "Unexpected: global esc key listener with priority [300, x] already exists." errors", even if not using the 'closeOnEscape' option (if they are not destroyed in the reverse order they become visible).
primereact/components/lib/hooks/useDisplayOrder.js
Line 22 in d5625fe
Here, the information is deleted taking the generated displayOrder as an index, but that will always be off by 1.
In the attached example, te following happens in this order:
Finally, because there are two visible Dialogs with displayOrder 2, the application crashes.
The fix should be pretty trivial, just delete the item with index
newDisplayOrder - 1
. Also, i think the global Esc handler should not be added ifcloseOnEscape
isfalse
.Reproducer
https://stackblitz.com/edit/vitejs-vite-e88fmg
PrimeReact version
10.5.1
React version
17.x
Language
ES6
Build / Runtime
Create React App (CRA)
Browser(s)
No response
Steps to reproduce the behavior
Just load the page, and look for the "Unexpected: global esc key listener with priority [300, 2] already exists." error.
Expected behavior
Should not crash.
The text was updated successfully, but these errors were encountered: