fix(metro-cache): cache building

This commit is contained in:
amsyarasyiq 2024-05-10 02:40:00 +08:00
parent 926d875de7
commit 072f189a72

View file

@ -34,19 +34,23 @@ function buildInitCache() {
assetsCache: {}
} as const;
// Make sure all assets are cached
for (const id in window.modules) {
require("@metro/filters").requireModule(id);
}
// Make sure all assets are cached (delay by a second
// because force loading all of it crashes for some reason (it shouldn't))
setTimeout(() => {
for (const id in window.modules) {
require("@metro/filters").requireModule(id);
}
}, 1000);
}
export async function initMetroCache() {
const rawCache = await MMKVManager.getItem(PYON_METRO_CACHE_KEY);
if (rawCache == null) return buildInitCache();
if (rawCache == null) return void buildInitCache();
try {
metroCache = JSON.parse(rawCache);
if (metroCache.buildNumber !== ClientInfoManager.Build) {
metroCache = null!;
throw "cache invalidated; version mismatch";
}
} catch {