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

Remove fbjs dependency #13069

Merged
merged 9 commits into from
Jun 19, 2018
Merged

Remove fbjs dependency #13069

merged 9 commits into from
Jun 19, 2018

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Jun 18, 2018

This removes our runtime dependency on fbjs for a few reasons:

  • We didn't get much value from it, the changes are pretty rare
  • It obscures what we're bundling and sometimes is more generic than we need
  • It drags some runtime dependencies that we don't use

I had to fork www's invariant and warning. Technically they were already implicitly forked (because www's CommonJS resolution gave us a different module) so this is just making it implicit. Warning needs to be forked because of blacklists, and invariant needs to be forked because of differences in production argument formatting logic (which goes through ex internally).

Note: to fully get rid of it we'd also need to remove it in prop-types (facebook/prop-types#194).

@pull-bot
Copy link

pull-bot commented Jun 18, 2018

React: size: 🔺+0.1%, gzip: 0.0%

ReactDOM: size: 0.0%, gzip: -0.1%

Details of bundled changes.

Comparing: b1b3acb...5ebb27b

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react.development.js +4.5% +5.2% 57.64 KB 60.25 KB 15.93 KB 16.77 KB UMD_DEV
react.production.min.js 🔺+0.1% 0.0% 6.85 KB 6.86 KB 2.91 KB 2.91 KB UMD_PROD
react.development.js +5.2% +2.9% 48.46 KB 51 KB 13.59 KB 13.99 KB NODE_DEV
react.production.min.js 🔺+5.3% 🔺+4.2% 5.57 KB 5.86 KB 2.41 KB 2.52 KB NODE_PROD
React-dev.js -0.0% -0.0% 48.65 KB 48.63 KB 13.28 KB 13.28 KB FB_WWW_DEV
React-prod.js 🔺+0.1% -0.1% 13.37 KB 13.38 KB 3.73 KB 3.73 KB FB_WWW_PROD

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.4% +0.6% 624.3 KB 626.74 KB 145.77 KB 146.62 KB UMD_DEV
react-dom.production.min.js 0.0% -0.1% 95.17 KB 95.18 KB 30.78 KB 30.74 KB UMD_PROD
react-dom.development.js +0.4% +0.5% 616.71 KB 619.43 KB 143.68 KB 144.46 KB NODE_DEV
react-dom.production.min.js 🔺+0.3% 🔺+0.6% 94.88 KB 95.17 KB 30.12 KB 30.29 KB NODE_PROD
react-dom-test-utils.development.js -3.4% -2.6% 44.49 KB 42.97 KB 12.25 KB 11.94 KB UMD_DEV
react-dom-test-utils.production.min.js 🔺+0.1% -0.1% 10.1 KB 10.11 KB 3.76 KB 3.76 KB UMD_PROD
react-dom-test-utils.development.js +6.3% +7.4% 40.16 KB 42.68 KB 11.06 KB 11.87 KB NODE_DEV
react-dom-test-utils.production.min.js 🔺+3.1% 🔺+3.2% 9.61 KB 9.91 KB 3.6 KB 3.71 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js -2.5% -1.9% 61.5 KB 59.99 KB 16.19 KB 15.88 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 🔺+0.1% -0.1% 11.05 KB 11.05 KB 3.83 KB 3.82 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js +4.4% +5.6% 57.13 KB 59.66 KB 14.92 KB 15.75 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 🔺+2.8% 🔺+3.0% 10.58 KB 10.87 KB 3.64 KB 3.75 KB NODE_PROD
react-dom-server.browser.development.js +2.6% +0.3% 100.04 KB 102.64 KB 26.46 KB 26.53 KB UMD_DEV
react-dom-server.browser.production.min.js 0.0% 0.0% 14.77 KB 14.78 KB 5.68 KB 5.68 KB UMD_PROD
react-dom-server.browser.development.js +2.8% +1.5% 92.72 KB 95.32 KB 24.89 KB 25.28 KB NODE_DEV
react-dom-server.browser.production.min.js 🔺+2.0% 🔺+1.9% 14.38 KB 14.68 KB 5.5 KB 5.61 KB NODE_PROD
react-dom-server.node.development.js +2.8% +1.5% 94.64 KB 97.24 KB 25.43 KB 25.81 KB NODE_DEV
react-dom-server.node.production.min.js 🔺+1.9% 🔺+1.8% 15.19 KB 15.48 KB 5.81 KB 5.91 KB NODE_PROD
ReactDOM-dev.js -0.0% -0.0% 626.77 KB 626.68 KB 143.11 KB 143.09 KB FB_WWW_DEV
ReactDOM-prod.js 0.0% -0.0% 271.75 KB 271.76 KB 51.22 KB 51.22 KB FB_WWW_PROD
ReactTestUtils-dev.js -0.0% -0.1% 41.56 KB 41.54 KB 11.25 KB 11.25 KB FB_WWW_DEV
ReactDOMUnstableNativeDependencies-dev.js -0.0% -0.1% 57.34 KB 57.33 KB 14.7 KB 14.69 KB FB_WWW_DEV
ReactDOMUnstableNativeDependencies-prod.js 0.0% -0.1% 26.2 KB 26.21 KB 5.33 KB 5.32 KB FB_WWW_PROD
ReactDOMServer-dev.js -0.0% -0.0% 96.45 KB 96.43 KB 24.83 KB 24.82 KB FB_WWW_DEV
ReactDOMServer-prod.js 0.0% -0.1% 31.9 KB 31.91 KB 7.77 KB 7.77 KB FB_WWW_PROD
react-dom.profiling.min.js +0.3% +0.6% 95.78 KB 96.07 KB 30.42 KB 30.59 KB NODE_PROFILING

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js +0.6% +0.9% 408.51 KB 411.02 KB 91.34 KB 92.16 KB UMD_DEV
react-art.production.min.js 0.0% -0.2% 82.38 KB 82.4 KB 25.41 KB 25.36 KB UMD_PROD
react-art.development.js +0.8% +1.1% 336.98 KB 339.55 KB 73.27 KB 74.1 KB NODE_DEV
react-art.production.min.js 🔺+0.6% 🔺+0.7% 47.08 KB 47.38 KB 14.65 KB 14.75 KB NODE_PROD
ReactART-dev.js -0.0% -0.0% 329.7 KB 329.62 KB 69.2 KB 69.19 KB FB_WWW_DEV
ReactART-prod.js 0.0% -0.0% 142.79 KB 142.8 KB 24.55 KB 24.55 KB FB_WWW_PROD

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer.development.js +0.7% +0.1% 342.77 KB 345.26 KB 74.27 KB 74.38 KB UMD_DEV
react-test-renderer.production.min.js 0.0% -0.3% 47.28 KB 47.29 KB 14.55 KB 14.51 KB UMD_PROD
react-test-renderer.development.js +0.8% +1.2% 335.37 KB 337.94 KB 72.22 KB 73.05 KB NODE_DEV
react-test-renderer.production.min.js 🔺+0.6% 🔺+0.7% 46.7 KB 46.99 KB 14.21 KB 14.32 KB NODE_PROD
react-test-renderer-shallow.development.js +5.0% +0.6% 23.89 KB 25.08 KB 6.48 KB 6.52 KB UMD_DEV
react-test-renderer-shallow.production.min.js 🔺+0.1% 🔺+0.2% 7.15 KB 7.16 KB 2.33 KB 2.34 KB UMD_PROD
react-test-renderer-shallow.development.js +7.2% +10.8% 15.69 KB 16.83 KB 4.16 KB 4.61 KB NODE_DEV
react-test-renderer-shallow.production.min.js 🔺+3.9% 🔺+4.4% 7.48 KB 7.77 KB 2.47 KB 2.58 KB NODE_PROD
ReactTestRenderer-dev.js -0.0% -0.0% 341.21 KB 341.13 KB 71.84 KB 71.83 KB FB_WWW_DEV
ReactShallowRenderer-dev.js -0.0% -0.1% 16.47 KB 16.46 KB 4.3 KB 4.29 KB FB_WWW_DEV

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js +0.8% +1.2% 327.5 KB 330.08 KB 69.75 KB 70.58 KB NODE_DEV
react-reconciler.production.min.js 🔺+0.6% 🔺+0.6% 46.8 KB 47.09 KB 14 KB 14.09 KB NODE_PROD
react-reconciler-persistent.development.js +0.8% +1.2% 326.12 KB 328.69 KB 69.17 KB 70.01 KB NODE_DEV
react-reconciler-persistent.production.min.js 🔺+0.6% 🔺+0.6% 46.81 KB 47.11 KB 14.01 KB 14.1 KB NODE_PROD
react-reconciler-reflection.development.js +21.8% +24.7% 11.57 KB 14.09 KB 3.56 KB 4.43 KB NODE_DEV
react-reconciler-reflection.production.min.js 🔺+12.8% 🔺+12.2% 2.26 KB 2.55 KB 1 KB 1.13 KB NODE_PROD

