diff --git a/lib/assets/src/caches.ts b/lib/assets/src/caches.ts index 8a4394a..7a0022e 100644 --- a/lib/assets/src/caches.ts +++ b/lib/assets/src/caches.ts @@ -19,12 +19,15 @@ const CacheStorage = getStorage(`revenge/assets.${Key}`, { // TODO(lib/assets/caches): This loads way too late and requires native interop to load earlier // biome-ignore lint/complexity/useArrowFunction: Arrow functions are not supported -export const promise = CacheStorage.get().then(async function (cache_) { +export const cached = CacheStorage.get().then(async function (cache_) { + const cached = cache_ !== cache // If we are not using the default value, merge it into the in-memory cache, then point the storage cache to the in-memory cache. - if (cache_ !== cache) { + if (cached) { Object.assign(cache, cache_) CacheStorage.cache = cache } + + return cached }) export interface Cache { diff --git a/lib/assets/src/preinit.ts b/lib/assets/src/preinit.ts index 01990aa..17e37be 100644 --- a/lib/assets/src/preinit.ts +++ b/lib/assets/src/preinit.ts @@ -3,7 +3,7 @@ import { byName, byProps } from '@revenge-mod/modules/finders/filters' import { waitForModules } from '@revenge-mod/modules/finders/wait' import { getModuleDependencies } from '@revenge-mod/modules/metro/utils' import { _overrides } from './_internal' -import { cache, cacheAsset, promise } from './caches' +import { cacheAsset, cached } from './caches' import type { ReactNative } from '@revenge-mod/react/types' import type { Asset, PackagerAsset } from './types' @@ -26,15 +26,8 @@ const unsubAR = waitForModules( unsubAR() // TODO(lib/assets/caches): Ideally we should not wait for the cache promise here, see the promise impl for more info. - promise.then(() => { - // Make sure we don't try to recache assets if it is already cached. - let uncached = true - for (const _ in cache) { - uncached = false - break - } - - if (uncached) { + cached.then(cached => { + if (!cached) { // More fragile way, but also more performant: // There is exactly one asset before the reexported asset registry :/ const firstAssetModuleId = id - 1