-
Notifications
You must be signed in to change notification settings - Fork 808
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
DataSync: Cancel all previous mutations upon new mutation of same key #41472
base: trunk
Are you sure you want to change the base?
DataSync: Cancel all previous mutations upon new mutation of same key #41472
Conversation
…client/react-query-devtools
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Follow this PR Review Process:
Still unsure? Reach out in #jetpack-developers for guidance! Boost plugin:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
…ion' of github.com:Automattic/jetpack into fix/react-data-sync-client/boost-settings-racing-condition
Code Coverage SummaryCoverage changed in 1 file.
|
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.
Perfect! I am a bit unsure if we still need to useRef
for the abort controller. If we do, LGTM.
@@ -98,6 +99,14 @@ export function useDataSync< | |||
const abortController = useRef< AbortController | null >( null ); |
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.
Do we still need to use a ref now that it's part of the mutation state?
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.
Good point! After thinking about it further, we don't, and can fully leverage React Query for this instead. I've updated the PR to reflect this.
queryClient.getMutationDefaults( queryKey )?.meta?.abortController as AbortController; | ||
const getAbortController = () => { | ||
const defaults = queryClient.getMutationDefaults( queryKey ); | ||
return defaults?.meta?.abortController instanceof AbortController |
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.
Per discussion with @dilirity, this avoids unnecessary type casts. Thanks for pushing this!
Fixes #40642
Proposed changes:
Other information:
Jetpack product discussion
N/A
Does this pull request change what data or activity we track or use?
N/A
Testing instructions:
With changes: Features that are toggled quickly persist their new toggled status.
Without changes: Features that are toggled quickly have their toggle switched inadvertently.
See below demo for applied changes.
Screen.Recording.2025-01-31.at.17.02.09.mov