facebook / metro

🚇 The JavaScript bundler for React Native
https://metrobundler.dev
MIT License
5.25k stars 627 forks source link

Always exempt Babel runtime helpers from inline (lazy) requires #1127

Closed gaearon closed 1 year ago

gaearon commented 1 year ago

Summary

There is no benefit to treating Babel helpers with lazy requires. They are always going to be needed, and their initialization is extremely cheap, so it just bloats up the code and adds extra runtime indirection on every access to them.

I considered a few alternatives:

I'm not particularly enthusiastic about doing the bigger changes myself. I think hardcoding it here is fine because there's basically no legit reason for wanting these to be lazy. In fact they might even not be lazy anyway depending on where in your compilation pipeline the runtime plugin is injected. But this is nice because it fixes it for all RN users with inline requires.

Test plan

Ran my app with the change. The app works. The diff looks like I'd expect, for example:

Screenshot 2023-10-31 at 00 40 00
facebook-github-bot commented 1 year ago

@robhogan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot commented 1 year ago

@robhogan merged this pull request in facebook/metro@fcd8867d5b2ccf4133e1c12f224695e315d09b6f.

zhusjfaker commented 1 year ago

mark