-
Notifications
You must be signed in to change notification settings - Fork 180
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
refactor(app): add test for shouldUseNotifications
false to true
#17870
Conversation
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.
the memoization happens on the caller-side rather than here, right? we should probably have a comment on this function saying that the callback should be memoized so its identity is stable between calls from the same location.
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.
Seems OK, but can you elaborate on this?
Also, we don't need to remove the callback every time shouldUseNotifications becomes false: we remove the callback on dismount.
if the bug was that flipping the feature flag on and off kept accumulating callbacks, isn't the problem that the callback wasn't being removed when the feature flag went off?
No, the problem is that every time If it flips to false, we don't have to remove it immediately, because when the component dismounts, the callback gets cleaned up. See L88.
|
I've looked more closely at the code and now I'm a little more confused. I'm looking at this calling code. If I understand correctly:
Because step 3i happens before step 7, how can there still be a callback in the store when we reach step 7? |
Ah, no, the |
I don't think that's true?
|
Ah, yep thanks. You're correct. I'll just merge the testing changes from this PR then 👍 |
shouldUseNotifications
false to true
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.
Cool, thanks for looking into this. LGTM if CI passes.
Thanks for being patient with me. It's been a week 😅 |
Overview
EDIT: See discussion below. Woops, we were already covered. Will just merge in the testing.
#17853 fixes an issue when the
shouldUseNotifications
flag is initiallyfalse
and then flips totrue
. We must also account for scenarios in which the caller repeatedly sets theshouldUseNotifications
flag betweenfalse
andtrue
: we do not want to add a new callback to the store every timeshouldUseNotifications
istrue
, only if it is not in the store already. Note that the callback added to the store is memoized, soincludes
is a sufficient filter check here. Also, we don't need to remove the callback every timeshouldUseNotifications
becomesfalse
: we remove the callback on dismount.This fix currently doesn't impact our codebase, fortunately. The one spot
shouldUseNotifications
flips is a one-timefalse
totrue
.This PR also adds testing for the earlier fix in the linked PR.
Test Plan and Hands on Testing
Risk assessment
low