Skip to content

Conversation

simolus3
Copy link
Contributor

As per the React documentation, useMemo should receive a constant-length array of dependencies:

The list of dependencies must have a constant number of items and be written inline like [dep1, dep2, dep3]

Since we're currently passing parameters of the query to that hook (which can change when e.g. SQL and parameters are changed at once), React may emit a warning about "The final argument passed to useMemo changed size between renders. The order and size of this array must remain constant".

I think that warning is harmless, but it's still something we should consider fixing.

So, this resolves that warning by:

  1. Stringifying parameters and using that representation as a dependency instead.
  2. To make up for that inefficiency, pass the stringified representation to checkQueryChanged to avoid recomputing it there.

Copy link

changeset-bot bot commented Sep 22, 2025

🦋 Changeset detected

Latest commit: bb76a66

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

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

Copy link
Collaborator

@stevensJourney stevensJourney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thanks for fixing this!

@simolus3 simolus3 merged commit d8236aa into main Sep 22, 2025
9 checks passed
@simolus3 simolus3 deleted the react-fix-dynamic-dependency-array branch September 22, 2025 09:46
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