Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Frank-vdm
Copy link

This prevents the 'spammy' useStatus behaviour
key changes:

  • explicitly compare the values in the SyncStatus object, its more performant than the JSON.stringify alternative this is important since this is triggered often
  • we use this isEqual in the usePowerSyncStatus hook to only update the state only when the value actually changes

Copy link

changeset-bot bot commented Dec 10, 2024

🦋 Changeset detected

Latest commit: 9d6b31b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@powersync/common Patch
@powersync/react Patch
@powersync/op-sqlite Patch
@powersync/react-native Patch
@powersync/tanstack-react-query Patch
@powersync/web Patch
@powersync/diagnostics-app Patch

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
Copy link
Collaborator

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.

Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants