Add getSnapshotBeforeUpdate support into shallow#1657
Merged
ljharb merged 1 commit intoenzymejs:masterfrom Jun 29, 2018
Merged
Conversation
41ced7e to
d9d878b
Compare
10 tasks
ljharb
requested changes
Jun 28, 2018
| } else { | ||
| instance.componentDidUpdate(prevProps, state); | ||
| let snapshot; | ||
| if ( |
Member
There was a problem hiding this comment.
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?
ljharb
reviewed
Jun 28, 2018
| this.options = { | ||
| ...this.options, | ||
| enableComponentDidUpdateOnSetState: true, | ||
| supportGetSnapshotBeforeUpdate: true, |
Member
There was a problem hiding this comment.
i'll add a new adapter for 16.2 separately, so this is the proper place to update this.
d9d878b to
3b017f7
Compare
ljharb
approved these changes
Jun 29, 2018
Member
ljharb
left a comment
There was a problem hiding this comment.
I went ahead and made the changes.
|
when will this be released? please :) |
ljharb
added a commit
that referenced
this pull request
Aug 8, 2018
- [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
Member
|
The following packages are now released: |
This was referenced Aug 8, 2018
This was referenced Oct 1, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.