Skip to content

[fix] Fix inverted Text/Markdown view in playground message editors#4554

Open
mmabrouk wants to merge 2 commits into
release/v0.102.0from
fix/playground-message-view-mode
Open

[fix] Fix inverted Text/Markdown view in playground message editors#4554
mmabrouk wants to merge 2 commits into
release/v0.102.0from
fix/playground-message-view-mode

Conversation

@mmabrouk
Copy link
Copy Markdown
Member

@mmabrouk mmabrouk commented Jun 5, 2026

Context

In the playground message editors, the Text/Markdown toggle was inverted. The default mode is "Text", but it rendered markdown, and picking "Markdown" showed the raw source. The dropdown mapped markdownView to the wrong boolean (viewMode === "markdown"), and markdownView={true} means "show raw source", so every label did the opposite of what it said. The live markdown toggle button had the same inverted icon/tooltip.

On top of that, the Text mode rendered in a monospace code font with code-block padding, and the message text did not line up with the role label above it.

Changes

  • Swap fix. Map markdownView to viewMode === "text" everywhere a message editor is rendered: chat turns (TurnMessageAdapter), prompt messages (ChatMessageList), variable inputs (VariableControlAdapter), and the JSON object field (JsonObjectField). Now "Text" shows raw text and "Markdown" renders, matching the labels. Default is "Text".
  • Toggle button. Fixed the inverted icon and tooltip on the live MarkdownToggleButton (when raw source is shown it now offers "Preview markdown", and vice versa).
  • Shared, persisted mode. Replaced the per-message useState with a shared atomWithStorage (messageViewModeAtom), so switching one message switches all of them and the choice survives a refresh.
  • Text mode styling. Text mode now uses the editor's proportional font instead of monospace, with spacing that matches the rendered markdown view. Message text and placeholder align with the first character of the role label.

Before: default "Text" showed rendered markdown; "Markdown" showed raw monospace source.
After: default "Text" shows raw proportional text; "Markdown" renders.

Notes

  • The mode atom is intentionally a single app-wide preference, so it is also shared by the drill-in message fields, not only the playground. The storage key reflects that (agenta:message-view-mode).
  • The text-alignment padding is applied via globals.css (scoped to .agenta-chat-message-editor) rather than the editorClassName prop, because ChatMessageEditor renders the editor with noProvider, a mode where Editor currently drops className. That noProvider bug is tracked as a separate follow-up; a stacked PR will fix it and migrate this padding to the prop.
  • Same swap also exists in the observability drill-in viewer (DrillInContent); left out of this PR since fixing it changes that surface's behavior and needs its own verification.

Tests

  • tsc --noEmit passes for @agenta/ui and @agenta/playground-ui.
  • Prettier and ESLint pass on the changed files.
  • Manually verified in the running app: default Text mode, correct swap, proportional font, and role/text alignment.

The message editors had the Text/Markdown view inverted: the view-mode
dropdown mapped markdownView to the wrong boolean, so picking 'Markdown'
showed raw source and the default 'Text' showed rendered markdown. Fixed
the mapping across every message editor (chat turns, prompt messages,
variable inputs, the JSON object field) and the live markdown toggle
button, whose icon and tooltip were also inverted.

Also:
- The view mode is now a shared, persisted atom (messageViewModeAtom), so
  switching one message switches all and the choice survives a refresh.
- Text mode renders with the editor's proportional font instead of
  monospace, with spacing that matches the rendered markdown view.
- Message text and placeholder align with the role label above them.
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 5, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agenta-documentation Ready Ready Preview, Comment Jun 5, 2026 12:28pm

Request Review

@dosubot dosubot Bot added bug Something isn't working Frontend labels Jun 5, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 5, 2026

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d4a68a4f-e5b0-44a6-8be1-1b7a5b2516e0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR centralizes message editor view-mode state using a Jotai atom persisted in localStorage, migrates multiple components from local state to the shared atom, flips the markdownView boolean condition to use "text" mode, updates UI labels and icons accordingly, and adds CSS styling for message editor text alignment.

Changes

Message Editor View-Mode Persistence and Alignment

