You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Markdown preview doesn't refresh/reload when the file is overwritten #265277
bugIssue identified by VS Code Team member as probable bugmarkdown-extThe Markdown extension: language features and previewteam-low-hangingLow effort issues team members can help fix. No external contributions will be accepted.
Does this issue occur when all extensions are disabled?: Yes
VS Code Version: 1.102.3
OS Version: Microsoft Windows 11 Pro, 10.0.26100 Build 26100
Steps to Reproduce:
Generate a markdown file with some content
Open the markdown in VS Code and preview using the "Open Preview" button
Do not close the VS Code instance
Override the file from 1, may be by downloading/copying a markdown file with the same name.
Now open the new file in VS Code and preview the data
The preview from the earlier version of the file is shown and not the latest file
Reacted by Adam Hernandez, Cary Symes, Pierre-Bartet, Lance Uymatiao, Chris Agri, Alexey Zaytsev, berk-steer73, RobLoctax, still-dreaming-1, Stormrage-DJ and 23 more
Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.103.2. Please try upgrading to the latest version and checking whether this issue remains.
My guess is this has something to do with the isPreviewOf check in the watcher callback. On windows the most likely cause of issues like this something related to the drive letter or to path casing. You can also try the Markdown: Refresh preview command to see if that forces a refresh to narrow things down
I still have this issue. Another workaround is to:
Focus the Markdown preview window or the .md editor tab.
Open the Command Palette (Ctrl+Shift+P on Windows/Linux or Cmd+Shift+P on macOS).
Type and select Markdown: Refresh Preview.
Reacted by Michał Stolarski, Markus Ernst, Tom Busby, Tunji Gbadamosi, Liam Bartsch, Philip Sosnin, Denton Krietz, Vincent Martin, zarovinskyi and Erick Giraldo
Just to be clear: The displayed content is initially updated correctly. After switching to another tab and then switching back, VS Code reverts the displayed content to an older, incorrect version.
Steps to reproduce
Create two Markdown files: D1.md and D2.md.
Set the initial content of D1.md to D1-A.
Open both files in VS Code.
View D1.md in Markdown Preview and verify that VS Code displays D1-A.
Modify D1.md externally, replacing D1-A with D1-B.
Verify that VS Code correctly refreshes the preview and displays D1-B.
Switch to the D2.md tab.
Switch back to the D1.md preview.
Expected behavior: VS Code continues to display D1-B, which is the current content of D1.md on disk. Actual behavior: VS Code displays D1-A again.
The important point: VS Code initially detects the external change and correctly displays version D1-B. The stale content appears only after switching away from D1.md and returning to it. In other words, the displayed content transitions from correct to incorrect even though the file on disk remains unchanged at version D1-B.
I spent some time instrumenting this and think I have the mechanism, plus a reproduction that works
reliably. Posting here since this is where the reports are — the issue is labelled team-low-hanging so I've filed against #331900 instead, which looks like the same bug.
Why it's been hard to reproduce: the preview works fine for the first few minutes. A preview
opened from the explorer has no editor holding the document open, so the document survives only on
the lease taken by openTextDocument, which lapses after a few minutes and is never renewed. Before
it lapses, onDidChangeTextDocument drives the refresh and everything is correct. After it lapses,
the next update re-opens the file as a new document whose version numbering restarts at 1.
Two separate caches key on (uri, version) and both then match the stale entry:
PreviewDocumentVersion.equals (preview/preview.ts) — #updatePreview returns early, so no
render is even attempted.
TokenCache (markdownEngine.ts) — if you force past the first one, this serves the previously
cached tokens.
Reproduction (the three-minute wait is the part that's usually missing):
Open the folder, right-click test.md in the explorer → Open Preview. Don't open it in an editor.
Wait more than three minutes.
printf '# CHANGED\n' > /tmp/mdbug/test.md
The preview still shows V0, permanently. Opening the file in an editor fixes it, because the
editor holds its own reference and the document never closes.
A couple of dead ends, measured, in case they save anyone time:
Subscribing the preview's watcher to onDidCreate does nothing. I assumed atomic writers
(temp file + rename) would emit only a create event. Logging watcher events for in-place writes,
same-directory renames, cross-directory renames and unlink-then-create: every one emits onDidChange too. The existing subscription already receives the event.
Forcing the update from the watcher doesn't work either — the token cache defeats it one layer
down, and it costs a full webview reload per write.
This is also the answer to the question asked when closing #297649 ("have you explored why the
existing events aren't working?"): they fire correctly. The update is discarded afterwards.
Fixes: #332081 covers the token cache; I've opened #333712 for the preview version comparison.
Both are needed — I built all four combinations and only the two together produce a correct preview.
I’m seeing the same issue when my codex making change to md files. I have to add and removing a space in the Markdown editor, then saving the file, forces the preview to refresh and display the current content(pretty annoying).
#316756 removes the watcher guard for documents VS Code already tracks. It does not change what a hidden panel is rebuilt from, so path 1 stays stale with it alone.
Reacted by Liam Bartsch, Victor L. and Matteus Kalis
Same behaviour on Windows, reproduced three times today.
VS Code 1.140.0 (07f806f), Windows 11 Pro 10.0.26200, built-in Markdown preview, no third-party markdown extension.
The file (a generated DASHBOARD.md) is overwritten on disk by an external process: a scheduled task runs git pull --ff-only every 5 minutes in that clone.
A text editor tab opened afterwards shows the new content. A preview tab opened earlier keeps the old render until "Refresh Preview" is chosen from the tab menu, or the window is reloaded.
Possibly relevant: the workspace holds about 300 git worktrees under one folder, so a dropped watcher event is plausible. Happy to test with files.watcherExclude if that helps.
Still reproduces on VS Code 1.143.1 (e646868, arm64), macOS 27.0.1, Apple silicon, with all extensions disabled (code --disable-extensions -n). Reproduced in a plain local folder and in a Google Drive for desktop folder.
A trigger I haven't seen mentioned here: opening another file from the terminal with code -r.
code -r ~/tmp/vscode-test/LAXA.md, then Cmd+Shift+V (the preview replaces the editor tab).
Outside VS Code: printf 'TEST LINE 1\n\n# Heading v1\n' > ~/tmp/vscode-test/LAXA.md → the preview updates and shows TEST LINE 1 (as expected).
code -r ~/tmp/vscode-test/other.md
Back to the preview of LAXA.md → it shows # Heading v1withoutTEST LINE 1, i.e. the content from when the preview was opened. The file on disk is unchanged.
Control: with a text editor tab instead of the preview, step 5 shows the new content.
This looks like the "hidden panel rebuilt from stale webview.html" path that #334681 addresses.
bugIssue identified by VS Code Team member as probable bugmarkdown-extThe Markdown extension: language features and previewteam-low-hangingLow effort issues team members can help fix. No external contributions will be accepted.
Activity
vs-code-engineering commentedon Sep 5, 2025
Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.103.2. Please try upgrading to the latest version and checking whether this issue remains.
Happy Coding!
sid-antzai commentedon Sep 5, 2025
I updated the version to 1.103.2 and I am still facing the same issue
ahernandez411 commentedon Sep 23, 2025
I have seen this behavior as long as I can remember. The only workaround I have ever done is:
I wish there were a refresh button or something like that. We shouldn't have to use workarounds for this
feat: add file system watchers for markdown preview updates
mjbvz commentedon Nov 18, 2025
For anyone looking into this: we already have a file watcher that should handle this. It seems to work fine in my testing on MacOS
My guess is this has something to do with the
isPreviewOfcheck in the watcher callback. On windows the most likely cause of issues like this something related to the drive letter or to path casing. You can also try theMarkdown: Refresh previewcommand to see if that forces a refresh to narrow things downPierre-Bartet commentedon Dec 11, 2025
Never noticed this bug until today, quite a nasty one when you are not looking at the file you think you are looking at.
anthony-spruyt commentedon Jan 1, 2026
Also ran into this today. Claude made some changs and it was not detected. I had to manually edit it to get the preview to detect there were changes.
nixjdm commentedon Feb 18, 2026
Same with Codex. I added a space and saved the file, then the changes were picked up. I'm on VSCodium v1.108.20787
32 remaining items
coolitbozzo commentedon Jul 15, 2026
I am also experiencing this issue, but in my case the Markdown file is not being replaced or overwritten externally.
It occurs during normal editing:
.mdfile in VS Code.Occasionally, the preview displays an older version instead of the latest saved content. The editor itself shows the correct updated content.
The issue is intermittent and does not occur after every save.
aaronstone-lut commentedon Jul 21, 2026
Reproduce Report for Markdown Preview Bug
I faced the Markdown preview sync issue on Ubuntu/ Windows based on the test case specifications.
Environment:
Steps to Reproduce:
README.mdfile in VS Code and open its markdown preview pane (Ctrl+Shift+V).README.mdfile from outside VS Code.Actual Behavior:
Expected Behavior:
deniskim-gh commentedon Jul 31, 2026
Still a problem
eduardomourar commentedon Aug 1, 2026
I still have this issue. Another workaround is to:
Markdown: Refresh Preview.isvec commentedon Aug 8, 2026
This is the single best advice for a workaround. Thanks.
Atreyu-94 commentedon Aug 20, 2026
This is happening not only in Markdown Preview but also in the new Markdown Editor. It's quite annoying, to be honest.
ladimolnar commentedon Aug 25, 2026
Just to be clear: The displayed content is initially updated correctly. After switching to another tab and then switching back, VS Code reverts the displayed content to an older, incorrect version.
Steps to reproduce
Expected behavior: VS Code continues to display D1-B, which is the current content of D1.md on disk.
Actual behavior: VS Code displays D1-A again.
The important point: VS Code initially detects the external change and correctly displays version D1-B. The stale content appears only after switching away from D1.md and returning to it. In other words, the displayed content transitions from correct to incorrect even though the file on disk remains unchanged at version D1-B.
OS Name Microsoft Windows 11 Pro
VS Code About info:
jrbarkin commentedon Sep 1, 2026
I spent some time instrumenting this and think I have the mechanism, plus a reproduction that works
reliably. Posting here since this is where the reports are — the issue is labelled
team-low-hangingso I've filed against #331900 instead, which looks like the same bug.Why it's been hard to reproduce: the preview works fine for the first few minutes. A preview
opened from the explorer has no editor holding the document open, so the document survives only on
the lease taken by
openTextDocument, which lapses after a few minutes and is never renewed. Beforeit lapses,
onDidChangeTextDocumentdrives the refresh and everything is correct. After it lapses,the next update re-opens the file as a new document whose version numbering restarts at 1.
Two separate caches key on
(uri, version)and both then match the stale entry:PreviewDocumentVersion.equals(preview/preview.ts) —#updatePreviewreturns early, so norender is even attempted.
TokenCache(markdownEngine.ts) — if you force past the first one, this serves the previouslycached tokens.
Reproduction (the three-minute wait is the part that's usually missing):
mkdir /tmp/mdbug && printf '# V0\n' > /tmp/mdbug/test.mdtest.mdin the explorer → Open Preview. Don't open it in an editor.printf '# CHANGED\n' > /tmp/mdbug/test.mdV0, permanently. Opening the file in an editor fixes it, because theeditor holds its own reference and the document never closes.
A couple of dead ends, measured, in case they save anyone time:
onDidCreatedoes nothing. I assumed atomic writers(temp file + rename) would emit only a create event. Logging watcher events for in-place writes,
same-directory renames, cross-directory renames and unlink-then-create: every one emits
onDidChangetoo. The existing subscription already receives the event.down, and it costs a full webview reload per write.
This is also the answer to the question asked when closing #297649 ("have you explored why the
existing events aren't working?"): they fire correctly. The update is discarded afterwards.
Fixes: #332081 covers the token cache; I've opened #333712 for the preview version comparison.
Both are needed — I built all four combinations and only the two together produce a correct preview.
ihaventcomeupanameyet commentedon Sep 5, 2026
I’m seeing the same issue when my codex making change to md files. I have to add and removing a space in the Markdown editor, then saving the file, forces the preview to refresh and display the current content(pretty annoying).
bompus commentedon Sep 5, 2026
The reports in this issue split into two paths, and it may help to keep them apart when testing fixes:
webview.htmlthat only the last full render wrote; in-place updates never reach it. Refresh markdown preview html before a hidden panel is rebuilt #334681 fixes that for the dynamic preview and forvscode.markdown.preview.editor(same mechanism as Markdown preview show cached file when switching to another tab and then switching back #271233, Markdown preview text is missing after tabs are switched #165188, Markdown preview show cached file when switching to another tab and then switching back #244328).#316756 removes the watcher guard for documents VS Code already tracks. It does not change what a hidden panel is rebuilt from, so path 1 stays stale with it alone.
jqit-ricky commentedon Oct 1, 2026
Same behaviour on Windows, reproduced three times today.
VS Code 1.140.0 (07f806f), Windows 11 Pro 10.0.26200, built-in Markdown preview, no third-party markdown extension.
The file (a generated
DASHBOARD.md) is overwritten on disk by an external process: a scheduled task runsgit pull --ff-onlyevery 5 minutes in that clone.A text editor tab opened afterwards shows the new content. A preview tab opened earlier keeps the old render until "Refresh Preview" is chosen from the tab menu, or the window is reloaded.
Possibly relevant: the workspace holds about 300 git worktrees under one folder, so a dropped watcher event is plausible. Happy to test with
files.watcherExcludeif that helps.Refresh markdown preview html before a hidden panel is rebuilt
lostheadset commentedon Oct 18, 2026
141.2 still here
kenrooted commentedon Oct 26, 2026
Still reproduces on VS Code 1.143.1 (e646868, arm64), macOS 27.0.1, Apple silicon, with all extensions disabled (
code --disable-extensions -n). Reproduced in a plain local folder and in a Google Drive for desktop folder.A trigger I haven't seen mentioned here: opening another file from the terminal with
code -r.~/tmp/vscode-test/LAXA.mdcontains# Heading v1;~/tmp/vscode-test/other.mdcontains anything.code -r ~/tmp/vscode-test/LAXA.md, then Cmd+Shift+V (the preview replaces the editor tab).printf 'TEST LINE 1\n\n# Heading v1\n' > ~/tmp/vscode-test/LAXA.md→ the preview updates and showsTEST LINE 1(as expected).code -r ~/tmp/vscode-test/other.mdLAXA.md→ it shows# Heading v1withoutTEST LINE 1, i.e. the content from when the preview was opened. The file on disk is unchanged.Control: with a text editor tab instead of the preview, step 5 shows the new content.
This looks like the "hidden panel rebuilt from stale
webview.html" path that #334681 addresses.Refresh markdown preview html before a hidden panel is rebuilt (#334681)