-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Navigation: avoid rerendering when placeholder does not change #32357
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
Conversation
|
Size Change: -567 B (0%) Total Size: 1.03 MB
ℹ️ View Unchanged
|
| const placeholder = useRef(); | ||
| useEffect( () => { | ||
| placeholder.current = <PlaceholderPreview />; | ||
| }, [] ); |
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.
or this preferable?
const placeholder = useMemo( () => ( <PlaceholderPreview /> ) , [] );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.
The is a third option in
import { memo } from 'react';
const placeholder = memo( <Placeholder /> );It might be worth it to wrap placeholder-preview.js itself with memo, as it is a display component that shouldn't change between re-renders.
export default memo( PlaceholderPreview );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 think using one of the memo functions will make it easier to scan and understand.
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.
Good suggestion @vcanales! However while testing it looks like the HoC memo doesn't appear to work this this context. I'll try the useMemo line next.

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.
vcanales
left a comment
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.
Confirmed, and LGTM!
|
Thanks for the reviews @vcanales @Mamaduka @jasmussen ! |


When editing a post with a lot of navigation links, typing in a paragraph block is slowed down considerably. One of the top reasons for re-renders is the placeholder component passed to innerBlocks.
Before:
beforeplaceholder.mp4
After:
placeholder-after.mp4
Testing instructions
/navigationand selecting the navigation block
- Add a number of navigation links and try to type in another paragraph - In trunk: confirm that one of the main reasons for re-render is the placeholder prop in the react profiler (see before video) - On this branch: verify that the placeholder prop no longer shows up as a reason for rerender (see after video)