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

Inserter: Use effect for unmodified default block replacement #5090

Closed
wants to merge 1 commit into from

Conversation

aduth
Copy link
Member

@aduth aduth commented Feb 16, 2018

Related: #4917

This pull request seeks to refactor the inserter default block replacement logic introduced in #4917 with an effect-based implementation. This optimizes the rendering of Inserter which currently rerenders on any change to the selected block, since the mergeProps result includes a changing function reference (even though we're careful not to pass the changing selectedBlock reference).

Testing instructions:

Repeat testing instructions from #4917

@aduth aduth added [Feature] Inserter The main way to insert blocks using the + button in the editing interface [Type] Performance Related to performance efforts labels Feb 16, 2018
@aduth aduth changed the title Inserter: Replace unmodified default block replacement using effect Inserter: Use effect for unmodified default block replacement Feb 16, 2018
@@ -97,30 +96,20 @@ export default compose( [
( state, ownProps ) => {
return {
insertionPoint: getBlockInsertionPoint( state, ownProps.rootUID ),
selectedBlock: getSelectedBlock( state ),
Copy link
Contributor

Choose a reason for hiding this comment

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

We could use limit the prop to the uid as well.

@youknowriad
Copy link
Contributor

I think I prefer the previous code (but I'm biased since I wrote it) but I don't feel strongly one way or another.

@@ -530,4 +557,6 @@ export default {
window.fetch( window._wpMetaBoxUrl, fetchOptions )
.then( () => store.dispatch( metaBoxUpdatesSuccess() ) );
},

INSERT_BLOCKS: removeDefaultEmptyPrecedingBlock,
Copy link
Contributor

Choose a reason for hiding this comment

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

I like that it's a separate documented function though it creates inconsistency between the effect handlers, we might want to move them all to separate functions.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like that it's a separate documented function though it creates inconsistency between the effect handlers, we might want to move them all to separate functions.

Yeah, this was trying something new, since I didn't like the disorganization of this file, which is largely a result of a disconnect between the action types upon which they act, and the behaviors themselves. This had also encouraged including many different side effects in the same handler, when in-fact the value can be an array of functions, where each is an individual side effect for that particular action. Finally (and a more minor point), our unit tests should be testing the behavior of the side effect, not the original firing action.

@aduth
Copy link
Member Author

aduth commented Feb 16, 2018

I think I prefer the previous code (but I'm biased since I wrote it) but I don't feel strongly one way or another.

I'm on the fence myself whether this behavior should be best described as a side-effect. The more pragmatic concern is that of performance: re-rendering this component on every block update.

@aduth
Copy link
Member Author

aduth commented Feb 16, 2018

The more pragmatic concern is that of performance: re-rendering this component on every block update.

In a worst case, there's an areMergedPropsEqual function we could implement in the fourth options argument of connect, though this would be tricky to do correctly since we do need the function to change when the values it depends on change.

https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options

@aduth
Copy link
Member Author

aduth commented Feb 23, 2018

The component still renders more than it should (because of the selectedBlock prop), but this has been pretty well improved using withDispatch in #5137.

@aduth aduth closed this Feb 23, 2018
@aduth aduth deleted the update/inserter-replace-unmodified-effect branch February 23, 2018 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Type] Performance Related to performance efforts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants