Skip to content

Commit

Permalink
fix(solid-query): Resolve resource before unmounting query (#7279)
Browse files Browse the repository at this point in the history
  • Loading branch information
ardeora committed Apr 15, 2024
1 parent 8469951 commit d384cac
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/solid-query/src/createBaseQuery.ts
Expand Up @@ -236,10 +236,19 @@ export function createBaseQuery<
*/
let unsubscribe: (() => void) | null = null

/*
Fixes #7275
In a few cases, the observer could unmount before the resource is loaded.
This leads to Suspense boundaries to be suspended indefinitely.
This resolver will be called when the observer is unmounting
but the resource is still in a loading state
*/
let resolver: ((value: ResourceData) => void) | null = null
const [queryResource, { refetch }] = createResource<ResourceData | undefined>(
() => {
const obs = observer()
return new Promise((resolve, reject) => {
resolver = resolve
if (isServer) {
unsubscribe = createServerSubscriber(resolve, reject)
} else if (!unsubscribe && !isRestoring()) {
Expand All @@ -261,6 +270,7 @@ export function createBaseQuery<
}
if (!observerResult.isLoading) {
const query = obs.getCurrentQuery()
resolver = null
return resolve(hydratableObserverResult(query, observerResult))
}

Expand Down Expand Up @@ -354,6 +364,10 @@ export function createBaseQuery<
unsubscribe()
unsubscribe = null
}
if (resolver && !isServer) {
resolver(observerResult)
resolver = null
}
})

createComputed(
Expand Down

0 comments on commit d384cac

Please sign in to comment.