Skip to content

Commit e7810a6

Browse files
remove functionality to release
1 parent 2a12094 commit e7810a6

File tree

3 files changed

+6
-25
lines changed

3 files changed

+6
-25
lines changed

packages/react/src/hooks/suspense/suspense-utils.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
11
import { WatchedQuery } from '@powersync/common';
22
import React from 'react';
33

4-
const NO_OP_RELEASE = () => {};
5-
64
/**
75
* The store will dispose this query if it has no subscribers attached to it.
86
* The suspense promise adds a subscriber to the query, but the promise could resolve
97
* before this component is committed. The promise will release it's listener once the query is no longer loading.
108
* This temporary hold is used to ensure that the query is not disposed in the interim.
119
* Creates a subscription for state change which creates a temporary hold on the query
12-
* @returns a function to release the hold
1310
*/
1411
export const useTemporaryHold = (watchedQuery?: WatchedQuery<unknown>) => {
1512
// Defaults to a no-op. If the provided WatchedQuery is not loading, we don't need a
1613
// temporary hold.
17-
const releaseTemporaryHold = React.useRef<() => void>(NO_OP_RELEASE);
14+
const releaseTemporaryHold = React.useRef<() => void | undefined>(undefined);
1815
const addedHoldTo = React.useRef<WatchedQuery<unknown> | undefined>(undefined);
1916

2017
if (addedHoldTo.current !== watchedQuery) {
2118
// The query changed, we no longer need the previous hold if present
2219
releaseTemporaryHold.current?.();
23-
releaseTemporaryHold.current = NO_OP_RELEASE;
20+
releaseTemporaryHold.current = undefined;
2421
addedHoldTo.current = watchedQuery;
2522

2623
if (!watchedQuery || !watchedQuery.state.isLoading) {
27-
// No query to hold or no reason to hold, return a no-op
28-
return {
29-
releaseHold: releaseTemporaryHold.current
30-
};
24+
// No query to hold or no reason to hold, return
25+
return;
3126
}
3227

3328
// Create a hold by subscribing
@@ -67,10 +62,6 @@ export const useTemporaryHold = (watchedQuery?: WatchedQuery<unknown>) => {
6762
// Set a timeout to conditionally remove the temporary hold
6863
setTimeout(checkHold, timeoutPollMs);
6964
}
70-
71-
return {
72-
releaseHold: releaseTemporaryHold.current
73-
};
7465
};
7566

7667
/**

packages/react/src/hooks/suspense/useSingleSuspenseQuery.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const useSingleSuspenseQuery = <T = any>(
3737

3838
// Only use a temporary watched query if we don't have data yet.
3939
const watchedQuery = data ? null : (store.getQuery(key, parsedQuery, options) as WatchedQuery<T[]>);
40-
const { releaseHold } = useTemporaryHold(watchedQuery);
40+
useTemporaryHold(watchedQuery);
4141
React.useEffect(() => {
4242
// Set the initial yielded data
4343
// it should be available once we commit the component
@@ -47,10 +47,6 @@ export const useSingleSuspenseQuery = <T = any>(
4747
setData(watchedQuery.state.data);
4848
setError(null);
4949
}
50-
51-
if (!watchedQuery?.state.isLoading) {
52-
releaseHold();
53-
}
5450
}, []);
5551

5652
if (error != null) {

packages/react/src/hooks/suspense/useWatchedQuerySuspenseSubscription.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const useWatchedQuerySuspenseSubscription = <
2929
>(
3030
query: Query
3131
): Query['state'] => {
32-
const { releaseHold } = useTemporaryHold(query);
32+
useTemporaryHold(query);
3333

3434
// Force update state function
3535
const [, setUpdateCounter] = React.useState(0);
@@ -44,12 +44,6 @@ export const useWatchedQuerySuspenseSubscription = <
4444
}
4545
});
4646

47-
// This runs on the first iteration before the component is suspended
48-
// We should only release the hold once the component is no longer loading
49-
if (!query.state.isLoading) {
50-
releaseHold();
51-
}
52-
5347
return dispose;
5448
}, []);
5549

0 commit comments

Comments
 (0)