Skip to content

Fix RAM bundle passing the deps function (not its result) to getTransformOptions - #1757

Open
durvesh1992 wants to merge 5 commits into
react:mainfrom
durvesh1992:fix/rambundle-getdependencies-callback
Open

Fix RAM bundle passing the deps function (not its result) to getTransformOptions#1757
durvesh1992 wants to merge 5 commits into
react:mainfrom
durvesh1992:fix/rambundle-getdependencies-callback

Conversation

@durvesh1992

@durvesh1992 durvesh1992 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

getRamBundleInfo hands custom getTransformOptions a callback to look up a module's transitive dependencies. But it builds that callback as:

async (x: string) => Array.from(getDependencies),

getDependencies is the function (filePath) => getTransitiveDependencies(filePath, graph). This calls Array.from on the function itself and ignores x — it never invokes getDependencies. Since the closure has arity 1, Array.from treats it as array-like via .length and returns [undefined]. So any getTransformOptions that uses this callback to compute preloadedModules/ramGroups receives [undefined] for every file it asks about.

Fix

-    async (x: string) => Array.from(getDependencies),
+    async (x: string) => Array.from(getDependencies(x)),

Changelog: [Fix] RAM bundle builds now pass real transitive dependencies to a custom getTransformOptions

Test plan

jest packages/metro/src/DeltaBundler/Serializers/__tests__/getRamBundleInfo-test.js

Added a regression test that supplies a getTransformOptions which calls the callback for /root/foo.js and asserts it returns foo's transitive deps (bar, baz, qux). Fails before ([undefined]), passes after. Existing tests + snapshots unchanged (4 passed, 2 snapshots).

…formOptions

getRamBundleInfo gives custom getTransformOptions a callback to look up a
module's transitive dependencies, but it called `Array.from(getDependencies)`
on the function itself instead of `Array.from(getDependencies(x))`. Since
the closure has arity 1, Array.from treated it as array-like and returned
[undefined], so any getTransformOptions relying on this callback received
garbage regardless of the file queried.

Invoke getDependencies(x). Existing tests never exercised the callback,
which masked this.

Adds a regression test that calls the callback and asserts the real
transitive deps (fails before / passes after).
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 30, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jun 30, 2026
`resolvedDeps` was declared without a type or initialiser, so spreading it fails `flow check` with "possibly uninitialized variable is incompatible with $Iterable".

Annotate it and assert it was assigned before spreading, which also gives a clearer failure if `getTransformOptions` is never called with a dependency lookup.

Changelog: [Internal]
…back

The suppression dates to Flow v0.99 in 2019 and no longer suppresses anything: `flow check` reports no error on this line with it removed, either with the fix in this stack or with the original `Array.from(getDependencies)`.

Worth noting Flow did not catch this bug in either form, for the same reason it was silent at runtime - `Array.from` accepts array-likes, and a function satisfies that via `.length`.

Changelog: [Internal]
The guard added in the previous commit exceeded the print width, failing `prettier --check` and so `yarn lint`.

Changelog: [Internal]

@robhogan robhogan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants