Skip to content

Graph: Carry require.context inputs as a VirtualSource - #2041

Merged
robhogan merged 1 commit into
mainfrom
pr2041
Oct 14, 2026
Merged

robhogan merged 1 commit into
mainfrom
pr2041

Conversation

@robhogan

@robhogan robhogan commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Graph threads a RequireContext per module from buildSubgraph through commit, snapshots and release, so that the transformer can render a context module's template.

It's the only place Metro carries a transform's input on a dependency edge rather than reading it from disk, which is the kind of shape we need for virtual modules.

This generalises that slot to VirtualSource, a union whose only member for now is require.context's parameters. ModuleData.resolvedContexts becomes virtualSources, and markModifiedContextModules only considers context entries.

This takes some of the noise out #2036 for ease of review, and should be read in the context of that design. No behaviour or API change.

Changelog: Internal

`Graph` threads a `RequireContext` per module from `buildSubgraph` through commit, snapshots and release, so that the transformer can render a context module's template. It's the one place Metro carries a transform's input on a dependency edge rather than reading it from disk.

This generalises that slot to `VirtualSource`, a tagged union whose only arm for now is a `require.context`'s parameters, so that a virtual module's source can travel the same way (#2036) rather than through a second mechanism beside it. `ModuleData.resolvedContexts` becomes `virtualSources`, and `markModifiedContextModules` only considers context entries.

Changelog: Internal
@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 Oct 8, 2026
@robhogan
robhogan added this pull request to stack #2042 October 8, 2026 12:56
@robhogan robhogan changed the title Graph: Carry require.context inputs as a VirtualSource Graph: Refactor require.context inputs as a VirtualSource (rename RequireContext) Oct 8, 2026
@robhogan
robhogan marked this pull request as ready for review October 8, 2026 13:29
@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 Oct 8, 2026
@robhogan robhogan changed the title Graph: Refactor require.context inputs as a VirtualSource (rename RequireContext) Graph: Carry require.context inputs as a VirtualSource Oct 11, 2026
@robhogan
robhogan removed this pull request from stack #2042 October 11, 2026 14:41
@robhogan
robhogan added this pull request to stack #2057 October 11, 2026 14:41
@robhogan
robhogan requested a balanced review from Copilot October 12, 2026 12:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

馃煝 Approval recommended

The refactor consistently preserves existing context-module behavior and updates relevant tests.

0 open findings

What changed in this PR

Generalizes require.context transform inputs into the extensible VirtualSource abstraction without changing behavior.

Changes:

  • Replaces resolvedContexts with tagged virtualSources.
  • Threads virtual sources through graph traversal, snapshots, and transforms.
  • Updates context-module tests for the new representation.
File Description
packages/鈥媘etro/鈥媠rc/鈥媗ib/鈥媡ransformHelpers.js Unwraps context virtual sources for transformation.
packages/鈥媘etro/鈥媠rc/鈥婦eltaBundler/鈥媡ypes.js Defines VirtualSource and updates related types.
packages/鈥媘etro/鈥媠rc/鈥婦eltaBundler/鈥婫raph.js Tracks virtual sources throughout graph lifecycle.
packages/鈥媘etro/鈥媠rc/鈥婦eltaBundler/鈥媌uildSubgraph.js Carries tagged virtual sources during traversal.
packages/鈥媘etro/鈥媠rc/鈥婦eltaBundler/鈥媉_tests__/鈥婫raph-test.js Updates graph expectations and transform signatures.
packages/鈥媘etro/鈥媠rc/鈥婦eltaBundler/鈥媉_tests__/鈥媌uildSubgraph-test.js Verifies tagged context-source propagation.

馃 Review effort: Balanced


馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@robhogan
robhogan merged commit ded095d into main Oct 14, 2026
18 checks passed
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.

3 participants