File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
packages/react/src/hooks/suspense Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @powersync/react ' : patch
3+ ---
4+
5+ Fixed regression in useSuspendingQuery where ` releaseHold is not a function ` could be thrown during hot reload or if the WatchedQuery ` loading ` state resolved before the first re-render.
Original file line number Diff line number Diff line change 11import { WatchedQuery } from '@powersync/common' ;
22import React from 'react' ;
33
4+ const NO_OP_RELEASE = ( ) => { } ;
5+
46/**
57 * The store will dispose this query if it has no subscribers attached to it.
68 * The suspense promise adds a subscriber to the query, but the promise could resolve
@@ -10,17 +12,20 @@ import React from 'react';
1012 * @returns a function to release the hold
1113 */
1214export const useTemporaryHold = ( watchedQuery ?: WatchedQuery < unknown > ) => {
13- const releaseTemporaryHold = React . useRef < ( ( ) => void ) | undefined > ( undefined ) ;
15+ // Defaults to a no-op. If the provided WatchedQuery is not loading, we don't need a
16+ // temporary hold.
17+ const releaseTemporaryHold = React . useRef < ( ) => void > ( NO_OP_RELEASE ) ;
1418 const addedHoldTo = React . useRef < WatchedQuery < unknown > | undefined > ( undefined ) ;
1519
1620 if ( addedHoldTo . current !== watchedQuery ) {
1721 releaseTemporaryHold . current ?.( ) ;
22+ releaseTemporaryHold . current = NO_OP_RELEASE ;
1823 addedHoldTo . current = watchedQuery ;
1924
2025 if ( ! watchedQuery || ! watchedQuery . state . isLoading ) {
2126 // No query to hold or no reason to hold, return a no-op
2227 return {
23- releaseHold : ( ) => { }
28+ releaseHold : releaseTemporaryHold . current
2429 } ;
2530 }
2631
You can’t perform that action at this time.
0 commit comments