Skip to content

sourceRef.current in useMemo may produce stale matchedTemplate #36

@GeneralJerel

Description

@GeneralJerel

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions