Repository navigation
Fix font_google(local = TRUE) failing on Windows and after cache pruning - #164
Merged
Merged
Conversation
When the Google Fonts CSS was a cache hit but a font file it references had been pruned from the cache, font_dep_google_local() would 'bust the CSS cache and start over' by calling itself recursively. However, that call happened inside a Map() callback, so its return value -- the correctly rebuilt htmlDependency -- was discarded. The outer call then continued and returned a dependency whose directory was missing (at least) the font file that triggered the cache miss. Record the need to restart in a flag and do the recursive restart at the top level of font_dep_google_local() instead.
Google Fonts may return font URLs containing a query string, and basename() of such URLs includes characters (e.g., '?') that are invalid in Windows file names, causing the download to fail. Name downloaded font files after a hash of their URL, plus an extension derived from the font's format() hint in the CSS. Names in already-rewritten (cached) CSS are kept as-is so cache lookups round-trip.
When only some font files are pruned from the cache, the recovery path re-downloads the CSS (so all URLs are remote again), but fonts still present in the cache hit the early return before their URLs were rewritten to the local copies -- the returned and re-cached CSS kept pointing at Google for those fonts, breaking offline rendering. Addresses Copilot review feedback on #164.
…font-windows # Conflicts: # NEWS.md
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.
Closes #157.
Why
font_google(local = TRUE)has two bugs that make locally-downloaded Google fonts unreliable:?that are invalid in Windows file names.htmlDependencywas missing exactly the pruned file(s).What changed
rlang::hash()), with an extension derived from the font'sformat()hint. When the hint is absent, a recognized extension from the URL path is used instead, ignoring query strings and fragments. Files continue to be downloaded locally without a format hint, and filenames remain valid on every platform.font_dep_google_local()call until after font processing and returns its result, busting the stale CSS cache entry exactly once (no infinite recursion; still-cached fonts are reused, only pruned ones re-download).Existing caches need no migration: old Unix caches keep working and age out naturally; Windows caches can't contain the broken entries (the download itself errored before this fix).
Tests
url()in the served CSS exists on disk (verified to fail against the old code).Known limitations
format()values, or missing format hints with no recognized URL extension, produce extensionless local files, which may get a generic MIME type. The current Google Fonts responses tested use woff2.