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

Upgrade to react 16 #191

Merged
merged 21 commits into from
Oct 15, 2017
Merged

Upgrade to react 16 #191

merged 21 commits into from
Oct 15, 2017

Conversation

tobilen
Copy link
Collaborator

@tobilen tobilen commented Sep 30, 2017

This kind of snowballed.

the old version of storybook doesnt work with react16. it was throwing exceptions before, so i just upgraded it to the most recent version.
This meant webpack had to be upgraded, so i've done that as well. The stories are all looking good so far.

The big problem with react 16 is enzyme. I imported the adapter, but chai-enzyme doesnt play nice with enzyme 3 yet.
There is an open PR which solves most of the issues. the others i circumvented by refactoring the assertions a bit. until its merged, you need to build chai-enzyme yourself:

  1. cd node_modules/chai-enzyme
  2. yarn && yarn build

The setProps() call doesnt seem to be working the same way in enzyme 3, which made the mountAttached + attachedWrapper.setProps(...) logic in the tests break. i worked around this by remounting for every test, but this of course makes the old/new position comparisons not work.

=================================
Update:
Refactored testing component so it passes its state to flip-move instead of its props. This means we can use setState(...) instead of setProps(...) to trigger a transition.
I had to make an empty setState(...) call after initial mounting because ...well, setState updates in enzyme 3 still appear to be a bit wonky.
I also removed chai-enzyme assertions for the time being.

@joshwcomeau
Copy link
Owner

Oh wow! Thanks so much for this, whole project is modernized :D

If I understand correctly:

  1. chai-enzyme is incompatible with Enzyme 3, and Enzyme 3 is needed for React 16
  2. There's an open PR on chai-enzyme (Make compatible with enzyme v3 enzymejs/chai-enzyme#196?) which addresses this, but in the meantime the tests can pass if you build it yourself, since you've specified a fork right now.
  3. The tests fail now because we can't use setProps anymore. Looking at the code, it seems like you're just mounting with the value, which means that the tests are failing (I presume because there's no longer a transition between two states, it just mounts at the final state?)

For those first two points, I wonder if chai-enzyme is worth the trouble. It's certainly a convenience, but I feel like regular Chai is good enough (as I see you've done, by just using to.equal instead of to.have.id).

For the third point... I initially thought this was an issue of state carrying between tests, but I remembered that @Hypnosphi's great work meant that we are already mounting for every describe. I ran the tests locally and it is a bit tough to tell what's going on, but yeah I think the issue is that we need some way to update the props after the component has mounted; everything other than appear animations works on transitions between props.

So, i think we need to figure out what the deal is with setProps. Do you know more about how it changed / why it doesn't work anymore?

@tobilen
Copy link
Collaborator Author

tobilen commented Sep 30, 2017

To your first point, correct.
To your second point, not exactly. Using the fork means we get past this line, but, like you've observed yourself, there dont seem to be many chai enzyme assertions that actually work. Removing them entirely might be more feasible.

Third point seems to be the biggest issue, i agree. I've read through the enzyme migration guide a couple of times now, but i dont see anything that explains why setProps throws. The only viable workaround i see atm is defining a wrapper component that passes its state as props, and then just calling setState on the wrapper.

