fix(vite-plugin): apply manual layouts in codegen React hooks#2876
Conversation
|
@coderabbitai review |
🦋 Changeset detectedLatest commit: f815c66 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 (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughRefactors the vite-plugin to derive generated view hooks from the computed Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
b9833b1 to
665c5dc
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/vite-plugin/src/virtuals/model.ts`:
- Around line 6-10: projectModelCode() only patches views in this virtual
module, so callers of layoutedModel() (e.g. likec4.layoutedModel(project.id))
still receive unpatched auto-layout results; move the manual-layout correction
into the shared layoutedModel() flow instead. Update the layoutedModel()
implementation so that before returning it applies the same transformation used
here (build views = indexBy([...model.views()].map(v => v.$layouted),
prop('id')) and sets model.$data.views accordingly) or make layoutedModel()
delegate to diagrams()/the canonical layout routine that already applies
$layouted; ensure model.$data and any returned model object contain the patched
views so all callers (not just projectModelCode) observe _layout: 'manual' where
appropriate.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4444f869-01a5-4b7e-9b6b-30110085da85
📒 Files selected for processing (1)
packages/vite-plugin/src/virtuals/model.ts
|
Good catch!! |
The useLikeC4Views and useLikeC4View hooks in the vite-plugin internal module returned raw data views without manual layouts applied. This caused codegen react to produce views missing _layout: "manual". The fix uses $layouted from LikeC4ViewModel (which applies manual layouts lazily) instead of reading raw views from the data atom. This matches the pattern in packages/likec4/app/src/hooks.ts. Suggested by @davydkov: #2876 (comment) Closes #2553 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
665c5dc to
31a2357
Compare
The useLikeC4Views and useLikeC4View hooks in the vite-plugin internal module returned raw data views without manual layouts applied. This caused codegen react to produce views missing _layout: "manual". The fix uses $layouted from LikeC4ViewModel (which applies manual layouts lazily) instead of reading raw views from the data atom. This matches the pattern in packages/likec4/app/src/hooks.ts. Suggested by @davydkov: #2876 (comment) Closes #2553 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
31a2357 to
9172345
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/vite-plugin/src/internal.ts (1)
90-94: Memoize the computed store to avoid recreation on every hook call.The
computed()store is created during eachuseLikeC4Viewcall, causing unnecessary subscribe/unsubscribe churn. UseuseMemoto create the store once perviewIdwithin a component instance.Proposed fix
+import { useMemo } from 'react' import { isDeepEqual, mapValues } from 'remeda' function useLikeC4View(viewId: string): DiagramView | null { - const $view = computed($likec4model, (model) => { - return model.findView(viewId)?.$layouted ?? null - }) + const $view = useMemo( + () => + computed($likec4model, (model) => { + return model.findView(viewId)?.$layouted ?? null + }), + [viewId], + ) return useStore($view) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/vite-plugin/src/internal.ts` around lines 90 - 94, The computed store $view created inside useLikeC4View is rebuilt on every hook call causing subscribe/unsubscribe churn; wrap the computed(...) creation in a memo so it's only created once per viewId (e.g., useMemo(() => computed($likec4model, model => model.findView(viewId)?.$layouted ?? null), [viewId])) and then pass that memoized store to useStore($view) so subsequent renders reuse the same computed instance; update useLikeC4View to reference the memoized $view instead of creating a new computed each call.
🤖 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/vite-plugin/src/internal.ts`:
- Around line 90-94: The computed store $view created inside useLikeC4View is
rebuilt on every hook call causing subscribe/unsubscribe churn; wrap the
computed(...) creation in a memo so it's only created once per viewId (e.g.,
useMemo(() => computed($likec4model, model => model.findView(viewId)?.$layouted
?? null), [viewId])) and then pass that memoized store to useStore($view) so
subsequent renders reuse the same computed instance; update useLikeC4View to
reference the memoized $view instead of creating a new computed each call.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 53e920f1-d4f6-4ab0-bc4b-e141234d76c5
📒 Files selected for processing (2)
packages/vite-plugin/src/internal.tspackages/vite-plugin/src/virtuals/model.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/vite-plugin/src/virtuals/model.ts
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
Thanks for the guidance! Moved the fix to |
The useLikeC4Views and useLikeC4View hooks in the vite-plugin internal module returned raw data views without manual layouts applied. This caused codegen react to produce views missing _layout: "manual". The fix uses $layouted from LikeC4ViewModel (which applies manual layouts lazily) instead of reading raw views from the data atom. This matches the pattern in packages/likec4/app/src/hooks.ts. Suggested by @davydkov: #2876 (comment) Closes #2553 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
9172345 to
57c04b4
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
useLikeC4Views and useLikeC4View hooks were reading raw view data from $atom.views, bypassing LikeC4ViewModel.$layouted which applies manual layout overrides. Changed hooks to derive from $likec4model and use $layouted, matching the pattern in app/src/hooks.ts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
0479afc to
f815c66
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Summary
Fix for #2553 — codegen React hooks (
useLikeC4Views,useLikeC4View) were not applying manual layouts.Root Cause
The hooks in
packages/vite-plugin/src/internal.tsread raw view data directly from$atom.views, bypassingLikeC4ViewModel.$layoutedwhich applies manual layout overrides.Fix
$likec4viewsnow derives from$likec4modeland maps throughv.$layouteduseLikeC4Viewusescomputed($likec4model, ...)with$layouted, wrapped inuseMemofor stable atom identityuseState/useEffectimportsThis matches the pattern already used in
packages/likec4/app/src/hooks.ts.Files changed
packages/vite-plugin/src/internal.ts— hooks use$layoutedviaLikeC4ViewModel.changeset/fix-codegen-manual-layout.md— patch changeset for@likec4/vite-plugin🤖 Generated with Claude Code