Address issue #318: Style reload doesn't update Preview pane#328
Merged
Address issue #318: Style reload doesn't update Preview pane#328
Conversation
Contributor
Code Coverage ReportCurrent Coverage: 56.67% Coverage Details (Summary) |
Add invalidateStyleCaches method that clears WebView's URL cache and resets cached style/theme names before explicit reload. This forces the full HTML reload path (bypassing DOM replacement) so edited CSS files are re-read from disk. The bug had two layers: (1) DOM replacement optimization only updated <body>, leaving <head> CSS <link> tags untouched because the style *name* hadn't changed, and (2) WebView cached CSS by URL, serving stale content even on full reload. Both reloadPreview: (context menu) and didRequestPreviewReload: (Settings gear menu) now call invalidateStyleCaches before rendering. Normal editing is unaffected since the method is only called on explicit user-initiated reload actions. Related to #318
62c0438 to
24d170d
Compare
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.
Summary
invalidateStyleCachesmethod toMPDocumentthat clears WebView's URL cache ([[NSURLCache sharedURLCache] removeAllCachedResponses]) and resets cached style/theme names to nilinvalidateStyleCachesfrom bothreloadPreview:(Preview context menu) anddidRequestPreviewReload:(Settings gear menu Reload button) before triggering re-renderMPDocumentStyleUpdateTests.min the Xcode project (existed on disk but was missing from project file)Related Issue
Related to #318
Root Cause
The bug had two layers:
renderer:didProduceHTMLOutput:only replaced<body>content when the style name hadn't changed — but the user edited the file content, not the style selection. Setting cached names to nil forcesstylesChanged = YES, bypassing DOM replacement.<link>tags with the samefile://URL. ClearingNSURLCacheforces WebView to re-read from disk.Normal editing is unaffected because
invalidateStyleCachesis only called from explicit reload handlers, never from theeditorTextDidChange:editing flow.Manual Testing Plan
body { background-color: red !important; })