Uh oh!
There was an error while loading. Please reload this page.
improvement(response-copilot): prefer builder mode + fix builder/editor mode conversions - #1648
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub. |
| // Use preview value when in preview mode, otherwise use store value | ||
| const value = isPreview ? previewValue : storeValue | ||
| const fields: Field[] = value || [] | ||
| const fields: Field[] = Array.isArray(value) ? value : [] |
There was a problem hiding this comment.
this prevents nuking diff store if copilot outputs invalid fields i.e. not an array
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Greptile Overview
Summary
Implements bidirectional conversion between builder and editor modes for the Response block, using refs to avoid stale closure issues and moving conversion logic to a useEffect.
Key changes:
- Added
previousModeRefto track mode changes and trigger conversions only when mode actually changes - Used refs (
builderDataRef,dataRef) to access latest values in useEffect without stale closures - Moved conversion logic from
handleSelectto dedicated useEffect for better separation - Updated best practices to prefer builder mode since JSON generation is weaker
- Added defensive type guard in
input-format.tsxto prevent crashes when value is not an array
Critical issue found:
- The regex pattern in
normalizeVariableReferencesincorrectly captures the character before variable references, producing malformed JSON that will cause JSON.parse to fail when converting from editor to builder mode
Confidence Score: 1/5
- This PR has a critical regex bug that will break editor-to-builder conversion
- The
normalizeVariableReferencesregex pattern/([^"]<[^>]+>)/gcaptures one character before the variable reference (e.g.,: <var>becomes": <var>"resulting in"": <var>"), producing invalid JSON that will cause runtime errors when users switch from editor to builder mode - Pay close attention to
dropdown.tsx- the regex bug on line 120 must be fixed before merge
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/sim/blocks/blocks/response.ts | 5/5 | Updated best practices to prefer builder mode over editor mode - simple documentation change |
| apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/starter/input-format.tsx | 5/5 | Added type guard for array values and improved placeholder text - safe defensive changes |
| apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/dropdown.tsx | 1/5 | Implements bidirectional mode conversion with refs to avoid stale closures, but regex bug will break JSON-to-builder conversion |
Sequence Diagram
sequenceDiagram
participant User
participant Dropdown
participant Store
participant ResponseBlockHandler
User->>Dropdown: Select mode (structured/json)
Dropdown->>Dropdown: handleSelect(selectedValue)
Dropdown->>Store: setStoreValue(selectedValue)
Note over Dropdown: useEffect triggered by storeValue change
Dropdown->>Dropdown: Check if subBlockId === 'dataMode'
Dropdown->>Dropdown: Compare previousMode vs currentMode
alt Builder → Editor (structured → json)
Dropdown->>Dropdown: Get builderDataRef.current
Dropdown->>ResponseBlockHandler: convertBuilderDataToJsonString(builderData)
ResponseBlockHandler-->>Dropdown: jsonString
Dropdown->>Store: setData(jsonString)
else Editor → Builder (json → structured)
Dropdown->>Dropdown: Get dataRef.current
Dropdown->>Dropdown: normalizeVariableReferences(jsonString)
Note right of Dropdown: ⚠️ Regex bug: creates invalid JSON
Dropdown->>Dropdown: convertJsonToBuilderData(jsonString)
Dropdown-->>Dropdown: builderArray
Dropdown->>Store: setBuilderData(builderArray)
end
Dropdown->>Dropdown: Update previousModeRef.current
3 files reviewed, 1 comment
| const normalizeVariableReferences = (jsonString: string): string => { | ||
| // Replace unquoted variable references with quoted ones | ||
| // Pattern: <variable.name> -> "<variable.name>" | ||
| return jsonString.replace(/([^"]<[^>]+>)/g, '"$1"') | ||
| } |
There was a problem hiding this comment.
logic: regex pattern incorrectly captures the character before <, causing malformed JSON (e.g., : <var> becomes ": <var>" → "": <var>")
| constnormalizeVariableReferences=(jsonString: string): string=>{ | |
| // Replace unquoted variable references with quoted ones | |
| // Pattern: <variable.name> -> "<variable.name>" | |
| returnjsonString.replace(/([^"]<[^>]+>)/g,'"$1"') | |
| } | |
| constnormalizeVariableReferences=(jsonString: string): string=>{ | |
| // Replace unquoted variable references with quoted ones | |
| // Pattern: <variable.name> -> "<variable.name>" | |
| returnjsonString.replace(/(?<!")(<[^>]+>)(?!")/g,'"$1"') | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/dropdown.tsx
Line: 117:121
Comment:
**logic:** regex pattern incorrectly captures the character before `<`, causing malformed JSON (e.g., `: <var>` becomes `": <var>"` → `"": <var>"`)
```suggestion const normalizeVariableReferences = (jsonString: string): string => { // Replace unquoted variable references with quoted ones // Pattern: <variable.name> -> "<variable.name>" return jsonString.replace(/(?<!")(<[^>]+>)(?!")/g, '"$1"') }```
How can I resolve this? If you propose a fix, please make it concise.
Summary
Type of Change
Testing
Tested manually + trained copilot on conversion op
Checklist