t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: Rendered-markdown view for a file in the right sidebar resets to source when you switch threads

Open kristjaningi opened this issue 4 months ago • 1 comments

Before submitting

  • [x] I searched existing issues and did not find a duplicate.
  • [x] I included enough detail to reproduce or investigate the problem.

Area

apps/web

Steps to reproduce

  1. Open a thread and open a .md file in the right-hand file preview panel.
  2. Click the eye toggle ("Show rendered markdown"). The panel switches to the rendered view.
  3. Switch to a different thread.
  4. Switch back to the original thread and open the same .md file.

Expected behavior

The panel is still showing rendered markdown. The view mode should be sticky — once I've said I want to read markdown rendered, that's my preference until I toggle it back.

Actual behavior

The panel is back to raw markdown source, and I have to click the toggle again every time I return to the thread.

Impact

Minor bug or occasional failure

Version or commit

main @ 5719e8ac

Environment

macOS 26.5.2, desktop app

Logs or stack traces

The toggle is backed by component-local state in `FilePreviewPanel`:

  apps/web/src/components/files/FilePreviewPanel.tsx:675
    const [markdownView, setMarkdownView] = useState<{
      path: string | null;
      revealRequestId: number | null;
    }>({ path: null, revealRequestId: null });

Nothing persists it, and it's invalidated two ways:

- `renderMarkdown` requires `markdownView.path === relativePath`
  (FilePreviewPanel.tsx:681), so any change of the open file drops back to
  source.
- The panel is mounted with `key={environmentId:workspaceRoot}`
  (ChatView.tsx:5588), so switching to a thread in another project remounts it
  and resets the state entirely.

The adjacent explorer-open toggle in the same component already persists via
`FILE_EXPLORER_STORAGE_KEY` in localStorage (FilePreviewPanel.tsx:701-711),
which looks like the precedent to follow here.

Screenshots, recordings, or supporting files

No response

Workaround

Click the toggle again each time.

kristjaningi avatar Jul 27 '26 14:07 kristjaningi

Opened #4853.

The choice was panel state keyed to one file path — "rendered is on for this file" — so leaving the thread tore it down. It is now a preference, persisted the way this same panel already persists its explorer state, rather than a new mechanism or a settings-schema change.

What was checked, and by whom:

step result
Toggle rendered, leave the thread, return still rendered — checked by me on a real project
Toggle writes and reloads the preference verified in a running client
Click a file.md:9 link while rendered switches to source and reveals the line; the preference survives
Toggle after that back to rendered

One limitation stays, and it is deliberate. rightPanelStore keeps revealLine as durable surface state and restores it across reloads, so if the last thing you did with a file was jump to a line, returning to it still shows source. That is not new — before this change, returning showed source in every case; now only in that one. Making it complete means letting the store consume a reveal once applied, which changes shared surface semantics for every file surface, not just markdown. That belongs in its own change rather than folded in here.

Sy-D avatar Jul 29 '26 16:07 Sy-D