Columns: Avoid re-render and subsequent action dispatch by adopting module constant #7720
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.
We were passing a new allowedBlocks reference on each column render. This dispatch additional unnecessary further actions to update inner block settings.
allowedBlocks reference should only be changed if, in fact, we are changing the allowedBlocks.
In the columns block, we can make allowed block a constant given that it never changes.
This problem may cause noticeable lag when writing/using columns because updating the InnerBlock setting may cause another rerender and another rerender updates the settings again. So this change prevents cascade re-renders.
The alternative is comparing each element of the array to verify if it changed or not. But this has a performance impact and we should not pass new props during rerenders if the props did not change so I feel this is the correct approach.
How has this been tested?
I verified the columns block works as before and no unnecessary UPDATE_BLOCK_LIST_SETTINGS are being dispatched.