Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Non resolving promises created when query is not enabled #8629

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/solid-query/src/createBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,27 @@ export function createBaseQuery<
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
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()

if(obs.options.enabled === false){
// Just in case, unsubscribe from observer if we did subscribe
if(unsubscribe){
unsubscribe()
}

// Use the default/previous state when not enabled
// Remove the promise since it's not serializable by seroval in case we're on the server
const { promise, ...rest } = hydratableObserverResult(obs.getCurrentQuery(), state)

return rest
}

return new Promise((resolve, reject) => {
resolver = resolve
if (isServer) {
Expand Down