fix(web): remember the rendered-markdown choice across threads - #4853
Conversation
The choice lived in panel state keyed to one file path, so leaving the thread tore it down and the panel came back showing source. It is a reading preference, not a property of a file: it now persists the way the panel already persists its explorer state. A line reveal still wins, since a line only exists in the source, and it no longer clears the preference on its way past. Closes pingdotgg#4645. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit dae51be. Configure here.
ApprovabilityVerdict: Approved 3238bcb This PR makes a simple change to persist the markdown rendering preference to localStorage using an existing hook. The change is self-contained with no security or schema implications, and the open review comment is just a clarifying question (the hook already exists). You can customize Macroscope's approvability policy. Learn more. |
Review feedback, and a regression I introduced: each file surface counts its reveals from one, so after dismissing a reveal on one file the first line link to another file carried the same id, was taken for already handled, and never left the rendered view. Pair the id with the path again, the way the state it replaced did. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Right on both counts, and it was a regression I introduced — the state I replaced paired the path with the request id, and I dropped the path. Fixed in a533f3a. Confirmed the precondition rather than taking it on faith. const surfaceId = `file:${relativePath}`;
const surface = fileSurface(relativePath, normalizeRevealLine(line), (existing?.revealRequestId ?? 0) + 1);so every file starts counting at one. Reproduced with two markdown files that link to each other by line, and read the persisted store afterwards: Both at 1, exactly the collision described. Walked through it in a running client:
Without the pairing the last row would have stayed rendered, since the stored id 1 matched.
|
| // Reading markdown rendered is a preference, not a property of one file. Keeping | ||
| // it on the panel meant a thread switch dropped it and forced source back. | ||
| const [renderMarkdownPreferred, setRenderMarkdownPreferred] = useState(initialRenderMarkdown); |
There was a problem hiding this comment.
do we not have a useLocalStorage hook yet??
There was a problem hiding this comment.
We do see comment below @juliusmarminge fixed it and why this approach has been chosen previously.
The hook exists and does this better: it reads, writes, validates and keeps instances in sync, so the hand-rolled initializer and the try/catch around the write both go away. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
oh yea we do and its used by I had followed the neighbouring pattern in this file instead: PS: the explorer state right above still uses the hand-rolled version. Happy to convert it too, but it is unrelated to this fix so I left it alone rather than widening the diff. |
Dismissing prior approval to re-evaluate 3238bcb

What Changed
The rendered-markdown choice in the file preview panel is now a persisted preference instead of panel state tied to one file path.
Why
Reported in #4645. The state was:
It said "rendered is on for this file", so leaving the thread tore the panel down and returning showed source again. The reporter describes it as a preference — "once I've said I want to read markdown rendered, that's my preference until I toggle it back" — so it now persists the way this same panel already persists its explorer state (
FILE_EXPLORER_STORAGE_KEY/initialExplorerOpen), rather than introducing a new mechanism or touching the settings schema.A line reveal still wins over the preference, because a line only exists in the source. It no longer clears the preference on the way past, so toggling once returns you to rendered.
Notes For Review
A limitation worth knowing, which this PR does not change.
rightPanelStorekeepsrevealLine/revealRequestIdas durable surface state and rehydrates them. So if the last thing you did with a file surface was jump to a line, returning to it still shows source: the stored reveal is indistinguishable, at mount, from a fresh one, and treating it as already handled would break the case the reveal exists for — clicking a line link while the panel is closed.That is not a regression. Before this change, returning showed source in every case; now it shows source only in that one. Making it complete means letting the store consume a reveal once it has been applied, which changes shared surface semantics and its persistence, so it felt like a separate change rather than something to fold in here.
Validation
Driven in a running client, on a markdown file whose own content links back to itself so the reveal path can be exercised:
t3code.renderMarkdown=true, view renderedREADME.md:9link while renderedtrueThe last row is the reported scenario. I could not reproduce it myself: the file explorer in my seeded fixture workspace lists no files, so I had no way to open a markdown file without going through a line link. It was checked by the reporter on a real project instead, and I am flagging that rather than implying I measured it.
vp run --filter @t3tools/web test— 1663 passedvp run --filter @t3tools/web typecheck— no errorsvp lint/vp fmt --checkon the changed file — cleanCloses #4645.
Checklist
Note
Low Risk
UI preference persistence in the file preview panel only; no auth, data, or API changes.
Overview
Fixes #4645 by persisting the file preview rendered markdown toggle in
localStorage(t3code.renderMarkdown) viauseLocalStorage, matching how explorer open/close is already stored—not per-file panel state that reset when switching threads.Line reveals still force source view (the line only exists there). A new
handledRevealstate pairs path withrevealRequestIdso a reveal handled on one file does not block reveals on another; toggling rendered again records the current reveal as handled without clearing the stored preference.Reviewed by Cursor Bugbot for commit 3238bcb. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Persist rendered-markdown toggle choice across threads in
FilePreviewPanelmarkdownViewstate with auseLocalStorage-backed preference keyed att3code.renderMarkdown, so the toggle choice survives navigation between threads and files.Macroscope summarized 3238bcb.