fix: clear Metro cache after generating native assets#52
Merged
oblador merged 1 commit intooblador:masterfrom Mar 24, 2026
Merged
Conversation
The asset filenames include a content hash (e.g. icon_svg_a1b2c3) that must match between the native assets and Metro's asset registry. The generate step spins up its own Metro instance to discover assets, but the dev server maintains a separate persistent cache. When SVG content changes (e.g. after a git rebase), the generate step produces native assets with new hashes, but a stale dev server cache can still serve the old hash at runtime, causing "Could not find image" warnings. Clearing the Metro cache directory after asset generation forces the dev server to recompute all asset hashes on next start, ensuring they match the freshly generated native resources.
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.
Problem
When SVG file content changes (e.g. after a
git rebase), runningexpo prebuildgenerates native assets with new content hashes (e.g.icon_svg_220cf9). However, the Metro dev server maintains its own persistent cache from before the change, so at runtime it resolves the old hash (e.g.icon_svg_884cf1). This causes warnings like:The root cause is that
generateAssetsspins up its own Metro instance viacreateMetroServerAndBundleRequestAsyncto discover assets, but the dev server's$TMPDIR/metro-cacheis a separate persistent cache that doesn't get invalidated.Fix
Clear
$TMPDIR/metro-cacheat the end ofgenerateAssets(), after native assets have been written. This forces the nextexpo startto recompute all asset hashes from scratch, ensuring they match the freshly generated native resources.The trade-off is a slightly slower first Metro startup after prebuild (cold cache), but it eliminates the hash mismatch class of bugs entirely.
Test plan
884cf1before rebase and220cf9afterexpo prebuildclears the Metro cache and subsequentexpo startresolves the correct hash