simple-cache-provider

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
simple-cache-provider.development.js +18.6% +21.6% 7.47 KB 8.86 KB 2.36 KB 2.86 KB NODE_DEV
SimpleCacheProvider-dev.js -0.1% -0.3% 7.87 KB 7.86 KB 2.39 KB 2.38 KB FB_WWW_DEV
SimpleCacheProvider-prod.js 🔺+0.5% 🔺+0.9% 3.63 KB 3.65 KB 1.1 KB 1.11 KB FB_WWW_PROD

create-subscription

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
create-subscription.development.js +45.8% +44.2% 5.5 KB 8.02 KB 1.93 KB 2.78 KB NODE_DEV
create-subscription.production.min.js 🔺+11.6% 🔺+9.5% 2.53 KB 2.82 KB 1.2 KB 1.32 KB NODE_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js +0.6% +0.8% 461.02 KB 463.82 KB 101.15 KB 102 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+0.3% 🔺+0.6% 206.26 KB 206.8 KB 36.21 KB 36.42 KB RN_FB_PROD
ReactNativeRenderer-dev.js +0.6% +0.8% 460.73 KB 463.53 KB 101.09 KB 101.94 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 🔺+0.3% 🔺+0.6% 198.82 KB 199.36 KB 34.75 KB 34.96 KB RN_OSS_PROD
ReactFabric-dev.js +0.6% +0.9% 451.27 KB 454.07 KB 98.75 KB 99.61 KB RN_FB_DEV
ReactFabric-prod.js 🔺+0.3% 🔺+0.6% 191.08 KB 191.62 KB 33.34 KB 33.55 KB RN_FB_PROD
ReactFabric-dev.js +0.6% +0.9% 451.31 KB 454.11 KB 98.77 KB 99.63 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+0.3% 🔺+0.6% 191.11 KB 191.66 KB 33.36 KB 33.57 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js +0.3% +0.6% 201.35 KB 201.9 KB 35.3 KB 35.51 KB RN_OSS_PROFILING
ReactFabric-profiling.js +0.3% +0.6% 193.33 KB 193.87 KB 33.82 KB 34.03 KB RN_OSS_PROFILING

