Skip to content

Respect excludeSource in inline source maps and custom serialisers - #2256

Open
robhogan wants to merge 1 commit into
mainfrom
pr2256
Open

robhogan wants to merge 1 commit into
mainfrom
pr2256

Conversation

@robhogan

@robhogan robhogan commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Currently, a bundle requested with inlineSourceMap=true&excludeSource=true still embeds sourcesContent in its inline source map, because getAppendScripts hard-codes excludeSource: false.

This change is two parts:

  • Allow a custom serialiser to respect this option by threading excludeSource into SerializerOptions.
  • Fix the inline map in the default baseJSBundle serialiser.

Categorising this as a fix because we weren't respecting the caller's request previously. excludeSource defaults to false, so bundles that don't set it are unchanged.

Metro's .map endpoint, and the separate map returned by Server.build(), already respected the option.

Changelog: [Fix] Respect excludeSource in inline source maps, and pass it to serializer.customSerializer

Test plan:
New unit tests for baseJSBundle and Server (bundle requests and build()). The excludeSource=true and custom serializer cases fail without the change.

E2E: ran Metro.runServer on the integration test fixture and requested TestBundle.bundle?platform=ios&dev=true&inlineSourceMap=true, then decoded the inline map:

Query Before After
(none) 8 of 9 sections with sourcesContent, 124,942 bytes Unchanged, 124,942 bytes
&excludeSource=true 8 of 9 sections with sourcesContent, 124,961 bytes 0 of 9, 71,461 bytes

@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 Nov 20, 2026
@robhogan robhogan changed the title Respect excludeSource in inline source maps and custom serializers Respect excludeSource in inline source maps and custom serialisers Nov 20, 2026
Currently, a bundle requested with `inlineSourceMap=true&excludeSource=true` still embeds `sourcesContent` in its inline source map, because `getAppendScripts` hard-codes `excludeSource: false`.

This change is two parts:
 - Allow a custom serialiser to respect this option by threading `excludeSource` into `SerializerOptions`.
 - Fix the inline map in the default `baseJSBundle` serialiser.

Categorising this as a fix because we weren't respecting the caller's request previously. `excludeSource` defaults to `false`, so bundles that don't set it are unchanged.

Metro's `.map` endpoint, and the separate `map` returned by `Server.build()`, already respected the option.

Changelog: [Fix] Respect `excludeSource` in inline source maps, and pass it to `serializer.customSerializer`

Test plan:
New unit tests for `baseJSBundle` and `Server` (bundle requests and `build()`). The `excludeSource=true` and custom serializer cases fail without the change.

E2E: ran `Metro.runServer` on the integration test fixture and requested `TestBundle.bundle?platform=ios&dev=true&inlineSourceMap=true`, then decoded the inline map:

| Query | Before | After |
|---|---|---|
| (none) | 8 of 9 sections with `sourcesContent`, 124,942 bytes | Unchanged, 124,942 bytes |
| `&excludeSource=true` | 8 of 9 sections with `sourcesContent`, 124,961 bytes | 0 of 9, 71,461 bytes |
@github-actions

Copy link
Copy Markdown

Metro review: Looks good

Risk: low · Commit: eadc580 · 5 commands run

The PR adds excludeSource to SerializerOptions, passes it from both Server serialization paths (bundle requests and build()), and has getAppendScripts honor it in the inline source map instead of hard-coding false. The change is small and consistent with how the .map endpoint, baseJSBundleWithLazyModuleDefinition and RAM bundles already handled the option. The new tests fail without the fix and pass with it, and typecheck, lint and the API snapshots are clean. One side effect: getRamBundleInfo passes its options straight through to getAppendScripts, so RAM bundle inline maps now honor excludeSource too. That fits the stated intent.

No findings.

Verified
  • ✅ yarn jest --no-watchman packages/metro/src/DeltaBundler/Serializers packages/metro/src/Server/__tests__/Server-test.js — 10 suites, 178 tests passed
  • ✅ Restore base getAppendScripts.js, Server.js and baseJSBundle.js (keeping the new tests), then yarn jest --no-watchman baseJSBundle-test.js Server-test.js (failed as expected) — 6 failed: all the new excludeSource=true and custom-serializer cases. The files were restored to the head versions afterwards.
  • ✅ yarn typecheck
  • ✅ yarn eslint <changed files>
  • ✅ yarn verify-api-snapshots — The API.md change matches the generated snapshot

Not run: I didn't re-run the E2E numbers from the description (inline map size on the integration fixture). The unit tests cover the same behavior. I skipped benchmarks because the change only forwards an existing option to the source map serializer, and leaving out sourcesContent can only shrink the output. Windows wasn't checked because the change involves no path handling.

Automated review by Claude. Advisory only: it never approves or blocks, and a maintainer makes the call.

@robhogan robhogan added the Auto review: Good The Metro review bot found nothing to change at this head label Nov 20, 2026

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

Auto review: Good The Metro review bot found nothing to change at this head 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.

2 participants