Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Nested includes are undefined on next render after collection.update

Cerrado
#1,635 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
react, typescript

Línea de trabajo

Comienza con la consulta anidada useLiveQuery y la llamada principal a documentCollection.update que se muestran en la reproducción. Reproduce el problema con las colecciones de documentos, esquemas y campos; después, rastrea cómo se propaga la actualización a los resultados anidados. El trabajo estará terminado cuando los datos anidados de esquemas y campos se rendericen después de collection.update y de una actualización, sin forzar un renderizado de React no relacionado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

  • I've validated the bug against the latest version of DB packages
    Packages:
    "@tanstack/db": "^0.6.7",
    "@tanstack/electric-db-collection": "^0.3.5",
    "@tanstack/react-db": "^0.1.85",

Describe the bug
I have a useLiveQuery with nested collections. When I call update on the parent collection, the nested collections are undefined. Sometimes refreshing the page the nested items are still undefined. A hard refresh is required.

This is using electric-sync. I can see the successful write call and shape update with matching txid.

If you force a re-render, the nested objects appear. See Additional Context below.

// collection
// the other two collection funcs are almost identical 
export const createDocumentCollection = (labId: number) =>
  createCollection(
    electricCollectionOptions<DocumentRow>({
      id: `documents:${labId}`,
      shapeOptions: {
        url: electricSyncUrl,
        params: {
          table: 'documents',
          where: 'lab_id = $1',
          params: { '1': String(labId) },
          columns: SYNC_COLUMNS,
        },
        fetchClient: (input, init) => fetch(input, { ...init, credentials: 'include' }),
        columnMapper: snakeCamelMapper(),
        parser: {
          data: (data) => JSON.parse(data),
        },
      },
      getKey: (row) => row.id,
      onUpdate: async ({ transaction }) => {
        const { original, changes } = transaction.mutations[0]
        const response = await DocumentService.updateDocument(labId, original.id, changes)
        return { txid: response.txid }
      },
    })
  )


// query
const { data: documentQuery } = useLiveQuery(
    (q) =>
      q
        .from({ document: documentCollection })
        .where(({ document }) => eq(document.id, documentId))
        .select(({ document }) => ({
          ...,
          schema: toArray(
            q
              .from({ schema: schemaCollection })
              .where(({ schema }) => eq(document.schemaId, schema.id))
              .select(({ schema }) => ({
                ...,
                fields: toArray(
                  q
                    .from({ field: fieldCollection })
                    .where(({ field }) => eq(field.schemaId, schema.id))
                    .select(({ field }) => field)
                ),
              }))
          ),
        })),
    [documentCollection, schemaCollection, fieldCollection, documentId]
  )
 
 const document = documentQuery[0] 
 const schema = document.schema[0] // comes up undefined 
 const fields = schema?.[0].fields ?? []

 const update = (name: string, v: string) => {
    return documentCollection.update(documentId, (draft) => {
       draft[name] = v
    })
  }

To Reproduce
Steps to reproduce the behavior:

  1. Setup nested include collection like above example
  2. Call collection.update where collection is the parent collection (documentCollection in example)
  3. Observe nested objects are now undefined
  4. Refresh the page
  5. Observe nested objects are now undefined

Expected behavior
I would expect the nested data to render after the update.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop:

  • OS: macOS
  • Browser: chrome
  • Version 148.0.7778.97

Additional context
If i add a simple useState counter to force a re-render, the nested collections appear

const [count, setCount] = useState(0)

return (
  <>
    <button onClick={() => setCount((c) => c + 1)}>{count}</button>
    ...rest of my component
  </>
)
Lenguaje dominante
TypeScript
Estrellas
3.9k
Forks
272
Merge medio
1 d 1 h
PR fusionados (30 d)
210

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de TanStack/db

Todos los issues de TanStack/db

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.