react-scheduler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-scheduler.development.js -7.7% -6.2% 16.37 KB 15.1 KB 5.04 KB 4.73 KB UMD_DEV
react-scheduler.development.js +10.2% +11.9% 13.53 KB 14.91 KB 4.19 KB 4.69 KB NODE_DEV
ReactScheduler-dev.js -0.1% -0.2% 13.68 KB 13.67 KB 4.22 KB 4.21 KB FB_WWW_DEV
ReactScheduler-prod.js 🔺+0.2% 🔺+0.7% 6.89 KB 6.91 KB 1.79 KB 1.8 KB FB_WWW_PROD

Generated by 🚫 dangerJS

@gaearon
Copy link
Collaborator Author

gaearon commented Jun 18, 2018

Btw I've no idea what's causing the size changes. Some CommonJS interop junk? Would be interesting to dive in.

@TrySound
Copy link
Contributor

There are already warning and invariant packages which mirror fbjs versions. A lot of packages use them. Would be good if react monorepo will be the source of them.

https://www.npmjs.com/package/warning
https://www.npmjs.com/package/invariant

@gaearon
Copy link
Collaborator Author

gaearon commented Jun 18, 2018

We want to go in the other direction. These are just internal utilities and there’s nothing special about them that we’d want other people to rely on.

@TrySound
Copy link
Contributor

The size is reduced because babel helpers are reused across whole bundle. In fbjs they look like inlined.
https://unpkg.com/[email protected]/lib/warning.js

@gaearon
Copy link
Collaborator Author

gaearon commented Jun 18, 2018

We’re talking about ~50 bytes here. This doesn’t make a practical difference.

