Structural sharing drops a `__proto__` key from query data and changes the object's prototype
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- typescript
- Bereich
- frontend
Rechercherichtung
The issue identifies replaceEqualDeep and explains how assigning the __proto__ key changes the copy's prototype. Start by locating that function and checking its existing tests for structural sharing. Done means refetching changed data preserves __proto__ as an own property and leaves the result's prototype as Object.prototype; the reporter says they plan to open a PR.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Describe the bug
If query data has a "__proto__" key (JSON.parse keeps it as a normal property), it disappears after a refetch where anything else in that object changed.
replaceEqualDeep builds the new object with copy[key] = value. For __proto__ that assignment calls the setter and changes the copy's prototype instead of adding a property. So the key is gone, and its contents show up as inherited properties instead.
The first fetch is fine, because there is no previous data to share with.
Your minimal, reproducible example
import { replaceEqualDeep } from '@tanstack/query-core'
const prev = JSON.parse('{"__proto__":{"admin":true},"count":1}')
const next = JSON.parse('{"__proto__":{"admin":true},"count":2}')
const result = replaceEqualDeep(prev, next)
Object.keys(result) // ['count']
JSON.stringify(result) // '{"count":2}'
result.admin // true (inherited)
Steps to reproduce
- Return JSON with a
__proto__key from a queryFn, for example a map keyed by user input. - Refetch so that some other field in that object changes.
data.__proto__is no longer an own key, and the object's prototype is now that value.
Expected behavior
__proto__ stays an own property, like any other key, and the prototype stays Object.prototype.
Platform
Any. Reproduced on Node 24.
TanStack Query version
5.104.5 (main)
Additional context
I have a small fix with tests and will open a PR.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 50.5k
- Forks
- 4.2k
- Ø Merge
- 9 Std. 34 Min.
- Gemergte PRs (30 T.)
- 603
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus TanStack/query
-
QueryClient.isFetching and useIsFetching accept a fetchStatus filter and ignore itEvtl. vergeben @Apu-Emdad hat das vor 11 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)Evtl. wieder frei @LeonxLJX hat das vor 52 Tagen übernommen, und es ist kein Pull Request offen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
TanStack/query#11358 · 2 Kommentare · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
-
angular-query-experimental: `import * as ng` in pending-tasks-compat pulls all of @angular/core into the initial bundleEvtl. vergeben @benjavicente hat das heute übernommen. Offenpackage: angular-query
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 52/100
TanStack/query#12319 · 1 Kommentar · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
useBaseQuery fetches the old query key when an <Activity> tree is revealedEvtl. vergeben @lazerg hat das vor 5 Tagen übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 35/100
Maintainer antworten meist innerhalb von 1 Tag
-
[query-broadcast-client-experimental] broadcastQueryClient: an `added` event overwrites a receiving query that has no data (e.g. in error) with the sender's empty stateEvtl. vergeben @lazerg hat das vor 5 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 25/100
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
grafana/profiles-drilldown#1212 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
grafana/traces-drilldown#980 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
openremote/openremote#3487 · 1 Kommentar ·
-
triage:needs-human
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
garrytan/gbrain#7635 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
coollabsio/jean#867 ·
Maintainer antworten meist innerhalb von 1 Tag