Skip to content

fix(preview): reload fetches images edited on disk again - #1067

Merged
PathGao merged 2 commits into
masterfrom
fix/reload-refetches-images
Nov 8, 2026
Merged

PathGao merged 2 commits into
masterfrom
fix/reload-refetches-images

Conversation

@PathGao

@PathGao PathGao commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

Closes #1066. RoyiAvital regenerated the images a document embeds, clicked Reload, and the preview kept the old pictures.

Reload re-reads the document, not its images. The preview only re-inserts blocks whose rendered markup changed, so an image block whose Markdown is the same is left in place. A re-inserted <img> would not help either: its asset URL is unchanged, and the webview reuses the image it already decoded for that URL. This predates the incremental preview: the earlier {@html} article also skipped an identical string.

Each explicit reload (Reload from disk, and Reload on the external-change bar) now bumps an image generation. The preview stamps it onto every <img> in the renderer's markup, which changes exactly the blocks that hold an image, and processBlockMarkup turns it into ?v=N on local asset URLs. The asset protocol reads only the URL path, and export, copy and "Save image as" parse the path too, so the query reaches nothing but the cache. Remote images keep the URL their author wrote.

Left alone: refreshing when an image changes on disk without a reload. That needs a watcher per image, as VS Code's preview has; MarkText and Obsidian also only refresh on request. The generation is shared by all tabs, so after a reload another tab's image blocks are re-inserted once, the next time that tab renders. The stamp is a text replace, so <img written inside raw HTML's attribute values or comments gets it too; it is unquoted, so it cannot close the attribute it lands in.

Tests: scripts/preview.imageReload.test.ts runs processMarkdownHtml on stamped markup: the image block changes and the text block does not, the URL gets ?v=1 then ?v=2, the stamp attribute does not reach the preview, remote URLs are untouched, and an <img inside an attribute value leaves the attribute whole (red with a quoted stamp). documents.conflicts.spec.ts checks that both reload commands start a new generation. Reverting the fix removes the functions these call, so they fail to load rather than going red on an assertion. npm run check, the node suite (952) and vitest (744) pass. Tried in a macOS release build: overwrote a PNG red to green to blue, and each Reload showed the new colour. Not tried on Windows.

Reload re-read the document but kept every image: a block whose markup
did not change is not re-inserted, and an unchanged URL is served from
the webview's decoded copy. Each explicit reload now stamps a generation
onto <img>, so only the blocks holding an image are replaced, and their
local URLs carry it as a query the asset protocol ignores.
Raw HTML can hold the text <img inside an attribute value. A quoted
stamp closed that attribute early; an unquoted one cannot.
@PathGao
PathGao merged commit 86718bd into master Nov 8, 2026
4 checks passed
@PathGao
PathGao deleted the fix/reload-refetches-images branch November 8, 2026 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MarkPad Does Not Reload Images on Relaod

1 participant