Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support code for experimental dev-mode bundle splitting #32098

Closed
wants to merge 2 commits into from

Conversation

motiz88
Copy link
Contributor

@motiz88 motiz88 commented Aug 26, 2021

Summary:
Changelog: [Internal]

Moves asyncRequireForMetro.js into React Native. This code can be used together with experimentalImportBundleSupport: true in Metro to load split bundles in development from a Metro server. This is still an experimental, undocumented workflow - proper documentation will follow when it's stable.

The minimal Metro config required for this to work is:

// metro.config.js
module.exports = {
  transformer: {
    asyncRequireModulePath: 'react-native/Libraries/DevBundleLoading/asyncRequireForMetro.js',
    experimentalImportBundleSupport: true,
  },
};

Differential Revision: D30580274

Differential Revision: D30577963

fbshipit-source-id: bd408ccbb727018a17564ef0a102df90b84b35ce
Summary:
Changelog: [Internal]

Moves `asyncRequireForMetro.js` into React Native. This code can be used together with `experimentalImportBundleSupport: true` in Metro to load split bundles in development from a Metro server. This is still an experimental, undocumented workflow - proper documentation will follow when it's stable.

The minimal Metro config required for this to work is:

```
// metro.config.js
module.exports = {
  transformer: {
    asyncRequireModulePath: 'react-native/Libraries/DevBundleLoading/asyncRequireForMetro.js',
    experimentalImportBundleSupport: true,
  },
};
```

Differential Revision: D30580274

fbshipit-source-id: 740af4947f753c8bed36fab67accd638ac0c3904
@motiz88 motiz88 requested a review from hramos as a code owner August 26, 2021 19:14
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported labels Aug 26, 2021
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D30580274

@pull-bot
Copy link

Warnings
⚠️ 🔒 package.json - Changes were made to package.json. This will require a manual import by a Facebook employee.
Messages
📖

📋 Missing Changelog - Can you add a Changelog? To do so, add a "## Changelog" section to your PR description. A changelog entry has the following format: [CATEGORY] [TYPE] - Message.

CATEGORY may be:
  • General
  • iOS
  • Android
  • JavaScript
  • Internal (for changes that do not need to be called out in the release notes)

TYPE may be:

  • Added, for new features.
  • Changed, for changes in existing functionality.
  • Deprecated, for soon-to-be removed features.
  • Removed, for now removed features.
  • Fixed, for any bug fixes.
  • Security, in case of vulnerabilities.

MESSAGE may answer "what and why" on a feature level. Use this to briefly tell React Native users about notable changes.

📖 📋 Missing Test Plan - Can you add a Test Plan? To do so, add a "## Test Plan" section to your PR description. A Test Plan lets us know how these changes were tested.
📖 📋 Missing Summary - Can you add a Summary? To do so, add a "## Summary" section to your PR description. This is a good place to explain the motivation for making this change.

Generated by 🚫 dangerJS against 386941a

@motiz88
Copy link
Contributor Author

motiz88 commented Aug 26, 2021

cc @cpojer, @EvanBacon

@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 362511d

@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 9,245,099 +0
android hermes armeabi-v7a 8,764,118 +0
android hermes x86 9,687,386 +0
android hermes x86_64 9,655,570 +0
android jsc arm64-v8a 10,881,708 +0
android jsc armeabi-v7a 9,791,996 +0
android jsc x86 10,919,417 +0
android jsc x86_64 11,529,096 +0

Base commit: 362511d

}
})
.finally(() => {
if (!--pendingRequests) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Where does this pendingRequests++?

return importBundlePromises[stringModuleID];
}

return dynamicRequire.importAll(moduleID);
Copy link
Contributor

@EvanBacon EvanBacon Aug 26, 2021

Choose a reason for hiding this comment

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

When would this be used?


const requestUrl = buildUrlForBundle(bundlePath, {
modulesOnly: 'true',
runModule: 'false',
Copy link
Contributor

@EvanBacon EvanBacon Aug 26, 2021

Choose a reason for hiding this comment

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

Missing shallow: true?

Edit: This actually doesn't work with shallow true if you have an async module inside another async module, but the bundles appear to be larger.

);
}

HMRClient.registerBundle(requestUrl);
Copy link
Contributor

Choose a reason for hiding this comment

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

fyi I found a bug with this code that you also have at Facebook. When Metro's websocket disconnects and reconnects, it will not replay the registerBundle calls and Metro won't update the right files any longer. Most likely it will manifest in Fast Refresh breaking until you reload. The fix is to append registerBundle calls to a Set and replay them when reconnecting.

@bfischer1121
Copy link

Any idea of when / if this will be merged?

Copy link

github-actions bot commented Mar 8, 2024

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Mar 8, 2024
@motiz88
Copy link
Contributor Author

motiz88 commented Mar 8, 2024

Lazy bundling shipped in React Native 0.73.

@motiz88 motiz88 closed this Mar 8, 2024
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. fb-exported p: Facebook Partner: Facebook Partner RN Team Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants