Skip to content

Markdown preview doesn't refresh/reload when the file is overwritten #265277

Description

@sid-antzai

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:

  1. Generate a markdown file with some content
  2. Open the markdown in VS Code and preview using the "Open Preview" button
Image

Do not close the VS Code instance

  1. Override the file from 1, may be by downloading/copying a markdown file with the same name.
  2. Now open the new file in VS Code and preview the data
  3. The preview from the earlier version of the file is shown and not the latest file
Image

Activity

  1. vs-code-engineering commented on Sep 5, 2025

    @vs-code-engineering
    Contributor

    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!

  2. sid-antzai commented on Sep 5, 2025

    @sid-antzai
    Author

    I updated the version to 1.103.2 and I am still facing the same issue

  3. ahernandez411 commented on Sep 23, 2025

    @ahernandez411

    I have seen this behavior as long as I can remember. The only workaround I have ever done is:

    1. Copy the contents
    2. Rename the file
    3. Delete the file
    4. Recreate the file
    5. Copy the contents back

    I wish there were a refresh button or something like that. We shouldn't have to use workarounds for this

  4. added
    help wanted
    markdown-ext
    on Sep 29, 2025
  5. added a commit that references this issue on Oct 4, 2025
    6f86468
  6. mjbvz commented on Nov 18, 2025

    @mjbvz
    Contributor

    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 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

  7. added
    bug
    on Dec 9, 2025
  8. added this to the Backlog milestone on Dec 9, 2025
  9. added
    team-low-hanging
    on Dec 9, 2025
  10. Pierre-Bartet commented on Dec 11, 2025

    @Pierre-Bartet

    Never noticed this bug until today, quite a nasty one when you are not looking at the file you think you are looking at.

  11. anthony-spruyt commented on Jan 1, 2026

    @anthony-spruyt

    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.

  12. nixjdm commented on Feb 18, 2026

    @nixjdm

    I had to manually edit it to get the preview to detect there were changes.

    Same with Codex. I added a space and saved the file, then the changes were picked up. I'm on VSCodium v1.108.20787

  13. 32 remaining items

  14. coolitbozzo commented on Jul 15, 2026

    @coolitbozzo

    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:

    1. Open a .md file in VS Code.
    2. Open the built-in Markdown preview.
    3. Edit and save the file.
    4. View or reopen the preview.

    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.

    • VS Code version: 1.128.1
    • OS: Windows 11 x64
    • Extensions disabled: No
  15. aaronstone-lut commented on Jul 21, 2026

    @aaronstone-lut

    Reproduce Report for Markdown Preview Bug

    I faced the Markdown preview sync issue on Ubuntu/ Windows based on the test case specifications.

    Environment:

    • OS: Ubuntu 26.04 Desktop / Windows 11 Home
    • VS Code Version: 1.129

    Steps to Reproduce:

    1. Open a README.md file in VS Code and open its markdown preview pane (Ctrl+Shift+V).
    2. Keep VS Code running in the background.
    3. Overwrite the README.md file from outside VS Code.
    4. Return to VS Code and switch between the source code tab and the preview tab.

    Actual Behavior:

    • The source tab correctly reloads and shows the new content from the disk.
    • However, the Markdown preview pane fails to sync automatically. It keeps rendering the old version of the document.

    Expected Behavior:

    • The Markdown preview pane should instantly detect file changes on the disk and refresh its rendered output to match the source tab automatically.
  16. deniskim-gh commented on Jul 31, 2026

    @deniskim-gh

    Still a problem

  17. eduardomourar commented on Aug 1, 2026

    @eduardomourar

    I still have this issue. Another workaround is to:

    1. Focus the Markdown preview window or the .md editor tab.
    2. Open the Command Palette (Ctrl+Shift+P on Windows/Linux or Cmd+Shift+P on macOS).
    3. Type and select Markdown: Refresh Preview.
  18. isvec commented on Aug 8, 2026

    @isvec

    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.

    This is the single best advice for a workaround. Thanks.

  19. Atreyu-94 commented on Aug 20, 2026

    @Atreyu-94

    This is happening not only in Markdown Preview but also in the new Markdown Editor. It's quite annoying, to be honest.

  20. ladimolnar commented on Aug 25, 2026

    @ladimolnar

    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

    1. Create two Markdown files: D1.md and D2.md.
    2. Set the initial content of D1.md to D1-A.
    3. Open both files in VS Code.
    4. View D1.md in Markdown Preview and verify that VS Code displays D1-A.
    5. Modify D1.md externally, replacing D1-A with D1-B.
    6. Verify that VS Code correctly refreshes the preview and displays D1-B.
    7. Switch to the D2.md tab.
    8. 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.

    OS Name Microsoft Windows 11 Pro

    VS Code About info:

    Version: 1.130.0 (system setup)
    Commit: 1b6a188127eeaf9194f945eb6eb89a657e93c54c
    Date: 2026-07-22T14:55:04Z
    Electron: 42.6.0
    ElectronBuildId: 14623276
    Chromium: 148.0.7778.280
    Node.js: 24.18.0
    V8: 14.8.178.38-electron.0
    OS: Windows_NT x64 10.0.26200
    
    
  21. jrbarkin commented on Sep 1, 2026

    @jrbarkin

    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):

    1. mkdir /tmp/mdbug && printf '# V0\n' > /tmp/mdbug/test.md
    2. Open the folder, right-click test.md in the explorer → Open Preview. Don't open it in an editor.
    3. Wait more than three minutes.
    4. printf '# CHANGED\n' > /tmp/mdbug/test.md
    5. 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.

  22. ihaventcomeupanameyet commented on Sep 5, 2026

    @ihaventcomeupanameyet

    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).

  23. bompus commented on Sep 5, 2026

    @bompus
    Contributor

    The reports in this issue split into two paths, and it may help to keep them apart when testing fixes:

    1. The preview updates while visible, the user switches to another tab and back, and the old content is shown. The webview is discarded when the panel is hidden and rebuilt from a webview.html that 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 for vscode.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).
    2. The preview is closed and reopened, or opened fresh, and shows old content. That is a different path, covered by Fix stale markdown preview after reopening document #332081 and Compare document identity when deciding if the preview needs updating #333712 (and Preview of a Markdown file shows a cached copy, not the current version #331900).

    #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.

  24. jqit-ricky commented on Oct 1, 2026

    @jqit-ricky

    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.

  25. lostheadset commented on Oct 18, 2026

    @lostheadset

    141.2 still here

  26. kenrooted commented on Oct 26, 2026

    @kenrooted

    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.

    1. ~/tmp/vscode-test/LAXA.md contains # Heading v1; ~/tmp/vscode-test/other.md contains anything.
    2. code -r ~/tmp/vscode-test/LAXA.md, then Cmd+Shift+V (the preview replaces the editor tab).
    3. 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).
    4. code -r ~/tmp/vscode-test/other.md
    5. Back to the preview of LAXA.md → it shows # Heading v1 without TEST 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugmarkdown-extteam-low-hanging

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions