solid-query 6.0.0-rc.5: useBaseQuery bumps its version signal on observerAdded/observerRemoved, remounting <Show> children in a loop on Solid 2 rc.14+ #12466
Describe the bug#
useBaseQuery's onCacheEvent (packages/solid-query/src/useBaseQuery.ts on solid-query-v6-pre) calls setVersion(v => v + 1) for every query-cache event whose queryHash matches, without looking at event.type. observerAdded, observerRemoved, observerOptionsUpdated and observerResultsUpdated do not change the query's state, but each one re-runs the result projection.
On Solid 2 rc.14+ this combines with a core issue (solidjs/solid#4540): a non-keyed <Show> gated on q.data remounts its children on every re-run. A child that calls useQuery with the same key adds an observer on mount → observerAdded → version bump → remount → new observer → … an infinite remount loop.
- solid-js rc.13 + solid-query 6.0.0-rc.5: 1 mount
- solid-js rc.20 + solid-query 6.0.0-rc.5: loop (21 mounts before the guard)
- solid-js next@215c365: loop
Steps to Reproduce#
package.json: solid-js, @solidjs/web, @solidjs/signals 2.0.0-rc.20, @tanstack/solid-query 6.0.0-rc.5; dev @solidjs/vite-plugin 3.0.0-next.54, vitest 5.0.5, jsdom 30.1.2.
import { render } from "@solidjs/web";
import { QueryClient, QueryClientProvider, useQuery } from "@tanstack/solid-query";
import { Show } from "solid-js";
import { expect, it } from "vitest";
const wait = (ms: number) => new Promise((r) => setTimeout(r, ms));
it("a second observer mounted under a Show gated on the first one's data mounts once", async () => {
const client = new QueryClient({ defaultOptions: { queries: { retry: false, staleTime: Number.POSITIVE_INFINITY } } });
let mounts = 0;
const options = () => ({ queryKey: ["k"], queryFn: () => wait(10).then(() => 1) });
function Child() {
mounts++;
if (mounts > 20) throw new Error("remount loop");
useQuery(options);
return <p>child</p>;
}
function Page() {
const q = useQuery(options);
return (
<Show when={q.data !== undefined}>
<Child />
</Show>
);
}
const el = document.createElement("div");
const dispose = render(() => (
<QueryClientProvider client={client}>
<Page />
</QueryClientProvider>
), el);
await wait(100);
dispose();
expect(mounts).toBe(1);
});
package.json
{
"name": "solid-query-repro",
"private": true,
"type": "module",
"scripts": { "test": "vitest run" },
"dependencies": {
"solid-js": "2.0.0-rc.20",
"@solidjs/web": "2.0.0-rc.20",
"@solidjs/signals": "2.0.0-rc.20",
"@tanstack/solid-query": "6.0.0-rc.5"
},
"devDependencies": {
"@solidjs/vite-plugin": "3.0.0-next.54",
"jsdom": "30.1.2",
"vitest": "5.0.5"
}
}
vitest.config.ts
import solid from "@solidjs/vite-plugin";
import { defineConfig } from "vitest/config";
export default defineConfig({
plugins: [solid()],
test: { environment: "jsdom" },
});
Expected behavior#
Child mounts once.
Actual behavior#
expected 21 to be 1 (the guard throws "remount loop").
Suggested fix#
Bump version only for events that can change the result (added, removed, updated), not for observer* events. The core issue is the root cause; this avoids the trigger and an unnecessary projection re-run per observer mount/unmount.
Related: #11903, #12031 / #12034 (same function, different defects).
tranhoangtu-it(GitHub profile, opens in a new tab) linked this to #12720
Sign in to join this conversation.
this is already fixed in rc.21 I think.