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

[RFC] Convert source module format from ES6 to CommonJS #152

Merged
merged 3 commits into from Jul 25, 2014

Conversation

pieterv
Copy link
Contributor

@pieterv pieterv commented Jul 12, 2014

The es6 module transpiler currently doesn't have a way to exclude 3rd party libs (and even if was added the grunt plugin is out of date anyway) which meant we have had to keep copies of React lib files converted to use es6 module imports in our repo, this is bad practice as it means we are unnecessarily locking react bootstrap to a specific react version and with React 0.11 on the near horizon not having this could make the transition between React version difficult as we can only support one version at a time. This change swaps the module format to CommonJS which (for the moment) has more mature tooling support allowing this functionality.

When swapping out the import statements i removed the additional whitespace aligning the ='s, this was becoming difficult to maintain and i didn't think worth the work to keep them in sync.

The tests are all passing but are throwing up the following error:

WARN: 'Warning: You are calling cloneWithProps() on a child with a ref. This is dangerous because you're creating a new child which will not be added as a ref to its parent.'

Since i haven't changed any functionality i assume we had just removed this error in our version of react/lib/cloneWithProps? But guess we will need to fix this properly if this change goes through.

The AMD files will need additional testing, i am just wrapping the CommonJS modules with define(function (require, exports, module) {}); via grunt-amd-wrap and it looks like it should run fine to me but i don't have a proper AMD project to test it in.

@stevoland how do you feel about this? I know we have only recently switched to es6 modules and it would be nice to transition back once the tools have stabilised.

@stevoland
Copy link
Contributor

Yeah we should definitely do this. I've no time to check this out properly at the moment though - it will have to wait a week or so. Cheers.

@pieterv
Copy link
Contributor Author

pieterv commented Jul 14, 2014

@stevoland Awesome, if its cool with you i will merge to master and create an issue to test the AMD modules.

@stevoland
Copy link
Contributor

@pieterv I'd like to hold on the merge til I get a chance to check it out properly. We use AMD at work so I'd like to make sure it's right first. Cheers.

@pieterv
Copy link
Contributor Author

pieterv commented Jul 16, 2014

Ok no problem :)

If anyone wants a React v0.11 compatible build (for CommonJS) just let me know and i can set one up until we can do a proper release.

@stevoland
Copy link
Contributor

Had a quick look and the AMD build doesn't work as it doesn't include the React internal modules in the build.

@pieterv
Copy link
Contributor Author

pieterv commented Jul 18, 2014

I assume you are talking about the amd/react-bootstrap.js bundled file? I have just pushed up a change for the requirejs grunt config which now includes all react internals needed. I have tested it locally so should work this time :P

@stevoland
Copy link
Contributor

No, I was referring to the AMD modules themselves although it would affect the bundled file also. We need to include the required internal React modules themselves. When a user does require('react-bootstrap').Nav; that module does require('react/lib/cx'); which isn't defined anywhere but needs to be. I might be able to look into this at the weekend but my broken laptop's getting in the way.

@pieterv
Copy link
Contributor Author

pieterv commented Jul 18, 2014

Right i understand now, i didn't realise the bower version of react didn't expose the internals as AMD modules. I assumed it was the same as the npm (commonjs) version. In this case i wonder whether we should switch to using react/addons and use these API's that way? I almost made this change the other day, but wasn't sure how it would work if something required react as well as react/addons, but looking at it now it should be fine. What do you think? Im happy to make that change and add it to this PR.

No good about your laptop, the screen died on mine (via me dropping it :|) a couple of weeks back so i feel your pain.

@tsing
Copy link

tsing commented Jul 19, 2014

@pieterv Would you please release a React v0.11 compatible build (for CommonJS) ?

The es6 module transpiler currently doesn't have a way to exclude 3rd
party libs which meant we have had to keep copies of React lib files
converted to use es6 module imports in our repo, this is bad practice as
it means we are unnecessarily locking react bootstrap to a specific
react version. This change swaps the module format to CommonJS which
(for the moment) has more mature tooling support allowing this
functionality.
@pieterv
Copy link
Contributor Author

pieterv commented Jul 19, 2014

@tsing i have created a build and pushed it to my github account, you should be able to install it via npm install pieterv/react-bootstrap-npm. Let us know if you have any problems with this.

