Fix externalization of 'lowPriorityWarning' in fb builds#9790
Fix externalization of 'lowPriorityWarning' in fb builds#9790flarnie merged 1 commit intofacebook:masterfrom
Conversation
**what is the change?:** - Add two more special cases for 'lowPriorityWarning' in 'modules.js', treating it the same as 'ReactCurrentOwner'. **why make this change?:** Without this, the build was including 'lowPriorityWarning' seemingly both as an external module and as part of the bundle. **test plan:** Ran `yarn build` and inspected the `React-dev` build. `lowPriorityWarning` did not get bundled in this time. **issue:** None yet - @gaearon flagged this for me directly.
|
Is there anything we can change in build system so that it wouldn't compile in the first place instead of producing weird output? @trueadm |
|
@gaearon it's a tricky one though – as this should build, but only for non-FB? Unless I misunderstand you. |
|
I mean that instead of producing broken output for FB bundles, it would be nice if it failed to build. var invariant = require('fbjs/lib/invariant')
var warning = require('fbjs/lib/warning')
require('lowPriorityWarning'); // it never makes sense to have top level require like this
// ...
function lowPriorityWarning() {
// ...
} |
|
@gaearon so I am not sure why this is. It sounds like a bug in Rollup maybe. I'll CC @Rich-Harris, if we can get a test case, maybe he can explain why this is the case. |
|
It is a bit hard to explain—you can revert this commit locally, run Our intention was to make However this produced a build that both had (an unused) This is not the first time we make this mistake (whatever it is). I remember having the same issue a few times before when I tried to externalize a module. I expect that adding it to I am suggesting that we either make |
|
@gaearon I understand, thank you for explaining that. I think the confusion is by the naming and the misconception that this works like Webpack – which it does not. I'll make it work like Webpack externals next week. It shouldn't take too much time to make, I just need to re-test everything extensively :) |
|
Awesome, thanks! I don't think it's necessary to make it work specifically like Webpack, but it shouldn't be so easy to end up with a broken state. Maybe we could just rename |
|
If the correct mental model for "external" modules today is that these are the modules that are allowed to be |
|
@gaearon I agree, although this is definitely a harder one to solve as it's how Rollup works by default. I do however have a solution without changing Rollup: we define externals for DEV and non DEV bundles, like we do now with To be honest, I'm not sure why I didn't think of this before. This is by far the best solution in my eyes, I guess I was trying to hard to automate this – but having them separate is probably more declarative in descriptive anyway. |
Thanks to @spicyj for pairing with me on this.
what is the change?:
treating it the same as 'ReactCurrentOwner'.
why make this change?:
Without this, the build was including 'lowPriorityWarning' seemingly both as an external module and as part of the bundle in fb builds.
test plan:
Ran
yarn buildand inspected theReact-devbuild.lowPriorityWarningdid not get bundled in this time.issue:
None yet - @gaearon flagged this for me directly.