-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
@@ -97,30 +96,20 @@ export default compose( [ | |||
( state, ownProps ) => { | |||
return { | |||
insertionPoint: getBlockInsertionPoint( state, ownProps.rootUID ), | |||
selectedBlock: getSelectedBlock( state ), |
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.
We could use limit the prop to the uid
as well.
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, |
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 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.
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 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.
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. |
In a worst case, there's an |
The component still renders more than it should (because of the |
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 themergeProps
result includes a changing function reference (even though we're careful not to pass the changingselectedBlock
reference).Testing instructions:
Repeat testing instructions from #4917