-
Notifications
You must be signed in to change notification settings - Fork 35
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
chore: optimize the useStatus hook and underlying isEqual #438
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 9d6b31b The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
statusChanged: (newStatus) => { | ||
setSyncStatus(prev => { | ||
// Only update if the status is actually different | ||
return prev.isEqual(newStatus) ? prev : newStatus |
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 isEqual
check should already be implemented here which should only cause the statusChanged
listeners to be fired if the status actually changed. Is this necessary? If so there might be a different bug elsewhere.
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.
From my experience, when I use the useStatus hook from powersync my app refreshes every 5 seconds even if the status has not actually changed
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.
@Frank-vdm I tried to reproduce the sync status hook updating periodically with no actual sync status changes or to see if the statusChanged
listener was being fired when there was infact no change, but I could not really reproduce this. The only time I could (unreliably) reproduce was when making changes to the usePowerSyncStatus
hook code and hot reloading the application - which seems like an edge case which would not happen for users of the SDK.
Do you perhaps have any more information on how to reproduce this?
This prevents the 'spammy' useStatus behaviour
key changes:
JSON.stringify
alternative this is important since this is triggered often