useTreeData mutations leave stale descendants under parents keyed by 0 or an empty string
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- react, typescript
- Área
- frontend
Línea de trabajo
The bug is in the ancestor loop of updateTree in the useTreeData hook, which uses while (node && node.parentKey) and stops at falsy keys such as 0 or ''. Read that loop and the reproduction steps, then run the hook test with a parent keyed 0 to see items diverge from getItem. Done means update, remove, insert and move keep items and getItem consistent for 0 and '' keys. A linked pull request (#10908) already exists, so check it before starting.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Provide a general summary of the issue here
useTreeData does not propagate mutations through a parent whose key is numeric 0 or an empty string. The returned items tree can retain an old child even though getItem reflects the mutation.
🤔 Expected Behavior?
Updating, inserting, removing, or moving descendants should update the tree for all valid string and numeric keys, including 0 and ''. The nodes reachable through items and getItem should agree.
😯 Current Behavior
With a child under a parent keyed by 0:
updatechanges the lookup entry but leaves the old value initems.removedeletes the lookup entry but leaves the child initems.- Appending a grandchild updates the lookup entry but not the tree.
- Moving the child to the root leaves a stale copy under its original parent.
The same behavior occurs with '', including when the parent is nested under another root.
StackBlitz Reproduction
No hosted StackBlitz is attached. This was found by source inspection and reproduced using the repository's real hook with its existing Jest/renderHook setup. A minimal component is included below so it can also be tried in an app.
🖥️ Steps to Reproduce
import {useTreeData} from 'react-stately/useTreeData';
export default function Repro() {
let tree = useTreeData({
initialItems: [{id: 0, children: [{id: 'child', name: 'Before'}]}]
});
return (
<>
<button onClick={() => tree.update('child', {id: 'child', name: 'After'})}>
Update child
</button>
<pre>items: {tree.items[0].children[0].value.name}</pre>
<pre>getItem: {tree.getItem('child').value.name}</pre>
</>
);
}
Click Update child. Expected: both outputs are After. Actual: items stays Before, while getItem becomes After. Replace 0 with '' for the string-key case.
💁 Possible Solution
The ancestor loop in updateTree uses while (node && node.parentKey), which stops at valid falsy keys. I plan to use an explicit nullish check and add regression tests for update, remove, insert, and move, checking both tree contents and lookup consistency.
🔦 Context
Discovered while auditing the public tree-data mutation API for edge cases. Numeric zero is a valid application ID; a component rendering tree.items can show stale or duplicated data after these mutations. This report is based on a local reproduction, not a claim about a production incident.
Version
Reproduced from main at 83fb30648fe0a1c463256423553d6b3a4ee2ce82 (react-stately package version 3.51.0). React 19.3.0; Jest 30 with the repository's StrictMode hook test wrapper.
What browsers are you seeing the problem on?
Other
If other, please specify.
Reproduced in Jest/jsdom; browser verification has not yet been performed.
What operating system are you using?
macOS 27.2
🧢 Your Company/Team
Independent contribution.
🕷 Tracking Issue
None.
- Lenguaje dominante
- TypeScript
- Estrellas
- 16k
- Forks
- 1.6k
- Merge medio
- 3 d 9 h
- PR fusionados (30 d)
- 45
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de adobe/react-spectrum
-
accessibility bug PreviewTrigger
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
adobe/react-spectrum#10917 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
S2 quiet Picker menu is always 192px wide: its width calc() has no unitPosiblemente ocupada @darshpatel1052 la tomó hace 1 día. Abiertowaiting on author
Dificultad 2/5 Menos de una hora Aptitud para principiantes 88/100
adobe/react-spectrum#10909 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
DatePicker omits timezone for initially empty fields despite zoned placeholderValuePosiblemente ocupada @mrlexcoder la tomó hace 2 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
adobe/react-spectrum#10900 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Separator adds a redundant role="separator" to its default <hr>Posiblemente ocupada @Janani-bn la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
adobe/react-spectrum#10894 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
ComboBox with selectionMode="multiple": Cmd/Ctrl+A does nothing while the popover is openPosiblemente ocupada @mangeshraut712 la tomó hace 8 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
adobe/react-spectrum#10866 ·
Los mantenedores suelen responder en 1 día
Todos los issues de adobe/react-spectrum
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Open-Earth-Foundation/CityCatalyst#3399 ·
Los mantenedores suelen responder en 2 días
-
userReport
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
nkprasad12/morcus-net#631 ·
Los mantenedores suelen responder en 1 día
-
fix(app): fail closed if GetGeneralSetting fails during initializationPosiblemente ocupada @kalavt la tomó hoy. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
nekko-labs/nekko-agent#1756 ·
Los mantenedores suelen responder en 1 día
-
needs-area-label
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 2 días