Skip to content

fix(resource): fix resource view disappearing on ats#4103

Merged
TheodoreSpeaks merged 1 commit intodevfrom
fix/resource-at
Apr 11, 2026
Merged

fix(resource): fix resource view disappearing on ats#4103
TheodoreSpeaks merged 1 commit intodevfrom
fix/resource-at

Conversation

@TheodoreSpeaks
Copy link
Copy Markdown
Collaborator

Summary

Atting a resource, then sending the message would cause the resource to disappear from the right temporarily. Also the symbol for the icon didn't show up until the chat streaming began.

Changed icon rendering to be persisted earlier and cleared resource context to prevent removing resource.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

  • Validated resources no longer disappear.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 11, 2026 0:39am

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 11, 2026

PR Summary

Medium Risk
Updates client-side chat caching and context-reset behavior, which could affect message/resource UI state during sends but is limited in scope and isolated to the frontend.

Overview
Fixes a UI regression where attached resources briefly disappeared (and mention icons lagged) when sending a message.

useChat.sendMessage now includes selected contexts in the optimistic React Query cache update for the pending user message and avoids persisting the transient streaming-file resource into cached chat history. UserInput also resets its previous-context tracking ref on submit to prevent context-removal side effects when clearing contexts.

Reviewed by Cursor Bugbot for commit 03c7b94. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 11, 2026

Greptile Summary

This PR fixes two related symptoms in the @-mention resource flow: the resource panel disappearing briefly after a message is sent, and the mention-chip icon not rendering until streaming began. Both were caused by the same root bug — clearContexts() in handleSubmit triggered the selectedContexts effect, which compared the cleared list against prevSelectedContextsRef.current (still holding the submitted contexts), detected them as "removed", and called onContextRemoveremoveResource for each one. The fix presets prevSelectedContextsRef.current = [] synchronously before clearContexts(), so the effect sees no delta and skips the spurious remove calls.

Confidence Score: 5/5

Safe to merge — targeted, minimal fix that closes the spurious removeResource call path without introducing new state invariants.

Single-line insertion that correctly exploits the existing ref-before-effect pattern. All edge cases behave correctly.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx Core fix: prevSelectedContextsRef.current = [] is now reset before clearContexts() in handleSubmit, preventing the selectedContexts effect from firing spurious onContextRemove calls when a message is submitted.
apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts No functional changes detected; resource/icon lifecycle via addResource, effectiveActiveResourceId, and ensureWorkflowInRegistry is unchanged.

Sequence Diagram

sequenceDiagram
    participant U as User
    participant UI as UserInput (handleSubmit)
    participant CTX as useContextManagement
    participant EFFECT as selectedContexts effect
    participant HOME as home.tsx (handleContextRemove)
    participant CHAT as use-chat.ts (removeResource)

    U->>UI: Press Enter / click Send
    UI->>CTX: clearContexts()
    Note over UI,CTX: BUG (before fix): prevSelectedContextsRef still=[workflowCtx]
    CTX-->>EFFECT: selectedContexts becomes []
    EFFECT->>EFFECT: prev=[workflowCtx], curr=[], removed=[workflowCtx]
    EFFECT->>HOME: onContextRemove(workflowCtx)
    HOME->>CHAT: removeResource('workflow', id)
    CHAT-->>UI: panel collapses / icon gone

    Note over UI,CTX: FIX: prevSelectedContextsRef.current=[] BEFORE clearContexts()
    UI->>UI: prevSelectedContextsRef.current = []
    UI->>CTX: clearContexts()
    CTX-->>EFFECT: selectedContexts becomes []
    EFFECT->>EFFECT: prev=[], curr=[], removed=[] — nothing to do
    Note over UI,CHAT: Resource stays in panel, icon stays visible
Loading

Reviews (1): Last reviewed commit: "fix(resource): fix resource view disappe..." | Re-trigger Greptile

@TheodoreSpeaks TheodoreSpeaks merged commit 5f7b98d into dev Apr 11, 2026
14 checks passed
@TheodoreSpeaks TheodoreSpeaks deleted the fix/resource-at branch April 11, 2026 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant