-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Add getSnapshotBeforeUpdate support into shallow #1657
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
Add getSnapshotBeforeUpdate support into shallow #1657
Conversation
41ced7e to
d9d878b
Compare
ljharb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is great!
| } else { | ||
| instance.componentDidUpdate(prevProps, state); | ||
| let snapshot; | ||
| if ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this logic is a bit hard to read - instead of making each step branch on cDU/gSBU - could we have two branches, one that's entirely cDU and one that's entirely gSBU?
| this.options = { | ||
| ...this.options, | ||
| enableComponentDidUpdateOnSetState: true, | ||
| supportGetSnapshotBeforeUpdate: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll add a new adapter for 16.2 separately, so this is the proper place to update this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've addressed this by #1192
d9d878b to
3b017f7
Compare
ljharb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went ahead and made the changes.
|
when will this be released? please :) |
- [new] add `isFragment` (#1733) - [new] Add `displayNameOfNode`, `isValidElementType` - [new] `mount`: add `hydrateIn` option (#1317, #1707) - [new] Add support for react context element types (#1513) - [new] `shallow`: Add getSnapshotBeforeUpdate support (#1657) - [fix] portals and roots may render fragments (#1733) - [fix] add missing support for animation events (#1569) - [fix] `shallow`: SFCs do not get a `this` (#1703) - [refactor]: add “lifecycles” adapter option (#1696) - [fix] call ref for a root element (#1541) - [fix] Allow empty strings as key props (#1524) - [fix] Fix ShallowWrapper for array-rendering components (#1498) - [refactor] use `react-is` package - [meta] ensure a license and readme is present in all packages when published
|
The following packages are now released: |
Fix #1602
This PR is to support
getSnapshotBeforeUpdateon shallow.I've added
supportGetSnapshotBeforeUpdateflag intoReactSixteenAdapterto implement this.As a result,
getSnapshotBeforeUpdateis called even if you usereact-test-renderer@<16.3.0so we have to add a new adapter likeenzyme-adapter-react16.2that turn offsupportGetSnapshotBeforeUpdate.You might think
getSnapshotBeforeUpdateshould be called beforerender, but the order is same asreact-dom.https://codepen.io/koba04/pen/erbbvB?editors=0011
React calls
getSnapshotBeforeUpdateat commit phase and callrenderat render phase so whengetSnapshotBeforeUpdateis calledrenderhas already been called.So It's reasonable for me that
shallowcallsgetSnapshotBeforeUpdateafterrender.