Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
experimentalImportBundleSupport: Move bundle path hints into serialis…
…ed dependency map Summary: Changelog: [Experimental] ## Problem `experimentalImportBundleSupport` (D15943150 (72329d0)) originally relied on including a global map from module IDs to paths (`importBundleNames`) in each bundle served by the HTTP server. This allowed a custom (and Meta-internal) implementation of `asyncRequire` to construct and fetch an HTTP URL corresponding to any given async-loadable module. The global map approach breaks Fast Refresh when new async imports are added to a module, because it turns out we never update the global map during HMR. New `import()` call sites can be added and are transformed to `asyncRequire`, but the map entries they need aren't there, so they just throw at runtime. ## Solution Naively, fixing this would require teaching the entire HMR pipeline (Graph, DeltaCalculator, HmrServer, HmrClient) to incrementally update the `importBundleNames` map at runtime on the client. Here we take a different approach: breaking up the `importBundleNames` map into individual maps, one for each module that contains async dependencies. 1. Every call to `asyncRequire` now has an extra argument `paths` which holds a *local* map from IDs to paths. Conceptually, this is the same information that `importBundleNames` has for the entire graph, except now it's split by "parent" module. 2. `paths` is generated by the serializer for async dependencies (only) and written to the bundle in a backwards-compatible format as part of the dependency map - which is now either an array or an *object with a numeric indexer*, depending on whether it has a `paths` property. The HMR machinery already knows how to update dependency maps, so in particular it keeps `paths` up-to-date as part of that. No special plumbing needed! 🎉 ## Next steps * `graph.importBundleNames` will be going away in a separate diff; anyone using the (still experimental) `experimentalImportBundleSupport` API will need to update their `asyncRequire` implementation at that point to use this new mechanism instead (cc EvanBacon). * Custom bundle splitting implementations may want something other than the *path* of a module, specifically, to be passed to `asyncRequire`. The contract is between the serializer and the `asyncRequire` implementation. We might want to use the term "fetch key" instead of "path", allow it to be any serializable value rather than just a string, and add a `createModuleFetchKey` API (analogous to `createModuleIdFactory`) to control this in config. Differential Revision: D40412241 fbshipit-source-id: 622c63c770d6aa95fca90decebe2f38feb2c31b6
- Loading branch information
1 parent
4942d56
commit 05d7264
Showing
18 changed files
with
262 additions
and
192 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.