Skip to content

Commit dae51be

Browse files
Simon Dobaclaude
andcommitted
fix(web): remember the rendered-markdown choice across threads
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 #4645. Co-Authored-By: Claude Opus 5 <[email protected]>
1 parent 49c0d96 commit dae51be

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

‎apps/web/src/components/files/FilePreviewPanel.tsx‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ interface FilePreviewPanelProps {
7979
}
8080

8181
const FILE_EXPLORER_STORAGE_KEY = "t3code.fileExplorerOpen";
82+
const RENDER_MARKDOWN_STORAGE_KEY = "t3code.renderMarkdown";
8283
const FILE_SAVE_DEBOUNCE_MS = 500;
8384
const FILE_LINK_REVEAL_ATTRIBUTE = "data-file-link-reveal";
8485
const FILE_LINK_REVEAL_UNSAFE_CSS = `
@@ -645,6 +646,15 @@ function initialExplorerOpen(): boolean {
645646
}
646647
}
647648

649+
function initialRenderMarkdown(): boolean {
650+
try {
651+
return getLocalStorageItem(RENDER_MARKDOWN_STORAGE_KEY, Schema.Boolean) ?? false;
652+
} catch (error) {
653+
console.error(error);
654+
return false;
655+
}
656+
}
657+
648658
export default function FilePreviewPanel({
649659
environmentId,
650660
cwd,
@@ -672,16 +682,17 @@ export default function FilePreviewPanel({
672682
const isImage = relativePath !== null && isWorkspaceImagePreviewPath(relativePath);
673683
const file = useProjectFileQuery(environmentId, cwd, relativePath, !isImage);
674684
const [explorerOpen, setExplorerOpen] = useState(initialExplorerOpen);
675-
const [markdownView, setMarkdownView] = useState<{
676-
path: string | null;
677-
revealRequestId: number | null;
678-
}>({ path: null, revealRequestId: null });
685+
// Reading markdown rendered is a preference, not a property of one file. Keeping
686+
// it on the panel meant a thread switch dropped it and forced source back.
687+
const [renderMarkdownPreferred, setRenderMarkdownPreferred] = useState(initialRenderMarkdown);
688+
const [revealHandledRequestId, setRevealHandledRequestId] = useState<number | null>(null);
679689
const breadcrumbRef = useRef<HTMLDivElement>(null);
680690
const isMarkdown = relativePath ? isMarkdownPreviewFile(relativePath) : false;
691+
// A reveal still wins over the preference: the line only exists in the source.
681692
const renderMarkdown =
682693
isMarkdown &&
683-
markdownView.path === relativePath &&
684-
(revealLine === null || markdownView.revealRequestId === revealRequestId);
694+
renderMarkdownPreferred &&
695+
(revealLine === null || revealHandledRequestId === revealRequestId);
685696
const canOpenInBrowser =
686697
relativePath !== null && isPreviewSupportedInRuntime() && isBrowserPreviewFile(relativePath);
687698
const absolutePath = relativePath ? resolvePathLinkTarget(relativePath, cwd) : null;
@@ -788,10 +799,13 @@ export default function FilePreviewPanel({
788799
className="shrink-0"
789800
pressed={renderMarkdown}
790801
onPressedChange={(pressed) => {
791-
setMarkdownView({
792-
path: pressed ? relativePath : null,
793-
revealRequestId: pressed ? revealRequestId : null,
794-
});
802+
setRenderMarkdownPreferred(pressed);
803+
setRevealHandledRequestId(pressed ? revealRequestId : null);
804+
try {
805+
setLocalStorageItem(RENDER_MARKDOWN_STORAGE_KEY, pressed, Schema.Boolean);
806+
} catch (error) {
807+
console.error(error);
808+
}
795809
}}
796810
aria-label={renderMarkdown ? "Show markdown source" : "Show rendered markdown"}
797811
variant="ghost"

0 commit comments

Comments
 (0)