setState doesnt work like it did before, as i learned during the upgrade of our codebase at work yesterday. It doesnt throw, but it also doesnt always trigger rerenders on children (enzymejs/enzyme#1153 ), but maybe we can mitigate that by calling wrapper.update(). I'll try that tomorrow

@tobilen
Copy link
Collaborator Author

tobilen commented Oct 1, 2017

We're looking good now. I'd still like to add a story (and test) for passing fragments and string to flip-move though.

@tobilen
Copy link
Collaborator Author

tobilen commented Oct 1, 2017

test for proper fragment rendering ( 9022b85 ) and string rendering (a4673cf) has been added, i'd say we're good to go now.

@tobilen tobilen requested a review from Hypnosphi October 1, 2017 14:48
@tobilen tobilen assigned joshwcomeau and unassigned joshwcomeau Oct 1, 2017
@tobilen tobilen requested a review from joshwcomeau October 1, 2017 14:48
@tobilen tobilen mentioned this pull request Oct 1, 2017
Copy link
Owner

@joshwcomeau joshwcomeau left a comment

Choose a reason for hiding this comment

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

Wooo!!

Thanks so much for this, and sorry it took me a few days to get to it (In Mountainview this week, working for my job on-site, so it's been hectic).

I had a really small nit, but I'm happy to quickly do that myself in a subsequent commit.

Will test this locally tomorrow just to make sure nothing funky happens, and will publish a release ASAP!

@@ -3,6 +3,8 @@
.*/node_modules/editions/.*
.*/node_modules/flow-coverage-report/.*
.*/node_modules/preact/.*
.*/node_modules/@storybook/.*
.*/node_modules/radium/.*
Copy link
Owner

Choose a reason for hiding this comment

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

Guessing modern versions of Storybook use Radium?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not directly, but via react-treebeard. We use glamorous for our own components

Copy link
Owner

Choose a reason for hiding this comment

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

Oh cool! Wasn't aware you were a contributor to Storybook - thanks for your work there :)

package.json Outdated
"babel": "6.1.18",
"babel-cli": "6.2.0",
"babel-core": "6.2.1",
"@storybook/react": "^3.2.8",
Copy link
Owner

Choose a reason for hiding this comment

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

Nit: can we omit the ^?

I don't really think this even matters anymore, with Yarn/NPM5. But, my inner OCD wants it to be consistent, haha.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You probably also want to upgrade it to 3.2.12, there has been some critical bugfixes

@@ -8,6 +8,7 @@ config.plugins = [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
new webpack.optimize.ModuleConcatenationPlugin(),
Copy link
Owner

Choose a reason for hiding this comment

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

Oooh, neat! Keen to see the effect this has on bundle size.

Copy link
Collaborator

@Hypnosphi Hypnosphi left a comment

Choose a reason for hiding this comment

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

LGTM

package.json Outdated
@@ -46,29 +46,29 @@
"web-animations"
],
"peerDependencies": {
"react": "0.13.x || 0.14.x || 15.x.x",
"react-dom": "0.13.x || 0.14.x || 15.x.x"
"react": ">0.13.x <16.x.x",
Copy link
Collaborator

@Hypnosphi Hypnosphi Oct 4, 2017

Choose a reason for hiding this comment

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

Copy link
Owner

Choose a reason for hiding this comment

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

Good catch 👍

Copy link
Owner

@joshwcomeau joshwcomeau Oct 5, 2017

Choose a reason for hiding this comment

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

Looks like >=0.13.x <=16.x.x works

screen shot 2017-10-05 at 8 12 33 am

screen shot 2017-10-05 at 8 12 26 am

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

😊

@joshwcomeau
Copy link
Owner

Hm, so I pulled this locally, tried running storybook, and I get the following errors:

screen shot 2017-10-05 at 9 08 55 am

I tried removing node_modules and reinstalling, but it still seems like there's some React version discrepancy.

Have you encountered this? Any tips for how to get past it?

@tobilen
Copy link
Collaborator Author

tobilen commented Oct 5, 2017

@joshwcomeau try upgrading to the latest version of yarn i guess storybookjs/storybook#1868 (comment)

@tobilen
Copy link
Collaborator Author

tobilen commented Oct 14, 2017

@Hypnosphi can you update your review?

@joshwcomeau
Copy link
Owner

Woooo!!! Psyched to have this ready :D can't thank you enough for your work on this!!

@joshwcomeau joshwcomeau merged commit 932437d into master Oct 15, 2017
@joshwcomeau joshwcomeau deleted the upgrade-react-16 branch October 15, 2017 12:11
@joshwcomeau
Copy link
Owner

Released in v2.9.17! 🎊

(Also, sorry for not debugging the yarn issue more thoroughly myself; the issue was indeed using 0.x yarn, upgrading fixed it!)

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.

3 participants