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

Prevent process polyfill to be included in builds because of process … #9518

Merged
merged 1 commit into from
Apr 26, 2017

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Apr 25, 2017

Related - reduxjs/redux#2244

By guarding process like this its polyfill is included by default when bundled with webpack. It should be highly desirable to avoid such side effect.

I understand that this PR is not complete, but as your build setup is way more complex than what is used in most projects I would need some guidelines how this should be proceeded further. Maybe introducing __TEST__ in similar manner how u introduce __DEV__?

Also this should land in 15.x branch too and aint sure how this should be tackled here.

cc @gaearon

Also maybe that could have been tackled on webpack's side as most of the people dont realise this is a problem and guarding against process seems like a right way to do things in the code. Dunno if we can safely predict what was the user intention though. cc @TheLarkInn @sokra

typeof process !== 'undefined' &&
process.env &&
process.env.NODE_ENV === 'test'
) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please just change this require to be unconditional. It is no longer necessary to do this trickery now. (The original reason for this was related to some Jest behavior that's irrelevant with flat bundles.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should i just var ReactComponentTreeHook = require('ReactComponentTreeHook') at the top of the file?

This ReactComponentTreeHook is later conditionally required in __DEV__ block. What about it then? Should something be adjusted?

Copy link
Collaborator

Choose a reason for hiding this comment

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

should i just var ReactComponentTreeHook = require('ReactComponentTreeHook') at the top of the file?

Yes.

This ReactComponentTreeHook is later conditionally required in DEV block.

You can remove that. It’s unnecessary now.

typeof process !== 'undefined' &&
process.env &&
process.env.NODE_ENV === 'test'
) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's not touch this file. It's gone in next version of React.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should i revert this change and the latter? Would be cool to fix this whole thing in 15.x

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, please revert. I don’t see us fixing this in 15 given that the hack was added to work around an accidental breaking change in 15.2.1: #7240. Let’s wait for 16 here please.

if (
typeof process !== 'undefined' &&
process.env &&
process.env.NODE_ENV === 'test'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, let's leave this one as is because it's a goner.

@Andarist
Copy link
Contributor Author

@gaearon ok, so i've amended the commit according to your suggestions

@gaearon
Copy link
Collaborator

gaearon commented Apr 25, 2017

Can you run yarn build -- core --type=UMD and verify code from ReactComponentTreeHook doesn't end up in react.production.min.js?

@gaearon
Copy link
Collaborator

gaearon commented Apr 26, 2017

This looks good to me, thanks!

@gaearon gaearon merged commit dce3c28 into facebook:master Apr 26, 2017
@Andarist
Copy link
Contributor Author

Andarist commented Apr 29, 2017

@gaearon sorry for not confirming sooner, ive tried to figure this out sooner, but the mentioned file src/isomorphic/children/flattenChildren.js is in fact not a part of most build types and I had to return to the issue way later than ive expected due to lack of time

Had to realise its used only for yarn build -- core --type=FB (at least for now) and now I can confirm that the goal is satisfied ofc. ReactComponentTreeHook is gone for production build

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.

3 participants