repack
repack copied to clipboard
Bug in `invalidateScripts` leading to app crash
Environment
React Native android (but I believe the bug is not specific to RN android)
Description
Calling invalidateScripts for a chunk is causing a crash when next attempting to use that chunk. On debugging it, the chunk file is getting deleted, but the entry in sqlite db is not getting cleared. It looks like there is a bug in invalidateScripts method. resolveScripts method appends caller to the scriptId to get the cacheKey (const cacheKey = `${scriptId}_${caller ?? 'unknown'}`;), while invalidateScripts directly uses scriptId as the cacheKey.
Reproducible Demo
- Have a remote code split chunk.
- Call
invalidateScriptswith that chunk's scriptId - Try using that chunk in UI, it leads to crash.
com.facebook.react.common.JavascriptException: ChunkLoadError: Loading chunk <scriptId> failed
@jbroma I am having few queries before getting into the fix:
callerDocumentation saysName of the calling script - it can be for example: name of the bundle, chunk or container.However, the default value ismainwhich is not the default bundle/chunk/container name.- Should default caller value be made
maininstead ofunknown?- I am unable to grasp what value the caller is adding for cacheKey in the first place, if the underlying downloaded file is the same irrespective of the caller value (I am assuming so as per the downloaded chunk file name). Can you please help elaborate, or point me to any other documentation behind the design decision?
- & 2. The name
maincomes from webpack, when you declare entry with a string or an array, it defaults the entry chunk name tomain. See webpack docs. So it's a decent default I think, but it's good to double check this if this is really the case. - I've looked at it and I'm pretty sure the
calleris there to create some sort of uniqueID, sincescriptIDis a string and can easily be duplicated in an app. Adding a caller creates a scope for it so it's harder to get a collision.
I suppose we could drop the caller altogether for the uniqueID, and rely on users specyfing output.uniqueName to avoid collisions.
EDIT: From my understanding, the scriptID is unique within a project, but there might be collision for example when using MF. If the configuration includes the output.uniqueName then we should be able to avoid any collision because the scriptID will be prefixed with uniqueName.
This issue has been marked as stale because it has been inactive for 30 days. Please update this issue or it will be automatically closed in 14 days.
This issue has been marked as stale because it has been inactive for 30 days. Please update this issue or it will be automatically closed in 14 days.
This issue has been automatically closed because it has been inactive for more than 14 days. Please reopen if you want to add more context.