-
Notifications
You must be signed in to change notification settings - Fork 280
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
fix: do not clear dialog state immediately on useDialog unmount #2584
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2584 +/- ##
=======================================
Coverage 81.14% 81.15%
=======================================
Files 448 448
Lines 9460 9470 +10
Branches 2316 2319 +3
=======================================
+ Hits 7676 7685 +9
- Misses 1422 1423 +1
Partials 362 362 ☔ View full report in Codecov by Sentry. |
Size Change: +892 B (+0.08%) Total Size: 1.19 MB
ℹ️ View Unchanged
|
removalTimeout: setTimeout(() => { | ||
this.remove(id); | ||
}, 16), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍒
dialogManager.remove(id); | ||
// Since this cleanup can run even if the component is still mounted | ||
// and dialog id is unchanged (e.g. in <StrictMode />), it's safer to | ||
// mark state as unused and only remove it after a timeout, rather than | ||
// to remove it immediately. | ||
dialogManager.markForRemoval(id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍓
<StrictMode> | ||
<App /> | ||
</StrictMode>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good to run demo apps in <StrictMode />
:)
@@ -257,7 +257,7 @@ | |||
"react-dom": "^18.1.0", | |||
"react-test-renderer": "^18.1.0", | |||
"semantic-release": "^19.0.5", | |||
"stream-chat": "^8.46.1", | |||
"stream-chat": "^8.47.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, bump stream-chat
version to incorporate recent <StrictMode />
-related fixes in the client (GetStream/stream-chat-js#1421).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @myandrienko 🙏
🎉 This PR is included in version 12.8.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎯 Goal
When the
useDialog
hook's component unmounts, it immediately clears dialog state in an effect cleanup. However, in some situations an effect cleanup can run even if the hook's component is still mounted and effect's dependencies didn't change - e.g., when<StrictMode />
is enabled.So it's safer to keep dialog state for a short time after cleanup runs.
🛠 Implementation details
Instead of immediately removing dialog state, it's marked to be removed after a short timeout. Referencing the dialog again quick cancels state removal.
Fixes #2583.