Add unstable_lazilyDefineModules serializer (switch-bundle output) - #1861
Closed
robhogan wants to merge 1 commit into
Closed
Add unstable_lazilyDefineModules serializer (switch-bundle output)#1861robhogan wants to merge 1 commit into
robhogan wants to merge 1 commit into
Conversation
Summary:
Ports the metro-buck "plain bundle with switch" output format to OSS Metro, behind a new opt-in `serializer.unstable_lazilyDefineModules`.
`baseJSBundleWithLazyModuleDefinition` emits the graph's modules inside a single segment definer:
```
__registerSegment(0, function (moduleId) { switch (...) })
```
...so each module's `__d(...)` runs lazily on first require, rather than eagerly at startup. Polyfills/runtime (pre-modules) and run-module calls stay eager. This mirrors `plain-bundle-with-switch.js` in the metro-buck worker, built on the same OSS `wrapModule` primitive, but parameterised on OSS `Module`/graph types.
Because the switch wraps all modules into one function, the flat index-map path (`fromRawMappingsIndexed`, which assumes the plain top-level `__d` layout) would misalign, so code and source map are assembled together via `metro-source-map`'s `BundleBuilder`, which offsets each module's map section by its actual position in the output.
The structured graph is untouched, so deltas and HMR (addressed per-module via `hmrJSBundle`) are unaffected: an HMR update remains a top-level `__d(...)` that shadows the switch branch, and the runtime materialises a not-yet-required module on demand via its segment definer.
This diff only adds the serializer + config. Wiring into Server (dev + prod) follows in the next diff.
Changelog:
```
- **[Experimental]**: Add serializer.unstable_lazyDefineModules for deferred __d calls
```
Reviewed By: huntie
Differential Revision: D113676086
Contributor
|
@robhogan has exported this pull request. If you are a Meta employee, you can view the originating Diff in D113676086. |
Contributor
|
This pull request has been merged in 8d92267. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Ports the metro-buck "plain bundle with switch" output format to OSS Metro, behind a new opt-in
serializer.unstable_lazilyDefineModules.baseJSBundleWithLazyModuleDefinitionemits the graph's modules inside a single segment definer:...so each module's
__d(...)runs lazily on first require, rather than eagerly at startup. Polyfills/runtime (pre-modules) and run-module calls stay eager. This mirrorsplain-bundle-with-switch.jsin the metro-buck worker, built on the same OSSwrapModuleprimitive, but parameterised on OSSModule/graph types.Because the switch wraps all modules into one function, the flat index-map path (
fromRawMappingsIndexed, which assumes the plain top-level__dlayout) would misalign, so code and source map are assembled together viametro-source-map'sBundleBuilder, which offsets each module's map section by its actual position in the output.The structured graph is untouched, so deltas and HMR (addressed per-module via
hmrJSBundle) are unaffected: an HMR update remains a top-level__d(...)that shadows the switch branch, and the runtime materialises a not-yet-required module on demand via its segment definer.This diff only adds the serializer + config. Wiring into Server (dev + prod) follows in the next diff.
Changelog:
Reviewed By: huntie
Differential Revision: D113676086