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

Data: Schedule render by store update via setState #7746

Merged
merged 2 commits into from
Jul 6, 2018

Conversation

aduth
Copy link
Member

@aduth aduth commented Jul 6, 2018

Fixes #7722

This pull request seeks to resolve an issue with withSelect state derivations where a subscribe update could be called with old versions of this.props during a scheduled update. Its subsequent forceUpdate would thereby prevent the default shouldComponentUpdate from taking place, where new props would be expected to be accounted for. The revised implementation here uses setState with awareness of the state change by referential equality condition to allow a props change to be accounted for after the subscribe.

Implementation notes:

I have thus far been unsuccessful in recreating this via a failing unit test. It's unclear if the render reconciliation flow is different in Enzyme / react-test-renderer. Neither have shown promise. The general idea would be that a prop update from a parent would be applied after a child had already triggered forceUpdate, and this prop update should but does not have an impact on the getDerivedStateFromProps. In the case of #7722, this prop is lastBlockUID, where the presence of a previous default block should be preventing the appender from being shown.

The specific handling in React where shouldComponentUpdate is being skipped occurs here:

https://github.com/facebook/react/blob/4fe6eec15bc69737910e5c6c749ebc6187d67be0/packages/react-reconciler/src/ReactFiberClassComponent.js#L816-L825

I had explored a number of alternative approaches here, none of which proved to provide stability in ensuring (a) synchronous application of state changes (otherwise resulting in strange behaviors like caret positioning shifting) or (b) major performance regressions.

See: https://gist.github.com/aduth/0b5b6ed26acbbf2f6387cb46d42059fe

Testing instructions:

Repeat Steps to Reproduce from #7722, verifying that no ghost appender appears.

Ensure unit tests pass:

npm run test-unit

Verify there are no performance regressions by typing within the Demo post.

@aduth aduth added [Type] Bug An existing feature does not function as intended [Priority] High Used to indicate top priority items that need quick attention Framework Issues related to broader framework topics, especially as it relates to javascript labels Jul 6, 2018
@aduth aduth added this to the 3.2 milestone Jul 6, 2018
@tofumatt tofumatt self-requested a review July 6, 2018 12:51
Copy link
Member

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

Tested locally, including the demo post. Perf seems good and the code makes sense.

I think the comments were a bit unclear ("exasperation comments" 😉), so I pushed a tweak to tidy them up.

If you're alright with them: 🚢

shouldComponentUpdate( nextProps, nextState ) {
const hasPropsChanged = ! isShallowEqual( this.props, nextProps );

// Only render if result of props change or merge props update
Copy link
Member

Choose a reason for hiding this comment

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

I think this comment is worded a bit strangely so I'm going to tweak it.

const nextMergeProps = getNextMergeProps( nextProps );
if ( ! isShallowEqual( this.mergeProps, nextMergeProps ) ) {
// While side effects are typically discouraged in this
// lifecycle methods, this component is very much on a hot
Copy link
Member

Choose a reason for hiding this comment

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

"hot code path" is a great turn of phrase but it might confuse ESL readers (or just folks unfamiliar with that colloquium). I'm just gonna tweak this comment.

@aduth
Copy link
Member Author

aduth commented Jul 6, 2018

tidy

@aduth
Copy link
Member Author

aduth commented Jul 6, 2018

My line hast been breached!

@tofumatt
Copy link
Member

tofumatt commented Jul 6, 2018

My tabs are set to 2-width in JS because everyone else in the universe uses 2-spaces for JS.

If it should be four then we should set it in the .editorconfig 😉

@aduth
Copy link
Member Author

aduth commented Jul 6, 2018

Oh come now, it's a pretty well-accepted objective truth that tabs are far superior than spaces.

@aduth aduth merged commit 6cd1707 into master Jul 6, 2018
@aduth aduth deleted the fix/7722-default-appender branch July 6, 2018 13:40
@jasmussen
Copy link
Contributor

💥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Issues related to broader framework topics, especially as it relates to javascript [Priority] High Used to indicate top priority items that need quick attention [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression: Weird behavior with default appender, appears to create two blocks
3 participants