Skip to content

Conversation

Chriztiaan
Copy link
Contributor

@Chriztiaan Chriztiaan commented Oct 7, 2024

An issue was found where if the query or parameters change for useQuery, there would be single render cycle where isFetching was false before it became true.

For example:

1. isFetching: false // query changed but the variable is still false
2. isFetching: true // state has been updated
3. isFetching: false // query has finished re-executing

This fix ensures that isFetching is correctly set to true as soon as the hook executes due to a query change.

1. isFetching: true // query change causes hook to execute, compare current query to new query - 
track with internal `shouldFetch` variable.
2. isFetching: true // state has been updated
3. isFetching: false // query has finished re-executing

Copy link

changeset-bot bot commented Oct 7, 2024

🦋 Changeset detected

Latest commit: 4d7b42f

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

This PR includes changesets to release 3 packages
Name Type
@powersync/react Patch
@powersync/react-native 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

@Chriztiaan Chriztiaan marked this pull request as ready for review October 7, 2024 14:59
@fooware
Copy link

fooware commented Oct 9, 2024

In our case, we had multiple renders with isFetching being incorrectly false in combination with the old stale data, probably due to us having multiple useQuery hooks firing and re-rendering things.

I have tested @Chriztiaan's changes locally, and the latest version in this PR resolves the issue for us.

@Chriztiaan Chriztiaan force-pushed the fix/react-is-fetching branch from 41ae097 to 4d7b42f Compare October 10, 2024 10:25
@Chriztiaan Chriztiaan merged commit f8ac369 into main Oct 10, 2024
5 checks passed
@Chriztiaan Chriztiaan deleted the fix/react-is-fetching branch October 10, 2024 12:14
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.

3 participants