From 61cec5d5eae05ec5dd32f0ff0644f5d94ca9b160 Mon Sep 17 00:00:00 2001 From: Dave Matthews Date: Tue, 24 Mar 2026 17:30:46 +0100 Subject: [PATCH] fix: clear Metro cache after generating native assets 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. --- src/cli/generateAssets.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cli/generateAssets.js b/src/cli/generateAssets.js index 977692f..39f2c1c 100644 --- a/src/cli/generateAssets.js +++ b/src/cli/generateAssets.js @@ -1,4 +1,5 @@ const fs = require('fs-extra'); +const os = require('os'); const path = require('path'); const generateIosAsset = require('./generateIosAsset'); const generateAndroidAsset = require('./generateAndroidAsset'); @@ -83,6 +84,14 @@ async function generateAssets({ } }) ); + + // Clear Metro's cache after generating native assets so the dev server + // recomputes asset hashes to match the regenerated native resources. + // Without this, a stale Metro cache can serve an old content hash after + // SVG files change (e.g. after a rebase), causing "Could not find image" + // warnings at runtime. + const metroCacheDir = path.join(os.tmpdir(), 'metro-cache'); + await fs.remove(metroCacheDir); } module.exports = generateAssets;