fix(ui) reduce redundant rerenders#3593
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview Tightens resource event handling in chat streaming. Written by Cursor Bugbot for commit 74fe25c. This will update automatically on new commits. Configure here. |
Greptile SummaryThis PR reduces redundant React re-renders in the Mothership chat view by wrapping Key changes:
One potential behavior regression: When Confidence Score: 3/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[SSE: resource_added] --> B[addResource - returns bool]
B -->|wasAdded=true - new| C[invalidateResourceQueries]
B -->|wasAdded=false - exists| C
C --> D{wasAdded?}
D -->|true| E[onResourceEvent - expand panel]
D -->|false| F{activeResourceId == resource.id?}
F -->|no| G[setActiveResourceId + onResourceEvent]
F -->|yes| H[no-op - skip expand]
E --> I{resource.type == workflow?}
G --> I
H --> I
I -->|wasAdded && ensureWorkflowInRegistry| J[setActiveWorkflow]
I -->|else - !wasAdded or registry fail| K[loadWorkflowState]
style H fill:#f9c74f,stroke:#f3722c
style J fill:#90be6d,stroke:#43aa8b
style K fill:#577590,color:#fff,stroke:#277da1
|
|
@greptile review |
| if (!wasAdded) { | ||
| if (activeResourceIdRef.current !== resource.id) { | ||
| setActiveResourceId(resource.id) | ||
| onResourceEventRef.current?.() | ||
| } | ||
| } else { | ||
| onResourceEventRef.current?.() | ||
| } |
There was a problem hiding this comment.
Panel won't re-expand for active-but-collapsed resource
When !wasAdded and activeResourceIdRef.current === resource.id, neither setActiveResourceId nor onResourceEventRef.current?.() is called. This means if the user manually collapsed the resource panel while a resource was active, a subsequent resource_added event for that same resource will not re-expand the panel, even though the PR's goal is for the panel to be visible when the AI references that resource.
Before this PR, onResourceEventRef.current?.() was always fired on resource_added, so handleResourceEvent would re-expand the panel whenever it was collapsed. The new logic silently skips the expand when the resource is already "active" by ID, regardless of panel collapse state.
If the intent is only to avoid the rerender (not the expand), consider still firing the event when the panel is collapsed:
if (!wasAdded) {
if (activeResourceIdRef.current !== resource.id) {
setActiveResourceId(resource.id)
onResourceEventRef.current?.()
} else if (isResourceCollapsedRef?.current) {
// Resource is active but panel was manually collapsed — re-expand
onResourceEventRef.current?.()
}
} else {
onResourceEventRef.current?.()
}
(Note: this would require threading isResourceCollapsedRef into useChat or checking collapse state inside handleResourceEvent before deciding to skip.)
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Summary
Reduce redundant rerenders
Type of Change
Testing
Checklist
Screenshots/Videos