-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[No QA] Fix regression on web due to #4760 #4800
[No QA] Fix regression on web due to #4760 #4800
Conversation
process.env values are always strings
This prevents an error related to bundling: Expensify#4760 (comment)
@@ -41,7 +41,7 @@ const metro = { | |||
* By default <React.Profiler> is disabled in production as it adds small overhead | |||
* When CAPTURE_METRICS is set we're explicitly saying that we want to capture metrics | |||
* To enable the <Profiler> for release builds we add these aliases */ | |||
if (process.env.CAPTURE_METRICS) { | |||
if (process.env.CAPTURE_METRICS === 'true') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
process.env
values are string
so we need to check explicitly for "true"
That's how other compile check are made as well (e.g. process.env.ANALYZE_BUNDLE === 'true'
)
Ideally we want check that can be evaluated at compile time (such as Another approach is with the platform specific code. We can extract Say something if you want to open another PR with the platform specific changes (or modify the current one) |
I don't have much context regarding this, But looking to previous work and PR's. I think we should see if we can configure our bundler to get rid of unused dependencies. If we're bounded by that, I'm fine with platform specific method. As I see, we had that before? Anyways, this PR looks good to me. |
I think if this PR fixes the web builds then we should start here. I agree it would make sense to not bundle this code, but as far as we know we don't have an issue related to the JS bundle size. So maybe it's not worth prioritizing? I found some documentation for how webpack handles this -> https://webpack.js.org/guides/code-splitting/#dynamic-imports My only question is... does the conditional require work correctly on native? If it's only web that is bundling I'd say this matters less. |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
RN does not support Dynamic Imports and doesn't have the Both webpack and metro support the optional and inline requires - we already use them conditionally load a lib
For the current item though the overhead added is negligible - about 10kb (there are also 30kb added by react-native-performance, but they are even harder to get rid of as we also conditionally use it in Onyx...) It's possible to configure webpack to split chunks out of The other approach is "dead code elimination" which can happen at compile time. Since we only set ENV vars at compile time - CAPTURE_METRICS. webpack and metro should be able to statically analyze and derive that certain code will never be evaluated to
As a summary the easiest thing to do right now is to write Platform specific code, but it doesn't seem to be worth it just for the current case. |
Thanks for the summary!
I agree with this. It does feel inevitable that we will want to optimize the JS bundle - but just isn't our focus right now. |
🚀 Deployed to production by @roryabraham in version: 1.0.88-2 🚀
|
This has been deployed to production and is now subject to a 7-day regression period. |
cc @marcaaron
Details
Making production web builds using
npm run build
fails with a webpack loader errorThe problem is discovered as a regression here: #4760 (comment)
Because
webpack
statically analyzes allrequire
calls - even those that might never happen we need to addreact-native-flipper
toincludeModules
Fixed Issues
$ N/A
Tests
Same as the tests here: #4760 (comment)
QA Steps
Tested On
Screenshots
Web
Mobile Web
Desktop
iOS
Android