Layer / File(s) Summary
Persistent view-mode atom creation and export
web/packages/agenta-ui/src/drill-in/state/messageViewModeAtom.ts, web/packages/agenta-ui/src/drill-in/index.ts
New Jotai atom messageViewModeAtom is created with atomWithStorage to persist editor view mode in localStorage under agenta:message-view-mode, defaulting to "text", and is re-exported from the drill-in module.
Migrate component state to shared atom
web/packages/agenta-playground-ui/src/components/adapters/TurnMessageAdapter.tsx, web/packages/agenta-ui/src/ChatMessage/components/ChatMessageList.tsx
TurnMessageAdapter and ChatMessageList replace local useState with useAtom(messageViewModeAtom), importing the new atom and Jotai hook to enable shared, persisted view-mode state across editors.
Invert markdownView boolean condition
web/packages/agenta-playground-ui/src/components/adapters/TurnMessageAdapter.tsx, web/packages/agenta-playground-ui/src/components/adapters/VariableControlAdapter.tsx, web/packages/agenta-ui/src/ChatMessage/components/ChatMessageList.tsx, web/packages/agenta-ui/src/drill-in/FieldRenderers/JsonObjectField.tsx
The markdownView prop condition flips from viewMode === "markdown" to viewMode === "text" in the tool-call editor, normal editor, markdown synchronizer, message editor, and object field renderer.
Update UI labels and icons
web/packages/agenta-ui/src/ChatMessage/components/MarkdownToggleButton.tsx, web/packages/agenta-ui/src/ChatMessage/components/ChatMessageList.tsx
MarkdownToggleButton inverts tooltip text and swaps icon rendering to match the flipped logic, and ChatMessageList adds a type assertion for the ViewModeDropdown value.
CSS and component wrapper styling
web/oss/src/styles/globals.css, web/packages/agenta-ui/src/ChatMessage/components/ChatMessageEditor.tsx
globals.css adjusts markdown-view code styling to use inherited fonts and removes padding/margins for alignment, adds new .agenta-chat-message-editor styling with --ag-message-inline-pad for text alignment, and ChatMessageEditor wraps its container with the new styling hook class.

Sequence Diagram

sequenceDiagram
  participant localStorage as Browser Storage
  participant atom as messageViewModeAtom
  participant TurnAdapter as TurnMessageAdapter
  participant ChatList as ChatMessageList
  participant Editor as ChatMessageEditor

  localStorage->>atom: Load persisted view mode ("text")
  TurnAdapter->>atom: Read viewMode via useAtom
  ChatList->>atom: Read viewMode via useAtom
  atom-->>TurnAdapter: Provide shared viewMode
  atom-->>ChatList: Provide shared viewMode
  TurnAdapter->>Editor: Pass markdownView = (viewMode === "text")
  ChatList->>Editor: Pass markdownView = (viewMode === "text")
  Editor->>Editor: Render with inherited fonts (markdown mode off)
  Editor->>localStorage: Persist viewMode changes on user toggle
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • Agenta-AI/agenta#4482: Both PRs touch the same markdown/text toggling wiring—updating markdownView/view-mode propagation and related Lexical synchronization in ChatMessageEditor, ChatMessageList, TurnMessageAdapter, and JsonObjectField—so the changes are code-level related.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: correcting the inverted Text/Markdown view modes in playground message editors.
Description check ✅ Passed The description comprehensively explains the context, changes, and rationale for the fix across all affected message editors.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 60.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/playground-message-view-mode

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e4d6a418-df8e-4d2e-ac00-03f6e42d6de8

📥 Commits

Reviewing files that changed from the base of the PR and between 98b8a9d and a8529a4.

📒 Files selected for processing (9)
  • web/oss/src/styles/globals.css
  • web/packages/agenta-playground-ui/src/components/adapters/TurnMessageAdapter.tsx
  • web/packages/agenta-playground-ui/src/components/adapters/VariableControlAdapter.tsx
  • web/packages/agenta-ui/src/ChatMessage/components/ChatMessageEditor.tsx
  • web/packages/agenta-ui/src/ChatMessage/components/ChatMessageList.tsx
  • web/packages/agenta-ui/src/ChatMessage/components/MarkdownToggleButton.tsx
  • web/packages/agenta-ui/src/drill-in/FieldRenderers/JsonObjectField.tsx
  • web/packages/agenta-ui/src/drill-in/index.ts
  • web/packages/agenta-ui/src/drill-in/state/messageViewModeAtom.ts

Comment thread web/packages/agenta-ui/src/ChatMessage/components/ChatMessageList.tsx Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Railway Preview Environment

Preview URL https://gateway-production-685b.up.railway.app/w
Project agenta-oss-pr-4554
Image tag pr-4554-6714fed
Status Deployed
Railway logs Open logs
Workflow logs View workflow run
Updated at 2026-06-05T12:36:56.480Z

@bekossy bekossy changed the base branch from main to release/v0.102.0 June 5, 2026 10:43
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jun 5, 2026
The shared messageViewModeAtom is typed ViewMode, which includes "form". Chat
and prompt message editors only handle text/markdown/json/yaml, and a cast
hid the mismatch, so a persisted "form" value could leave the dropdown and
editor inconsistent. Add toMessageViewMode() (form -> text) and use it in
ChatMessageList and TurnMessageAdapter before deriving mode-dependent state,
removing the unsafe cast. Addresses CodeRabbit review on PR #4554.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Frontend size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants