Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

Structural sharing drops a `__proto__` key from query data and changes the object's prototype

Fermée
#12,303 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

  • #12304 par @Gourav224 — fermée sans fusion

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
typescript
Domaine
frontend

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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
  1. Return JSON with a __proto__ key from a queryFn, for example a map keyed by user input.
  2. Refetch so that some other field in that object changes.
  3. 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.

Langage dominant
TypeScript
Étoiles
50.5k
Forks
4.2k
Merge moyen
8 h 14 min
PR mergées (30 j)
632

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de TanStack/query

Toutes les issues de TanStack/query

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.