-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Avoid calling redux actions constantly when moving the mouse or scrolling #44325
Conversation
Size Change: +73 B (0%) Total Size: 1.26 MB
ℹ️ View Unchanged
|
* | ||
* @return {Record<string,boolean>} Block visibility. | ||
*/ | ||
export function blockVisibility( state = {}, action ) { |
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.
Moving blockVisibility state of the "blocks" state means any change to "blockVisibility" won't have an impact on the undo/redo behavior.
before this a call to SET_BLOCK_VISIBILITY
would force an undo state even if we were typing in the middle of a word.
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 have tested this by making some commonly large posts and seeing if there is any flicker or delay in how blocks show up. I did not notice a difference vs trunk
for scrolling but I did notice a great difference in how intentful the inserter showing up feels.
Although the numbers seem the same in this PR the delay in which the inserter shows up is actually real, I found this very refreshing getting rid of the flickering inserter on scroll.
The code LGTM
What?
I've noticed that when you scroll the page or when you move the mouse on the editor canvas, there are redux actions that are constantly called, causing potential re-renders and this might slow the editor and remove the feeling of responsiveness. This PR makes sure these actions are delayed/debounced accordingly.
Why?
To improve the responsive of the editor when moving around.
How?
setBlockVisibility
action which is responsible of the sync/async behavior of the data module is delayed and batched.showInsertionPoint
call entirely to avoid re-rendering, that way when you move the mouse across blocks, the insertion point action is not triggered at all unless you stay more than 500ms between the blocks.I'm not sure we have performance metrics that show the impact here but I'm convinced this will largely improve the responsiveness when moving the mouse on large posts.
Testing Instructions
1- Test the in-between inserter
2- Try scrolling and moving the mouse around especially with large posts.