@stevoland
Copy link
Contributor

@tsing @pieterv Hmm, I thought RB 0.11 was compatable with React 0.11. Is it not?

@pieterv
Copy link
Contributor Author

pieterv commented Jul 20, 2014

@stevoland it is in the sense that the tests pass and seems to work in general but since the react internals in RB are still from version 0.10 we don't know what edge cases could come up since we are doing things like cloneWithProps on react components from 0.11 but using 0.10 cloneWithProps logic. The build i did using this branch would be safer as it uses the internals from the react version you have installed. Does that make sense?

@tsing
Copy link

tsing commented Jul 21, 2014

@pieterv The pieterv/react-bootstrap-npm works perfect in my project

@pieterv
Copy link
Contributor Author

pieterv commented Jul 21, 2014

@tsing Awesome :)

@kellec is currently working on the change to using using react/addons instead of react/lib/*, which is looking pretty straight forward :)

@brigand
Copy link

brigand commented Jul 21, 2014

If it's switched to browserify, you can generate a UMD with a simple config option, which gives you compatibility with commonjs (node or browserify), AMD, and window globals.

@stevoland
Copy link
Contributor

@tsing @pieterv I'm not sure I'd like to require react.addons just for a couple of internal functions. In addition, we're using ReactTransitionEvents which isn't exposed in the addons. I'm comfortable using copies of these until the React module system makes it possible to access these modules properly.

@brigand Currently we support requiring individual modules require('react-boostrap').Button in AMD and I'd like to continue this. We would need each module to be wrapped in UMD and also a way to wrap these internal React modules.

I'm hoping to look into this this week.

@pieterv
Copy link
Contributor Author

pieterv commented Jul 22, 2014

@stevoland see facebook/react#1906 on progress for React making internals available in some form.

Also agree about the react/addons after actually thinking about it how you would have to configure it. @kellec has some code pulling these react internals into react-bootstrap, the major one to copy is cloneWithProps, we will get that finished and push it up for review.

Removed all references to react/lib files, and move necessary functions
into their own files in a utils directory including: classSet,
cloneWithProps, createChainedFunction, EventListener, merge, and
TransitionEvents. If/when these become available through React we can
remove these files.
@kellec
Copy link
Contributor

kellec commented Jul 23, 2014

I've removed all references to react/lib files, and where we need access to an unexposed React method, the functionality has been copied into it's own file and placed into a /utils directory to try to keep the main src directory for components. Also split up the former utils.js file and removed the deprecated functions.

We ended up with classSet, cloneWithProps, EventListener, createChainedFunction, merge, and TransitionEvents. Since they're their own files we can easily remove them if/when the method becomes available (which may happen in a staggered fashion per the link from @pieterv above). Where relevant, the files contain comments to this effect. This way we don't have to require react/addons which was going to be a giant pain when supporting both AMD and CommonJS.

This is passing the tests and the docs site works fine, which takes care of the CJS modules. I set up a quick AMD testing environment to check it, and it's working fine there too.

@stevoland
Copy link
Contributor

@kellec This sounds perfect! I'll try to check it out tonight.

@stevoland
Copy link
Contributor

@kellec Sorry for the delay. This is perfect, thanks so much.

@pieterv I'm going to do a patch release for this. It seems there's no breaking changes, right?

stevoland added a commit that referenced this pull request Jul 25, 2014
Convert source module format from ES6 to CommonJS
@stevoland stevoland merged commit ff1e72a into react-bootstrap:master Jul 25, 2014
@pieterv pieterv deleted the es6-modules-to-commonjs branch July 25, 2014 23:00
@pieterv
Copy link
Contributor Author

pieterv commented Jul 25, 2014

Awesome! :)

@stevoland no breaking changes to the public components, the only breaking change will be if someone was requiring one of our internal utils modules which have now moved.

@stevoland
Copy link
Contributor

I've released 0.11.1 with all the new hotness - great work.

@kellec
Copy link
Contributor

kellec commented Jul 28, 2014

Yay, awesome :D

@pieterv
Copy link
Contributor Author

pieterv commented Jul 28, 2014

Awesome! You got to love any pull request thats +710 but −17,994 lines :P

aryad14 pushed a commit to aryad14/react-bootstrap that referenced this pull request Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants