Skip to content

Fix getCodeFrame resolution for watchFolder source files - #2018

Open
robhogan wants to merge 1 commit into
pr2016from
pr2017
Open

robhogan wants to merge 1 commit into
pr2016from
pr2017

Conversation

@robhogan

@robhogan robhogan commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Recreating #1710 / D104259454 (@motiz88) for GH first without a diff attachment

The getCodeFrame helper in the symbolicate handler resolves stack frame file paths against projectRoot only. When source maps use SourcePathsMode.ServerUrl, the file field may be a server-relative URL pathname (e.g. /src/App.js) or a virtual-prefix path (e.g. /[metro-watchFolders]/0/foo.js). These resolve incorrectly against projectRoot.

Here, we check path.isAbsolute(file) first (for SourcePathsMode.Absolute source maps), then try filePathOfUrlDecodedPathname (for virtual-prefix paths), and fall back to the original path.resolve(projectRoot, file).

Changelog: Internal

Test plan:
See D104259454

@robhogan
robhogan added this pull request to stack #2016 October 3, 2026 22:02
@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 3, 2026
@robhogan
robhogan requested review from huntie and motiz88 and a balanced review from Copilot October 3, 2026 22:09
@robhogan
robhogan marked this pull request as ready for review October 3, 2026 22:10
*Recreating #1710 / [D104259454](https://www.internalfb.com/diff/D104259454) (@motiz88) for GH first without a diff attachment*

The `getCodeFrame` helper in the symbolicate handler resolves stack frame file paths against `projectRoot` only. When source maps use `SourcePathsMode.ServerUrl`, the `file` field may be a server-relative URL pathname (e.g. `/src/App.js`) or a virtual-prefix path (e.g. `/[metro-watchFolders]/0/foo.js`). These resolve incorrectly against `projectRoot`.

Here, we check `path.isAbsolute(file)` first (for `SourcePathsMode.Absolute` source maps), then try `filePathOfUrlDecodedPathname` (for virtual-prefix paths), and fall back to the original `path.resolve(projectRoot, file)`.

Changelog: Internal

Test plan:
See [D104259454](https://www.internalfb.com/diff/D104259454)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

馃煛 Changes recommended

Encoded paths remain unresolved, and the regression test bypasses the production sourcePaths=url-server flow.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
What changed in this PR

Updates symbolication code-frame resolution for virtual Metro source paths.

Changes:

  • Resolves virtual-prefixed and relative source paths.
  • Adds symbolication code-frame tests.
File Description
packages/鈥媘etro/鈥媠rc/鈥婼erver.js Adds virtual-path resolution for code frames.
packages/鈥媘etro/鈥媠rc/鈥婼erver/鈥媉_tests__/鈥婼erver-test.js Tests virtual and relative paths.

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

const fileAbsolute = path.resolve(this._config.projectRoot, file ?? '');
const fileAbsolute =
file != null
? (this._routeMap.filePathOfUrlDecodedPathname(file) ??
Comment on lines +1496 to +1498
jest
.spyOn(server, '_explodedSourceMapForBundleOptions')
.mockResolvedValue([

This branch has not been deployed

No deployments
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants