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.
useWatchedQuerySuspenseSubscription
is called. We create a temporary hold and suspend the component during loading.useWatchedQuerySuspenseSubscription
which callsuseTemporaryHold
- since the query is not loading, we don't need to create a temporary hold. We return a no-opreleaseHold
method (we don't assign it to thereleaseTemporaryHold
Ref since it's a no-op).useWatchedQuerySuspenseSubscription
is eventually triggered, we get the value Ref value ofreleaseTemporaryHold
(which has not been assigned). We then enter the useEffect inuseWatchedQuerySuspenseSubscription
and 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 == true
and throw the pending promise which triggers suspense. Throwing this promise will not trigger theuseEffect
in this "render".Once the promise resolves React's suspense will reinvoke
useWatchedQuerySuspenseSubscription
(without any previous state). CallinguseTemporaryHold
will not create a temporary hold since the WatchedQuery is no longer in the loading state. TheuseEffect
will 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
useWatchedQuerySuspenseSubscription
where theuseEffect
was triggered, but removing this unnecessary check avoids this issue entirely.The
should suspend on initial load
test 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.