fix: merge subblock values in auto-layout to prevent losing router context#4055
fix: merge subblock values in auto-layout to prevent losing router context#4055waleedlatif1 merged 1 commit intostagingfrom
Conversation
PR SummaryMedium Risk Overview On save failure rollback, it also merges subblock state when restoring the previous Reviewed by Cursor Bugbot for commit aac05b6. Configure here. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryThis PR fixes a data-loss bug where auto-layout was persisting stale subblock values to the database. The fix adds Confidence Score: 5/5Safe to merge — the fix is minimal, correct, and follows the established persistence pattern used everywhere else in the codebase. The prior P1 concern (using No files require special attention.
|
| Filename | Overview |
|---|---|
| apps/sim/app/workspace/[workspaceId]/w/[workflowId]/utils/auto-layout-utils.ts | Adds mergeSubblockState on both the happy path (lines 113–114) and the revert path (line 173), using the scoped workflowId parameter throughout — correctly prevents auto-layout from overwriting runtime-edited subblock values. |
Sequence Diagram
sequenceDiagram
participant U as User
participant ALU as applyAutoLayoutAndUpdateStore
participant API as /api/workflows/[id]/autolayout
participant SBS as SubBlockStore
participant WFS as WorkflowStore
participant DB as /api/workflows/[id]/state
U->>ALU: trigger auto-layout
ALU->>WFS: getState() → blocks, edges, loops, parallels
ALU->>API: POST (blocks + layout options)
API-->>ALU: layoutedBlocks (positions updated)
ALU->>SBS: mergeSubblockState(layoutedBlocks, workflowId)
SBS-->>ALU: mergedBlocks (positions + current subblock values)
ALU->>WFS: replaceWorkflowState(mergedBlocks)
ALU->>DB: PUT (mergedBlocks with subblock values preserved)
alt Save succeeds
DB-->>ALU: 200 OK
ALU-->>U: { success: true }
else Save fails
DB-->>ALU: error
ALU->>SBS: mergeSubblockState(originalBlocks, workflowId)
SBS-->>ALU: revertBlocks
ALU->>WFS: replaceWorkflowState(revertBlocks)
ALU-->>U: { success: false, error }
end
Reviews (2): Last reviewed commit: "fix: merge subblock values in auto-layou..." | Re-trigger Greptile
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/utils/auto-layout-utils.ts
Outdated
Show resolved
Hide resolved
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/utils/auto-layout-utils.ts
Outdated
Show resolved
Hide resolved
0b31cce to
c2765fa
Compare
…ntext Auto-layout was reading from getWorkflowState() without merging subblock store values, then persisting stale subblock data to the database. This caused runtime-edited values (e.g. router_v2 context) to be overwritten with their initial/empty values whenever auto-layout was triggered. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
c2765fa to
aac05b6
Compare
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit aac05b6. Configure here.
…ntext (#4055) Auto-layout was reading from getWorkflowState() without merging subblock store values, then persisting stale subblock data to the database. This caused runtime-edited values (e.g. router_v2 context) to be overwritten with their initial/empty values whenever auto-layout was triggered.
* fix(billing): skip billing on streamed workflows with byok * Simplify logic * Address comments, skip tokenization billing fallback * Fix tool usage billing for streamed outputs * fix(webhook): throw webhook errors as 4xxs (#4050) * fix(webhook): throw webhook errors as 4xxs * Fix shadowing body var --------- Co-authored-by: Theodore Li <theo@sim.ai> * feat(enterprise): cloud whitelabeling for enterprise orgs (#4047) * feat(enterprise): cloud whitelabeling for enterprise orgs * fix(enterprise): scope enterprise plan check to target org in whitelabel PUT * fix(enterprise): use isOrganizationOnEnterprisePlan for org-scoped enterprise check * fix(enterprise): allow clearing whitelabel fields and guard against empty update result * fix(enterprise): remove webp from logo accept attribute to match upload hook validation * improvement(billing): use isBillingEnabled instead of isProd for plan gate bypasses * fix(enterprise): show whitelabeling nav item when billing is enabled on non-hosted environments * fix(enterprise): accept relative paths for logoUrl since upload API returns /api/files/serve/ paths * fix(whitelabeling): prevent logo flash on refresh by hiding logo while branding loads * fix(whitelabeling): wire hover color through CSS token on tertiary buttons * fix(whitelabeling): show sim logo by default, only replace when org logo loads * fix(whitelabeling): cache org logo url in localstorage to eliminate flash on repeat visits * feat(whitelabeling): add wordmark support with drag/drop upload * updated turbo * fix(whitelabeling): defer localstorage read to effect to prevent hydration mismatch * fix(whitelabeling): use layout effect for cache read to eliminate logo flash before paint * fix(whitelabeling): cache theme css to eliminate color flash before org settings resolve * fix(whitelabeling): deduplicate HEX_COLOR_REGEX into lib/branding and remove mutation from useCallback deps * fix(whitelabeling): use cookie-based SSR cache to eliminate brand flash on all page loads * fix(whitelabeling): use !orgSettings condition to fix SSR brand cache injection React Query returns isLoading: false with data: undefined during SSR, so the previous brandingLoading condition was always false on the server — initialCache was never injected into brandConfig. Changing to !orgSettings correctly applies the cookie cache both during SSR and while the client-side query loads, eliminating the logo flash on hard refresh. * fix(editor): stop highlighting start.input as blue when block is not connected to starter (#4054) * fix: merge subblock values in auto-layout to prevent losing router context (#4055) Auto-layout was reading from getWorkflowState() without merging subblock store values, then persisting stale subblock data to the database. This caused runtime-edited values (e.g. router_v2 context) to be overwritten with their initial/empty values whenever auto-layout was triggered. * fix(whitelabeling): eliminate logo flash by fetching org settings server-side (#4057) * fix(whitelabeling): eliminate logo flash by fetching org settings server-side * improvement(whitelabeling): add SVG support for logo and wordmark uploads * skelly in workspace header * remove dead code * fix(whitelabeling): hydration error, SVG support, skeleton shimmer, dead code removal * fix(whitelabeling): blob preview dep cycle and missing color fallback * fix(whitelabeling): use brand-accent as color fallback when workspace color is undefined * chore(whitelabeling): inline hasOrgBrand --------- Co-authored-by: Theodore Li <theo@sim.ai>
Summary
getWorkflowState()without merging subblock store values, then persisting stale data to the database viaPUT /api/workflows/[id]/statecontext) to be silently overwritten with their initial/empty values whenever auto-layout was triggeredmergeSubblockState()call (the same pattern used by every other persistence path) to preserve current subblock values during auto-layoutTest plan