@TrySound
Copy link
Contributor

It's better to tell them because they do not accept any improvements like esm support.
https://github.com/BerkeleyTrue/warning#faq-read-before-opening-an-issue

@gaearon
Copy link
Collaborator Author

gaearon commented Jun 18, 2018

I don't understand what it is that you'd like us to on our side. We don't recommend anyone to use or depend on these modules. They're internal to React. If somebody decides to publish a copy it's their business—you're not obligated to use them either :-).

We want to stop depending on fbjs because fbjs includes a bunch of dependencies that we don't use, and so every install of React has to download them in vain (this doesn't have to do with bundle size, just package management). It's annoying when some transitive deps are flagged as having security issues, but again, we don't actually use them. So that's part of motivation for us to get rid of fbjs dependency.

Another part is that we might want to make more changes to our invariant/warning setup, potentially with React-specific aspects. This is harder to do when they're centralized like this and used by everyone. So we want to have more freedom by making them private.

@aweary
Copy link
Contributor

aweary commented Jun 18, 2018

I think it'd be worth broadcasting this change to the community. There are likely a number of packages that import from fbjs without declaring it as a dependency, because they assume it will be implicitly available through React.

@gaearon
Copy link
Collaborator Author

gaearon commented Jun 18, 2018

Umm.. That was always a bad idea. I'm worried that "announcing" this might make it look like we're intentionally breaking something, and trying to "smooth it over". Whereas in practice anybody who relies on this has a misunderstanding of how npm works.

@aweary
Copy link
Contributor

aweary commented Jun 18, 2018

I know it's a bad idea, but I've seen it before 🙂 Maybe it's uncommon enough to not worry about it.

@nhunzaker
Copy link
Contributor

I think it's reasonable: From the readme

Note: If you are consuming the code here and you are not also a Facebook project, be prepared for a bad time. APIs may appear or disappear and we may not follow semver strictly, though we will do our best to. This library is being published with our use cases in mind and is not necessarily meant to be consumed by the broader public.

@realityking
Copy link
Contributor

IMHO it'd be great to make invariant warning official react packages, either taking over those npm repos or calling them react-warning and react-invariant.

Not only are they quite popular in the React ecosystem and it'd be great if there was more code sharing going on here, they're also used by other React projects from Facebook like prop-types and React Native.

@TrySound
Copy link
Contributor

@realityking This already was discussed above
#13069 (comment)

@realityking
Copy link
Contributor

@TrySound I saw that but it doesn't address the usage in other React projects like Native and prop-types.

@gaearon
Copy link
Collaborator Author

gaearon commented Jun 19, 2018

There's just no reason for anyone to want to use our warning and invariant modules. It's kind of a cargo cult which I regrettably contributed to a while ago in my own packages.

Inside React, they have a specific purpose. We use invariant to tag code that we apply some transforms to (e.g. stripping the error message). We use warning so we can override the behavior internally at FB and show warnings differently. Neither of those capabilities is available or useful to external projects.

React Native might also inline them later. PropTypes can be changed to use throw and console.error directly.

Copy link
Contributor

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

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

I dig it.

I think we can now remove the "fbjs" dependency in our release script?

@@ -237,6 +237,20 @@ function isProfilingBundleType(bundleType) {
}
}

function blacklistFBJS() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 👍

'prop-types/checkPropTypes': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
'fbjs/lib/camelizeStyleName': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
'fbjs/lib/hyphenateStyleName': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
deepFreezeAndThrowOnMutationInDev: HAS_NO_SIDE_EFFECTS_ON_IMPORT,
Copy link
Contributor

Choose a reason for hiding this comment

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

Also nice 😄

@gaearon
Copy link
Collaborator Author

gaearon commented Jun 19, 2018

PropTypes PR: facebook/prop-types#194

@gaearon gaearon merged commit aeda7b7 into facebook:master Jun 19, 2018
NMinhNguyen referenced this pull request in enzymejs/react-shallow-renderer Jan 29, 2020
* Inline fbjs/lib/invariant

* Inline fbjs/lib/warning

* Remove remaining usage of fbjs in packages/*.js

* Fix lint

* Remove fbjs from dependencies

* Protect against accidental fbjs imports

* Fix broken test mocks

* Allow transitive deps on fbjs/ for UMD bundles

* Remove fbjs from release script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants