diff --git a/packages/solid-query/package.json b/packages/solid-query/package.json index 79030ff54c..3b757c9865 100644 --- a/packages/solid-query/package.json +++ b/packages/solid-query/package.json @@ -69,6 +69,7 @@ }, "devDependencies": { "@solidjs/testing-library": "^0.8.10", + "@solidjs/router": "^0.15.3", "npm-run-all2": "^5.0.0", "solid-js": "^1.9.5", "tsup-preset-solid": "^2.2.0", diff --git a/packages/solid-query/src/__tests__/useQuery.test.tsx b/packages/solid-query/src/__tests__/useQuery.test.tsx index 70914603b7..9ea6f6520e 100644 --- a/packages/solid-query/src/__tests__/useQuery.test.tsx +++ b/packages/solid-query/src/__tests__/useQuery.test.tsx @@ -2,6 +2,7 @@ import { describe, expect, expectTypeOf, it, vi } from 'vitest' import { ErrorBoundary, Match, + Suspense, Switch, createEffect, createMemo, @@ -11,6 +12,7 @@ import { } from 'solid-js' import { fireEvent, render, waitFor } from '@solidjs/testing-library' import { reconcile } from 'solid-js/store' +import { MemoryRouter, Route, createMemoryHistory } from '@solidjs/router' import { QueryCache, QueryClientProvider, keepPreviousData, useQuery } from '..' import { Blink, @@ -6045,4 +6047,79 @@ describe('useQuery', () => { await waitFor(() => rendered.getByText('Status: custom client')) }) + + // See https://github.com/tannerlinsley/react-query/issues/8469 + it('should correctly manage dependent queries', async () => { + const queryCache = new QueryCache() + const queryClient = createQueryClient({ queryCache }) + + const history = createMemoryHistory() + + const errorHandler = vi.fn<(err: unknown) => void>() + + function App() { + return ( + { + errorHandler(err) + return err.message + }} + > + + + + + + + + ) + } + + queryClient.setQueryData(['parent'], { id: 123 }) + + function Index() { + return 'Index' + } + + function Sub() { + const parent = useQuery(() => ({ + queryKey: ['parent'], + async queryFn() { + await new Promise((r) => setTimeout(r, 100)) + return { + id: 123, + } + }, + })) + + const childQuery = useQuery(() => ({ + queryKey: ['sub', parent.data?.id], + async queryFn() { + await new Promise((r) => setTimeout(r, 200)) + return Promise.resolve('child' + parent.data?.id) + }, + })) + return
{childQuery.data}
+ } + + const rendered = render(() => ( + + + + )) + + await waitFor(() => rendered.getByText('Index')) + + history.set({ + value: '/sub', + }) + + await sleep(200) + + expect(errorHandler).not.toHaveBeenCalled() + + await waitFor(() => { + expect(rendered.getByText('child123')).toBeInTheDocument() + }) + }) }) diff --git a/packages/solid-query/src/useBaseQuery.ts b/packages/solid-query/src/useBaseQuery.ts index 0b504ed0a7..d6b967831c 100644 --- a/packages/solid-query/src/useBaseQuery.ts +++ b/packages/solid-query/src/useBaseQuery.ts @@ -116,7 +116,11 @@ export function useBaseQuery< ) { type ResourceData = QueryObserverResult - const client = createMemo(() => useQueryClient(queryClient?.())) + const client = createMemo( + () => useQueryClient(queryClient?.()), + useQueryClient(queryClient?.()), + ) + const isRestoring = useIsRestoring() // There are times when we run a query on the server but the resource is never read // This could lead to times when the queryObserver is unsubscribed before the resource has loaded diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c961b7bd5e..880e8169c2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2046,7 +2046,7 @@ importers: devDependencies: '@angular-devkit/build-angular': specifier: ^19.2.5 - version: 19.2.5(@angular/compiler-cli@19.2.4(@angular/compiler@19.2.4)(typescript@5.8.3))(@angular/compiler@19.2.4)(@types/node@22.14.1)(chokidar@4.0.3)(html-webpack-plugin@5.6.3(webpack@5.98.0(esbuild@0.25.1)))(jiti@2.4.2)(lightningcss@1.29.2)(tailwindcss@4.0.14)(typescript@5.8.3)(vite@6.2.6(@types/node@22.14.1)(jiti@2.4.2)(less@4.2.2)(lightningcss@1.29.2)(sass@1.85.0)(terser@5.39.0)(yaml@2.6.1))(yaml@2.6.1) + version: 19.2.5(@angular/compiler-cli@19.2.4(@angular/compiler@19.2.4)(typescript@5.8.2))(@angular/compiler@19.2.4)(@types/node@22.14.0)(chokidar@4.0.3)(html-webpack-plugin@5.6.3(webpack@5.98.0(esbuild@0.25.1)))(jiti@2.4.2)(lightningcss@1.29.2)(tailwindcss@4.0.14)(typescript@5.8.2)(vite@6.2.5(@types/node@22.14.0)(jiti@2.4.2)(less@4.2.2)(lightningcss@1.29.2)(sass@1.85.0)(terser@5.39.0)(yaml@2.6.1))(yaml@2.6.1) '@angular/cli': specifier: ^19.2.5 version: 19.2.5(@types/node@22.14.1)(chokidar@4.0.3) @@ -2606,6 +2606,9 @@ importers: packages/solid-query: dependencies: + '@solidjs/router': + specifier: ^0.15.3 + version: 0.15.3(solid-js@1.9.5) '@tanstack/query-core': specifier: workspace:* version: link:../query-core @@ -16011,11 +16014,11 @@ snapshots: transitivePeerDependencies: - chokidar - '@angular-devkit/build-angular@19.2.5(@angular/compiler-cli@19.2.4(@angular/compiler@19.2.4)(typescript@5.8.3))(@angular/compiler@19.2.4)(@types/node@22.14.1)(chokidar@4.0.3)(html-webpack-plugin@5.6.3(webpack@5.98.0(esbuild@0.25.1)))(jiti@2.4.2)(lightningcss@1.29.2)(tailwindcss@4.0.14)(typescript@5.8.3)(vite@6.2.6(@types/node@22.14.1)(jiti@2.4.2)(less@4.2.2)(lightningcss@1.29.2)(sass@1.85.0)(terser@5.39.0)(yaml@2.6.1))(yaml@2.6.1)': + '@angular-devkit/build-angular@19.2.5(@angular/compiler-cli@19.2.4(@angular/compiler@19.2.4)(typescript@5.8.2))(@angular/compiler@19.2.4)(@types/node@22.14.0)(chokidar@4.0.3)(html-webpack-plugin@5.6.3(webpack@5.98.0(esbuild@0.25.1)))(jiti@2.4.2)(lightningcss@1.29.2)(tailwindcss@4.0.14)(typescript@5.8.2)(vite@6.2.5(@types/node@22.14.0)(jiti@2.4.2)(less@4.2.2)(lightningcss@1.29.2)(sass@1.85.0)(terser@5.39.0)(yaml@2.6.1))(yaml@2.6.1)': dependencies: '@ampproject/remapping': 2.3.0 '@angular-devkit/architect': 0.1902.5(chokidar@4.0.3) - '@angular-devkit/build-webpack': 0.1902.5(chokidar@4.0.3)(webpack-dev-server@5.2.0(webpack@5.98.0(esbuild@0.25.1)))(webpack@5.98.0(esbuild@0.25.1)) + '@angular-devkit/build-webpack': 0.1902.5(chokidar@4.0.3)(webpack-dev-server@5.2.0(webpack@5.98.0(esbuild@0.25.2)))(webpack@5.98.0(esbuild@0.25.1)) '@angular-devkit/core': 19.2.5(chokidar@4.0.3) '@angular/build': 19.2.5(@angular/compiler-cli@19.2.4(@angular/compiler@19.2.4)(typescript@5.8.3))(@angular/compiler@19.2.4)(@types/node@22.14.1)(chokidar@4.0.3)(jiti@2.4.2)(less@4.2.2)(lightningcss@1.29.2)(postcss@8.5.2)(tailwindcss@4.0.14)(terser@5.39.0)(typescript@5.8.3)(yaml@2.6.1) '@angular/compiler-cli': 19.2.4(@angular/compiler@19.2.4)(typescript@5.8.3) @@ -16064,12 +16067,12 @@ snapshots: terser: 5.39.0 tree-kill: 1.2.2 tslib: 2.8.1 - typescript: 5.8.3 + typescript: 5.8.2 webpack: 5.98.0(esbuild@0.25.1) webpack-dev-middleware: 7.4.2(webpack@5.98.0(esbuild@0.25.1)) webpack-dev-server: 5.2.0(webpack@5.98.0(esbuild@0.25.1)) webpack-merge: 6.0.1 - webpack-subresource-integrity: 5.1.0(html-webpack-plugin@5.6.3(webpack@5.98.0(esbuild@0.25.1)))(webpack@5.98.0(esbuild@0.25.1)) + webpack-subresource-integrity: 5.1.0(html-webpack-plugin@5.6.3(webpack@5.98.0(esbuild@0.25.2)))(webpack@5.98.0(esbuild@0.25.1)) optionalDependencies: esbuild: 0.25.1 tailwindcss: 4.0.14 @@ -16096,12 +16099,12 @@ snapshots: - webpack-cli - yaml - '@angular-devkit/build-webpack@0.1902.5(chokidar@4.0.3)(webpack-dev-server@5.2.0(webpack@5.98.0(esbuild@0.25.1)))(webpack@5.98.0(esbuild@0.25.1))': + '@angular-devkit/build-webpack@0.1902.5(chokidar@4.0.3)(webpack-dev-server@5.2.0(webpack@5.98.0(esbuild@0.25.2)))(webpack@5.98.0(esbuild@0.25.1))': dependencies: '@angular-devkit/architect': 0.1902.5(chokidar@4.0.3) rxjs: 7.8.1 - webpack: 5.98.0(esbuild@0.25.1) - webpack-dev-server: 5.2.0(webpack@5.98.0(esbuild@0.25.1)) + webpack: 5.98.0(esbuild@0.25.2) + webpack-dev-server: 5.2.0(webpack@5.98.0(esbuild@0.25.2)) transitivePeerDependencies: - chokidar @@ -19314,8 +19317,8 @@ snapshots: '@ngtools/webpack@19.2.5(@angular/compiler-cli@19.2.4(@angular/compiler@19.2.4)(typescript@5.8.3))(typescript@5.8.3)(webpack@5.98.0(esbuild@0.25.1))': dependencies: - '@angular/compiler-cli': 19.2.4(@angular/compiler@19.2.4)(typescript@5.8.3) - typescript: 5.8.3 + '@angular/compiler-cli': 19.2.4(@angular/compiler@19.2.4)(typescript@5.8.2) + typescript: 5.8.2 webpack: 5.98.0(esbuild@0.25.1) '@nodelib/fs.scandir@2.1.5': @@ -21964,7 +21967,7 @@ snapshots: '@babel/core': 7.26.10 find-cache-dir: 4.0.0 schema-utils: 4.3.0 - webpack: 5.98.0(esbuild@0.25.1) + webpack: 5.98.0(esbuild@0.25.2) babel-loader@9.2.1(@babel/core@7.26.10)(webpack@5.98.0): dependencies: @@ -22898,7 +22901,7 @@ snapshots: normalize-path: 3.0.0 schema-utils: 4.3.0 serialize-javascript: 6.0.2 - webpack: 5.98.0(esbuild@0.25.1) + webpack: 5.98.0(esbuild@0.25.2) core-js-compat@3.40.0: dependencies: @@ -23111,7 +23114,7 @@ snapshots: postcss-value-parser: 4.2.0 semver: 7.7.1 optionalDependencies: - webpack: 5.98.0(esbuild@0.25.1) + webpack: 5.98.0(esbuild@0.25.2) css-select@4.3.0: dependencies: @@ -25124,7 +25127,7 @@ snapshots: util.promisify: 1.0.0 webpack: 4.44.2(webpack-cli@4.10.0) - html-webpack-plugin@5.6.3(webpack@5.98.0(esbuild@0.25.1)): + html-webpack-plugin@5.6.3(webpack@5.98.0(esbuild@0.25.2)): dependencies: '@types/html-minifier-terser': 6.1.0 html-minifier-terser: 6.1.0 @@ -25132,7 +25135,7 @@ snapshots: pretty-error: 4.0.0 tapable: 2.2.1 optionalDependencies: - webpack: 5.98.0(esbuild@0.25.1) + webpack: 5.98.0(esbuild@0.25.2) optional: true html-webpack-plugin@5.6.3(webpack@5.98.0): @@ -26043,7 +26046,7 @@ snapshots: dependencies: less: 4.2.2 optionalDependencies: - webpack: 5.98.0(esbuild@0.25.1) + webpack: 5.98.0(esbuild@0.25.2) less@4.2.2: dependencies: @@ -26070,7 +26073,7 @@ snapshots: dependencies: webpack-sources: 3.2.3 optionalDependencies: - webpack: 5.98.0(esbuild@0.25.1) + webpack: 5.98.0(esbuild@0.25.2) lie@3.1.1: dependencies: @@ -27069,7 +27072,7 @@ snapshots: dependencies: schema-utils: 4.3.0 tapable: 2.2.1 - webpack: 5.98.0(esbuild@0.25.1) + webpack: 5.98.0(esbuild@0.25.2) minimalistic-assert@1.0.1: {} @@ -28295,7 +28298,7 @@ snapshots: postcss: 8.5.2 semver: 7.7.1 optionalDependencies: - webpack: 5.98.0(esbuild@0.25.1) + webpack: 5.98.0(esbuild@0.25.2) transitivePeerDependencies: - typescript @@ -29303,7 +29306,7 @@ snapshots: neo-async: 2.6.2 optionalDependencies: sass: 1.85.0 - webpack: 5.98.0(esbuild@0.25.1) + webpack: 5.98.0(esbuild@0.25.2) sass@1.85.0: dependencies: @@ -29772,7 +29775,7 @@ snapshots: dependencies: iconv-lite: 0.6.3 source-map-js: 1.2.1 - webpack: 5.98.0(esbuild@0.25.1) + webpack: 5.98.0(esbuild@0.25.2) source-map-resolve@0.5.3: dependencies: @@ -30246,16 +30249,16 @@ snapshots: webpack-sources: 1.4.3 worker-farm: 1.7.0 - terser-webpack-plugin@5.3.11(esbuild@0.25.2)(webpack@5.98.0(esbuild@0.25.1)): + terser-webpack-plugin@5.3.11(esbuild@0.25.1)(webpack@5.98.0(esbuild@0.25.2)): dependencies: '@jridgewell/trace-mapping': 0.3.25 jest-worker: 27.5.1 schema-utils: 4.3.0 serialize-javascript: 6.0.2 terser: 5.39.0 - webpack: 5.98.0(esbuild@0.25.1) + webpack: 5.98.0(esbuild@0.25.2) optionalDependencies: - esbuild: 0.25.2 + esbuild: 0.25.1 terser-webpack-plugin@5.3.11(esbuild@0.25.2)(webpack@5.98.0): dependencies: @@ -31451,7 +31454,7 @@ snapshots: webpack: 5.98.0(esbuild@0.25.2)(webpack-cli@5.1.4) webpack-merge: 5.10.0 - webpack-dev-middleware@7.4.2(webpack@5.98.0(esbuild@0.25.1)): + webpack-dev-middleware@7.4.2(webpack@5.98.0(esbuild@0.25.2)): dependencies: colorette: 2.0.20 memfs: 4.17.0 @@ -31460,9 +31463,9 @@ snapshots: range-parser: 1.2.1 schema-utils: 4.3.0 optionalDependencies: - webpack: 5.98.0(esbuild@0.25.1) + webpack: 5.98.0(esbuild@0.25.2) - webpack-dev-server@5.2.0(webpack@5.98.0(esbuild@0.25.1)): + webpack-dev-server@5.2.0(webpack@5.98.0(esbuild@0.25.2)): dependencies: '@types/bonjour': 3.5.13 '@types/connect-history-api-fallback': 1.5.4 @@ -31489,10 +31492,10 @@ snapshots: serve-index: 1.9.1 sockjs: 0.3.24 spdy: 4.0.2 - webpack-dev-middleware: 7.4.2(webpack@5.98.0(esbuild@0.25.1)) + webpack-dev-middleware: 7.4.2(webpack@5.98.0(esbuild@0.25.2)) ws: 8.18.0 optionalDependencies: - webpack: 5.98.0(esbuild@0.25.1) + webpack: 5.98.0(esbuild@0.25.2) transitivePeerDependencies: - bufferutil - debug @@ -31518,12 +31521,12 @@ snapshots: webpack-sources@3.2.3: {} - webpack-subresource-integrity@5.1.0(html-webpack-plugin@5.6.3(webpack@5.98.0(esbuild@0.25.1)))(webpack@5.98.0(esbuild@0.25.1)): + webpack-subresource-integrity@5.1.0(html-webpack-plugin@5.6.3(webpack@5.98.0(esbuild@0.25.2)))(webpack@5.98.0(esbuild@0.25.1)): dependencies: typed-assert: 1.0.9 - webpack: 5.98.0(esbuild@0.25.1) + webpack: 5.98.0(esbuild@0.25.2) optionalDependencies: - html-webpack-plugin: 5.6.3(webpack@5.98.0(esbuild@0.25.1)) + html-webpack-plugin: 5.6.3(webpack@5.98.0(esbuild@0.25.2)) webpack-virtual-modules@0.6.2: {} @@ -31557,7 +31560,7 @@ snapshots: transitivePeerDependencies: - supports-color - webpack@5.98.0(esbuild@0.25.1): + webpack@5.98.0(esbuild@0.25.2): dependencies: '@types/eslint-scope': 3.7.7 '@types/estree': 1.0.7 @@ -31579,7 +31582,7 @@ snapshots: neo-async: 2.6.2 schema-utils: 4.3.0 tapable: 2.2.1 - terser-webpack-plugin: 5.3.11(esbuild@0.25.2)(webpack@5.98.0(esbuild@0.25.1)) + terser-webpack-plugin: 5.3.11(esbuild@0.25.1)(webpack@5.98.0(esbuild@0.25.2)) watchpack: 2.4.2 webpack-sources: 3.2.3 transitivePeerDependencies: