fix(core): skip re-application of manual layout instead of crashing#2883
Conversation
|
@coderabbitai review |
🦋 Changeset detectedLatest commit: 31ab78e The changes in this PR will be included in the next version bump. This PR includes changesets to release 21 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Actions performedReview triggered.
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a patch changeset and a guard in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/core/src/manual-layout/applyManualLayout.ts (1)
268-272: Move the manual fast-path before invariant checksLine 265-267 invariants still run before the new manual short-circuit. If
snapshotis stale/mismatched, this path can still throw even though the function can safely skip re-application for already-manual input.Suggested adjustment
export function applyManualLayout< V extends LayoutedView, >( autoLayouted: V, snapshot: ViewManualLayoutSnapshot, ): V { + if (autoLayouted._layout === 'manual') { + return autoLayouted + } + invariant(autoLayouted.id === snapshot.id, 'applyManualLayout: view ids do not match') invariant(autoLayouted._stage === 'layouted', 'applyManualLayout: expected layouted view') invariant(snapshot._stage === 'layouted', 'applyManualLayout: expected layouted snapshot') - // If the view already has manual layout applied, return it as-is. - // This can happen when the Vite client receives pre-processed data (`#2882`). - if (autoLayouted._layout === 'manual') { - return autoLayouted - }As per coding guidelines: “When changes relate to views (types or models), update View-drifts detection/auto-applying in
src/manual-layoutaccordingly. If unsure what leads to layout drifts or can be auto-applied, ask for confirmation.”🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/manual-layout/applyManualLayout.ts` around lines 268 - 272, The manual-layout fast-path should be moved before any invariant/snapshot validation so we don't throw on stale/mismatched snapshot for already-manual inputs; in applyManualLayout (look for autoLayouted and its _layout === 'manual' check) relocate that short-circuit to run before the snapshot/invariant checks that reference snapshot, and ensure you still run any necessary view-drifts detection/auto-applying updates in src/manual-layout per the coding guidelines.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/core/src/manual-layout/applyManualLayout.ts`:
- Around line 268-272: The manual-layout fast-path should be moved before any
invariant/snapshot validation so we don't throw on stale/mismatched snapshot for
already-manual inputs; in applyManualLayout (look for autoLayouted and its
_layout === 'manual' check) relocate that short-circuit to run before the
snapshot/invariant checks that reference snapshot, and ensure you still run any
necessary view-drifts detection/auto-applying updates in src/manual-layout per
the coding guidelines.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7a5bcfb4-d3c6-42e2-be6d-c79a89dc7029
📒 Files selected for processing (2)
.changeset/fix-manual-layout-crash.mdpackages/core/src/manual-layout/applyManualLayout.ts
|
@coderabbitai review |
4bf6b36 to
4be345b
Compare
✅ Actions performedReview triggered.
|
4be345b to
97d4564
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
97d4564 to
eafe583
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
#2882) When the Vite dev server client receives a view with _layout already set to 'manual', LikeC4ViewModel.$manual would call applyManualLayout on already-processed data, crashing with an invariant violation. Moved the guard to $manual getter in LikeC4ViewModel where the data-flow context is understood: if this.#view already has _layout: 'manual', return it directly (it has current data + manual positions). The applyManualLayout invariant is preserved — it correctly rejects double-application as a contract violation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
eafe583 to
31ab78e
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Summary
Fix for #2882 — views with manual layout snapshots crash on the interactive view route in dev mode.
Root Cause
The Vite dev server client receives view data where
_layoutis already'manual', butLikeC4ViewModel.$manualunconditionally callsapplyManualLayout()which throws an invariant on_layout === 'manual'.Server-side:
layoutedModel()returns_layout: 'auto'— correct. The Vite client pipeline modifies the value before rendering.Fix
Guard in
LikeC4ViewModel.$manual(packages/core/src/model/view/LikeC4ViewModel.ts): ifthis.#view._layout === 'manual', returnthis.#viewdirectly — it already has current data + manual positions. TheapplyManualLayoutinvariant is preserved as a contract guard.Before / After
/project/e2e/view/view-with-custom-colors/shows red "Something went wrong" error screen withapplyManualLayout: expected auto-layouted viewTest
Added
e2e/tests/manual-layout-views.spec.ts— navigates to the interactive view route (/view/, not/export/) forview-with-custom-colorsand verifies the diagram renders without the error boundary firing.Files changed
packages/core/src/model/view/LikeC4ViewModel.ts— guard in$manualgettere2e/tests/manual-layout-views.spec.ts— e2e regression test for interactive routee2e/.gitignore— whitelist new test.changeset/fix-manual-layout-crash.md— patch changesetCloses #2882
🤖 Generated with Claude Code