Skip to content

Commit 61cec5d

Browse files
author
Dave Matthews
committed
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.
1 parent 6250570 commit 61cec5d

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/cli/generateAssets.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const fs = require('fs-extra');
2+
const os = require('os');
23
const path = require('path');
34
const generateIosAsset = require('./generateIosAsset');
45
const generateAndroidAsset = require('./generateAndroidAsset');
@@ -83,6 +84,14 @@ async function generateAssets({
8384
}
8485
})
8586
);
87+
88+
// Clear Metro's cache after generating native assets so the dev server
89+
// recomputes asset hashes to match the regenerated native resources.
90+
// Without this, a stale Metro cache can serve an old content hash after
91+
// SVG files change (e.g. after a rebase), causing "Could not find image"
92+
// warnings at runtime.
93+
const metroCacheDir = path.join(os.tmpdir(), 'metro-cache');
94+
await fs.remove(metroCacheDir);
8695
}
8796

8897
module.exports = generateAssets;

0 commit comments

Comments
 (0)