{{ message }}
Repository navigation
feat(muya): add invalidateImageCache - #4396
Merged
Merged
Conversation
The renderer memoises loaded inline images in `loadImageMap` (skipped on the next render once `isSuccess` is true) and resolved URLs in `urlMap`, so an image whose file changed on disk would keep showing the stale bitmap with no way to flush it. Add `InlineRenderer.invalidateImageCache()` which clears both caches and re-renders every content block (via `scrollPage.breadthFirstTraverse`), so `loadImageAsync` runs afresh for inline images. Expose it publicly as `Muya.invalidateImageCache()`, mirroring legacy muyajs `StateRender.invalidateImageCache` so the desktop migration can call `editor.invalidateImageCache()` after a watched image file changes or on the `mt::invalidate-image-cache` IPC. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a public invalidateImageCache() API to @muyajs/core so the desktop shell can force inline images to reload after their underlying files change, by flushing the inline renderer’s image caches and re-rendering all content blocks.
Changes:
- Add
Muya.invalidateImageCache()as a public wrapper delegating to the inline renderer. - Add
InlineRenderer.invalidateImageCache()to clearloadImageMap/urlMapand re-render all content blocks viascrollPage.breadthFirstTraverse(...).update(). - Add a happy-dom Vitest spec validating cache flush + re-render behavior and no-op safety.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Why
The desktop shell calls
editor.invalidateImageCache()to force inline images to reload — e.g. after a watched image file changes on disk, or on themt::invalidate-image-cacheIPC.@muyajs/corememoises loaded images but had no way to flush and re-render them, so an image whose file changed on disk would keep showing the stale bitmap. This is part of the desktop migration off legacypackages/muyajs(which already exposesStateRender.invalidateImageCache).What
InlineRenderer.invalidateImageCache()(src/inlineRenderer/index.ts): clears the renderer'sloadImageMapandurlMapimage caches, then re-renders every content block viascrollPage.breadthFirstTraverse(...).update(). Re-rendering re-runsloadImageAsync, which — with the caches now empty — loads each image source afresh. This follows the existingScrollPage.updateRefLinkAndImagetraversal pattern.Muya.invalidateImageCache()(src/muya.ts): public delegating wrapper, inserted immediately afterhideAllFloatTools().src/__tests__/invalidateImageCache.spec.ts: seeds the cache maps, callsmuya.invalidateImageCache(), and asserts both maps are cleared, the API is present, content blocks are re-patched (viavi.waitFor), and it does not throw on image-free / empty documents.Behavior
invalidateImageCache()is a no-op-safe flush: the image caches are cleared synchronously and every content block is re-rendered so inline images reload from their source. Documents with no images (or empty documents) are handled without error.Verification
All green in
packages/muya:lint— 0 errors (pre-existing complexity warnings only, none in touched files)lint:types— cleancheck-circular— no circular dependencytest— 446 passedtest:spec— 1347 passed (CommonMark + GFM conformance)🤖 Generated with Claude Code