sourceRef.current in useMemo may produce stale matchedTemplate

Aperta
#36 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
typescript
Ambito
frontend

Direzione di ricerca

Start in apps/app/src/components/generative-ui/save-template-overlay.tsx and inspect the matchedTemplate useMemo, its dependency array, and how sourceRef.current is set in the apply flow. Choose a reactive source-template representation, then verify that the matched template badge updates when the source ref changes after the last html or templates change.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Problem

In save-template-overlay.tsx, the matchedTemplate useMemo reads sourceRef.current to find the source template from the apply flow. However, React refs don't trigger re-renders when they change, so the memo's dependency array ([html, agent.state?.templates]) won't capture changes to sourceRef.current.

In practice this works because html or templates changes trigger recomputation, but it's technically not guaranteed — if the ref is set after the last html/templates change, the matched template badge could show stale data.

Suggested fix

Either:

  • Store the source template info in state instead of a ref (triggers re-render on change)
  • Add the source ID as an explicit dependency by extracting it to a state variable

Files

  • apps/app/src/components/generative-ui/save-template-overlay.tsx

From PR #20 review

Lingua principale
TypeScript
Stelle
1.6k
Fork
202
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di CopilotKit/OpenGenerativeUI

Tutte le issue di CopilotKit/OpenGenerativeUI

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.