React 19 Fixes#688
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 04d35ce The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 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 |
stevensJourney
commented
Aug 7, 2025
Chriztiaan
approved these changes
Aug 7, 2025
whygee-dev
pushed a commit
to whygee-dev/powersync-js
that referenced
this pull request
Oct 18, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Closes #687
I have only been able to reproduce the issue above when using React 19 in Strict mode.
It seems like the flow is as follows.
useWatchedQuerySuspenseSubscriptionis called. We create a temporary hold and suspend the component during loading.useWatchedQuerySuspenseSubscriptionwhich callsuseTemporaryHold- since the query is not loading, we don't need to create a temporary hold. We return a no-opreleaseHoldmethod (we don't assign it to thereleaseTemporaryHoldRef since it's a no-op).useWatchedQuerySuspenseSubscriptionis eventually triggered, we get the value Ref value ofreleaseTemporaryHold(which has not been assigned). We then enter the useEffect inuseWatchedQuerySuspenseSubscriptionand attempt to release using the undefined method.Generally the current implementation is unnecessarily flawed. We cannot feasibly remove the temporary hold from
useWatchedQuerySuspenseSubscription. We have to rely on the polling to remove this.There are primarily 2 scenarios
If the WatchedQuery is loading on the first render:
During the initial render (while the query is loading). We will detect
isLoading == trueand throw the pending promise which triggers suspense. Throwing this promise will not trigger theuseEffectin this "render".Once the promise resolves React's suspense will reinvoke
useWatchedQuerySuspenseSubscription(without any previous state). CallinguseTemporaryHoldwill not create a temporary hold since the WatchedQuery is no longer in the loading state. TheuseEffectwill run, but releasing would be a no-op.If the supplied WatchedQuery was already loaded on the first render:
We will not suspend or create any temporary hold. There is nothing to release in the
useWatchedQuerySuspenseSubscription::useEffect.I'm not entirely sure why React 19 Strict mode triggered the third invocation of
useWatchedQuerySuspenseSubscriptionwhere theuseEffectwas triggered, but removing this unnecessary check avoids this issue entirely.The
should suspend on initial loadtest ensures that temporary holds are removed correctly.I manually verified that the unit tests pass when using React 19. This required manually extracting the unit tests from the Monorepo. We should eventually update React in this monorepo.