Fix: Handle object rendering in UI#2726
Open
Patel230 wants to merge 7 commits intosimstudioai:stagingfrom
Open
Fix: Handle object rendering in UI#2726Patel230 wants to merge 7 commits intosimstudioai:stagingfrom
Patel230 wants to merge 7 commits intosimstudioai:stagingfrom
Conversation
|
@Patel230 is attempting to deploy a commit to the Sim Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
There was a problem hiding this comment.
Greptile Overview
Greptile Summary
Fixes React crashes when workflow outputs return structured objects by introducing a robust formatting utility that safely converts various output types to displayable strings. Replaces inline JSON.stringify calls in chat components with deep object traversal that intelligently extracts text content from nested structures. Includes comprehensive unit tests covering edge cases like circular references, binary data, and common LLM response formats.
Confidence Score: 3/5
- Generally safe with minor implementation issues that should be addressed
- The PR successfully solves the object rendering crash issue with comprehensive error handling and extensive test coverage. However, several implementation concerns warrant attention: (1) unused
seenObjectsvariable indicates incomplete cleanup, (2) array joining with newlines may cause unexpected vertical layout in chat UI, (3) aggressive whitespace normalization could break formatted content like code snippets, and (4)for...inusage is less efficient than modern alternatives. These are style and UX concerns rather than critical bugs, but they could impact display quality and code maintainability. apps/sim/lib/core/utils/format-output.tsneeds attention for unused variables, whitespace handling, and array formatting behavior
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/sim/lib/core/utils/format-output.ts | 2/5 | Adds comprehensive output formatting utility; seenObjects variable declared but never used, array joining uses newline which may cause layout issues in chat |
| apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/chat/chat.tsx | 4/5 | Replaces inline formatting logic with shared utility formatOutputForWorkflow; removes duplicate code |
| apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/chat/components/chat-message/chat-message.tsx | 4/5 | Replaces manual JSON.stringify with formatOutputForChat utility for consistent object handling |
Sequence Diagram
sequenceDiagram
participant User
participant ChatMessage
participant FormatUtil as format-output.ts
participant DeepExtract as deepExtractText()
participant SafeStringify as safeStringify()
User->>ChatMessage: Render message with object content
ChatMessage->>FormatUtil: formatOutputForChat(content)
FormatUtil->>FormatUtil: extractContent(item)
alt Object with text field
FormatUtil->>DeepExtract: deepExtractText(obj)
DeepExtract->>DeepExtract: Search TEXT_FIELD_NAMES
DeepExtract->>DeepExtract: Recursive traversal (max depth 10)
DeepExtract-->>FormatUtil: Return extracted text
FormatUtil->>FormatUtil: Clean whitespace & truncate
FormatUtil-->>ChatMessage: Formatted string
else Array
FormatUtil->>FormatUtil: Map extractContent over items
FormatUtil->>FormatUtil: Join with newline
FormatUtil-->>ChatMessage: Joined string
else Fallback to JSON
FormatUtil->>SafeStringify: safeStringify(obj)
SafeStringify->>SafeStringify: Handle circular refs
SafeStringify-->>FormatUtil: JSON string
FormatUtil->>FormatUtil: Wrap in code block (workflow mode)
FormatUtil-->>ChatMessage: Formatted JSON
end
ChatMessage->>User: Display formatted text
- Remove unused seenObjects variable - Use Object.entries instead of for...in for better performance - Join arrays with spaces instead of newlines for better chat UI layout - Improve whitespace normalization to preserve code formatting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
{text, type}Changes
format-output.tsutility with deep object traversalTest Plan
{text: "content", type: "response"}