Skip to content

fix(diagram): updated dynamicViewVariant on navigation to dynamic view#2827

Merged
davydkov merged 6 commits into
likec4:mainfrom
kavishkartha05:fix/dynamic-view-variant-not-honored
Apr 7, 2026
Merged

fix(diagram): updated dynamicViewVariant on navigation to dynamic view#2827
davydkov merged 6 commits into
likec4:mainfrom
kavishkartha05:fix/dynamic-view-variant-not-honored

Conversation

@kavishkartha05

Copy link
Copy Markdown
Contributor

Checklist

  • [✓ ] I've thoroughly read the latest contribution guidelines.
  • [ ✓] I've rebased my branch onto main before creating this PR.
  • [ ✓] My commit messages follow conventional spec
  • [ ✓] I've added tests to cover my changes (if applicable).
  • [ ✓] I've verified that all new and existing tests have passed locally for mobile, tablet, and desktop screen sizes.
  • My change requires documentation updates.
  • I've updated the documentation accordingly.

Fixes #2802. When navigating to a dynamic view, the XState machine's enqueue.assign block in the navigating state never updated dynamicViewVariant to match the incoming view's declared variant, but rather it inherited the previous view's value. Added dynamicViewVariant to both the first-time navigation path and the history-restore path in machine.state.navigating.ts. Added 4 tests covering both paths.

@changeset-bot

changeset-bot Bot commented Apr 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b75f8f8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 20 packages
Name Type
@likec4/diagram Patch
@likec4/playground Patch
likec4 Patch
@likec4/react Patch
@likec4/vscode-preview Patch
likec4-vscode Patch
@likec4/docs-astro Patch
@likec4/style-preset Patch
@likec4/styles Patch
@likec4/config Patch
@likec4/core Patch
@likec4/generators Patch
@likec4/language-server Patch
@likec4/language-services Patch
@likec4/layouts Patch
@likec4/leanix-bridge Patch
@likec4/log Patch
@likec4/mcp Patch
@likec4/tsconfig Patch
@likec4/vite-plugin Patch

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

@coderabbitai

coderabbitai Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a99e1437-a6aa-4d99-9245-facf6795ff70

📥 Commits

Reviewing files that changed from the base of the PR and between 20f1175 and b75f8f8.

📒 Files selected for processing (2)
  • .changeset/fix-dynamic-view-variant.md
  • packages/diagram/src/likec4diagram/state/machine.state.navigating.spec.ts
✅ Files skipped from review due to trivial changes (2)
  • .changeset/fix-dynamic-view-variant.md
  • packages/diagram/src/likec4diagram/state/machine.state.navigating.spec.ts

📝 Walkthrough

Walkthrough

Update navigation handling so context.dynamicViewVariant is determined from incoming view data and fromHistory with a defined precedence; add Vitest actor tests validating variant initialization and restoration across navigation scenarios.

Changes

Cohort / File(s) Summary
State machine update
packages/diagram/src/likec4diagram/state/machine.state.navigating.ts
Adjust update.view logic to set context.dynamicViewVariant with precedence: fromHistory.dynamicViewVariant → incoming view.variant if view._type === 'dynamic' → existing context.dynamicViewVariant. Distinguishes history vs direct navigation assignment paths.
Tests (new)
packages/diagram/src/likec4diagram/state/machine.state.navigating.spec.ts
Add Vitest actor-based specs that mock minimal DiagramView variants and partial XYStoreApi/XYFlowInstance to exercise navigation flows and assert context.dynamicViewVariant during initial load and after navigations (sequence/diagram/element transitions). Uses fake timers and actor helpers.
Release metadata
.changeset/fix-dynamic-view-variant.md
Add changeset bump (patch) noting a fix for dynamic view variant not being applied when navigating to a dynamic view (references issue #2802).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing the dynamicViewVariant to be updated when navigating to a dynamic view, which directly addresses the core issue.
Description check ✅ Passed The PR description covers the key aspects: links to the issue (#2802), explains the problem, details the changes made, and confirms tests were added and verified.
Linked Issues check ✅ Passed The PR successfully addresses issue #2802 by implementing the assignment of dynamicViewVariant from the incoming view's variant during navigation, ensuring the preview honors the declared variant setting.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the dynamicViewVariant assignment issue: modified machine logic, added comprehensive tests, and created a changeset. No unrelated changes detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/diagram/src/likec4diagram/state/machine.state.navigating.spec.ts`:
- Around line 9-22: The fixture mockElementView is using a double-cast "as
unknown as DiagramView" which bypasses TypeScript checks; replace the cast with
a proper typed fixture using either the "satisfies DiagramView" operator or an
explicit builder function so the object shape is validated at compile time.
Update mockElementView (and the similar fixtures at the other ranges mentioned)
to declare the literal as const and append "satisfies DiagramView" or construct
it via a typed helper (e.g., createDiagramView({...})) so the compiler enforces
the DiagramView/XY contract rather than using "as unknown as".
🪄 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: 47fd704e-7614-4986-a0a8-46e5265f299d

📥 Commits

Reviewing files that changed from the base of the PR and between 3190615 and 9c0b9e4.

📒 Files selected for processing (2)
  • packages/diagram/src/likec4diagram/state/machine.state.navigating.spec.ts
  • packages/diagram/src/likec4diagram/state/machine.state.navigating.ts

Comment thread packages/diagram/src/likec4diagram/state/machine.state.navigating.spec.ts Outdated
@kavishkartha05

Copy link
Copy Markdown
Contributor Author

@davydkov would greatly appreciate a review of this PR. Will create a changeset as soon as you approve and are satisfied with it.

@davydkov davydkov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!
I think we can merge this (seems repetitive):

const actor = createTestActor(view)
actor.start()
advanceToReady(actor, view)

I see you have asserts before advanceToReady, but I think they are redundant

What do you think?

@kavishkartha05

Copy link
Copy Markdown
Contributor Author

Yea that makes sense

@kavishkartha05 kavishkartha05 requested a review from davydkov April 2, 2026 01:19
@kavishkartha05

Copy link
Copy Markdown
Contributor Author

@davydkov I removed the redundant asserts. Would greatly appreciate it if you could please take a look at the PR. I will add a changeset if you are satisfied.


it('sets dynamicViewVariant to "sequence" when navigating from a non-dynamic view', () => {
const actor = createTestActor(mockElementView)
actor.start()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move actor.start() to createTestActor

@kavishkartha05 kavishkartha05 requested a review from davydkov April 3, 2026 21:45
@kavishkartha05

Copy link
Copy Markdown
Contributor Author

@davydkov updated! Added changeset as well. Would greatly appreciate a review.

@kavishkartha05

Copy link
Copy Markdown
Contributor Author

@davydkov just wanted to follow up on this. Thank you for your time!

@davydkov davydkov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @kavishkartha05
This weekend was on holidays, sorry for delay

@davydkov davydkov enabled auto-merge (squash) April 7, 2026 06:49
@davydkov davydkov merged commit 1ae3eb6 into likec4:main Apr 7, 2026
14 checks passed
@likec4-ci likec4-ci Bot mentioned this pull request Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preview does not honor dynamic view variant setting

2 participants