-
Notifications
You must be signed in to change notification settings - Fork 8.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
Fix: Prevent some needless re-rendering in high-level components #31958
Conversation
Pinging @elastic/kibana-canvas |
3452677
to
a6ecfad
Compare
💚 Build Succeeded |
a6ecfad
to
a6e2ded
Compare
💚 Build Succeeded |
💔 Build Failed |
💚 Build Succeeded |
allow setting the keyhandler function on the component instance
flat state prevents re-renders, and not using the workpad name prevents re-renders. plus, side effects should happen in middleware
help prevent re-renders on function redefinition
don't mutate values in mapStateToProps, so the connect function retains pure functionality
neither take props, so this stops some re-rendering
3168ff6
to
82525ac
Compare
💚 Build Succeeded |
@@ -9,6 +9,12 @@ import PropTypes from 'prop-types'; | |||
import { Shortcuts } from 'react-shortcuts'; | |||
|
|||
export class FullscreenControl extends React.PureComponent { | |||
keyHandler = action => { | |||
if (action === 'FULLSCREEN' || (this.props.isFullscreen && action === 'FULLSCREEN_EXIT')) { |
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.
nit: can we make these const
s?
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 don't understand what you're asking for here.
Is this what you're looking for?
export class FullscreenControl extends React.PureComponent {
keyHandler = action => {
- if (action === 'FULLSCREEN' || (this.props.isFullscreen && action === 'FULLSCREEN_EXIT')) {
+ const enterFullscreen = action === 'FULLSCREEN';
+ const exitFullscreen = this.props.isFullscreen && action === 'FULLSCREEN_EXIT';
+
+ if (enterFullscreen || exitFullscreen) {
this.toggleFullscreen();
}
};
<Shortcuts name="EDITOR" handler={keyHandler} targetNodeSelector="body" global /> | ||
)} | ||
const bufferStyle = { | ||
height: isFullscreen ? height : height + 32, |
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.
nit: can we make 32
a const
? It will help explain what it is and why it's necessary.
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'm not sure why that value is there, I didn't change that. I'll try figuring it out though.
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.
Excellent refactors! I threw a bunch of console.logs in all the render functions effected, and there are significantly less unnecessary re-renders when making changes to the workpad name, size, etc. I only have one requested change.
@@ -63,84 +69,85 @@ export const Workpad = props => { | |||
} | |||
}; | |||
|
|||
setDocTitle(workpad.name); | |||
render() { | |||
console.log('Workpad render'); |
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.
Please remove ^
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.
Nice spot!
|
||
next(action); | ||
|
||
// This middleware updates the page title when the workpad name changes | ||
if (getWorkpadName(getState()) !== oldName) { | ||
setDocTitle(getWorkpadName(getState())); |
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.
++ to checking the name changed before setting the doc title. This is a much better place to do the title update
💚 Build Succeeded |
…stic#31958) In an effort to remove the workpad renaming lag in elastic#25070, I started hunting down and fixing re-renders that happened with the name change. I was hoping this PR would fix the lag, but I've shifted to some other performance issues that have a much larger impact, so this is just a bunch of re-rendering fixes, which come with some performance gains. Here's the breakdown: - `Workpad`, `WorkpadHeader`, and `FullscreenControl` would always re-render because the hotkey handler function was always re-created - `Workpad` would re-render when the workpad's name changed - We were passing the whole workpad object into the component, so it re-rendered on all sorts of changes - Page title updating moved to middleware so the component doesn't need that value - `AssetManager` would always re-render if the parent re-rendered because it always created a new state value in `mapStateToProps` - make `Workpad` and `Toolbar` pure, they take no props and this helps stop some re-rendering
…stic#31958) In an effort to remove the workpad renaming lag in elastic#25070, I started hunting down and fixing re-renders that happened with the name change. I was hoping this PR would fix the lag, but I've shifted to some other performance issues that have a much larger impact, so this is just a bunch of re-rendering fixes, which come with some performance gains. Here's the breakdown: - `Workpad`, `WorkpadHeader`, and `FullscreenControl` would always re-render because the hotkey handler function was always re-created - `Workpad` would re-render when the workpad's name changed - We were passing the whole workpad object into the component, so it re-rendered on all sorts of changes - Page title updating moved to middleware so the component doesn't need that value - `AssetManager` would always re-render if the parent re-rendered because it always created a new state value in `mapStateToProps` - make `Workpad` and `Toolbar` pure, they take no props and this helps stop some re-rendering
…stic#31958) In an effort to remove the workpad renaming lag in elastic#25070, I started hunting down and fixing re-renders that happened with the name change. I was hoping this PR would fix the lag, but I've shifted to some other performance issues that have a much larger impact, so this is just a bunch of re-rendering fixes, which come with some performance gains. Here's the breakdown: - `Workpad`, `WorkpadHeader`, and `FullscreenControl` would always re-render because the hotkey handler function was always re-created - `Workpad` would re-render when the workpad's name changed - We were passing the whole workpad object into the component, so it re-rendered on all sorts of changes - Page title updating moved to middleware so the component doesn't need that value - `AssetManager` would always re-render if the parent re-rendered because it always created a new state value in `mapStateToProps` - make `Workpad` and `Toolbar` pure, they take no props and this helps stop some re-rendering
) (#32359) In an effort to remove the workpad renaming lag in #25070, I started hunting down and fixing re-renders that happened with the name change. I was hoping this PR would fix the lag, but I've shifted to some other performance issues that have a much larger impact, so this is just a bunch of re-rendering fixes, which come with some performance gains. Here's the breakdown: - `Workpad`, `WorkpadHeader`, and `FullscreenControl` would always re-render because the hotkey handler function was always re-created - `Workpad` would re-render when the workpad's name changed - We were passing the whole workpad object into the component, so it re-rendered on all sorts of changes - Page title updating moved to middleware so the component doesn't need that value - `AssetManager` would always re-render if the parent re-rendered because it always created a new state value in `mapStateToProps` - make `Workpad` and `Toolbar` pure, they take no props and this helps stop some re-rendering
) (#32358) In an effort to remove the workpad renaming lag in #25070, I started hunting down and fixing re-renders that happened with the name change. I was hoping this PR would fix the lag, but I've shifted to some other performance issues that have a much larger impact, so this is just a bunch of re-rendering fixes, which come with some performance gains. Here's the breakdown: - `Workpad`, `WorkpadHeader`, and `FullscreenControl` would always re-render because the hotkey handler function was always re-created - `Workpad` would re-render when the workpad's name changed - We were passing the whole workpad object into the component, so it re-rendered on all sorts of changes - Page title updating moved to middleware so the component doesn't need that value - `AssetManager` would always re-render if the parent re-rendered because it always created a new state value in `mapStateToProps` - make `Workpad` and `Toolbar` pure, they take no props and this helps stop some re-rendering
) (#32357) In an effort to remove the workpad renaming lag in #25070, I started hunting down and fixing re-renders that happened with the name change. I was hoping this PR would fix the lag, but I've shifted to some other performance issues that have a much larger impact, so this is just a bunch of re-rendering fixes, which come with some performance gains. Here's the breakdown: - `Workpad`, `WorkpadHeader`, and `FullscreenControl` would always re-render because the hotkey handler function was always re-created - `Workpad` would re-render when the workpad's name changed - We were passing the whole workpad object into the component, so it re-rendered on all sorts of changes - Page title updating moved to middleware so the component doesn't need that value - `AssetManager` would always re-render if the parent re-rendered because it always created a new state value in `mapStateToProps` - make `Workpad` and `Toolbar` pure, they take no props and this helps stop some re-rendering
…stic#31958) In an effort to remove the workpad renaming lag in elastic#25070, I started hunting down and fixing re-renders that happened with the name change. I was hoping this PR would fix the lag, but I've shifted to some other performance issues that have a much larger impact, so this is just a bunch of re-rendering fixes, which come with some performance gains. Here's the breakdown: - `Workpad`, `WorkpadHeader`, and `FullscreenControl` would always re-render because the hotkey handler function was always re-created - `Workpad` would re-render when the workpad's name changed - We were passing the whole workpad object into the component, so it re-rendered on all sorts of changes - Page title updating moved to middleware so the component doesn't need that value - `AssetManager` would always re-render if the parent re-rendered because it always created a new state value in `mapStateToProps` - make `Workpad` and `Toolbar` pure, they take no props and this helps stop some re-rendering (cherry picked from commit 7d8dbc6)
In an effort to remove the workpad renaming lag in #25070, I started hunting down and fixing re-renders that happened with the name change.
I was hoping this PR would fix the lag, but I've shifted to some other performance issues that have a much larger impact, so this is just a bunch of re-rendering fixes, which come with some performance gains. Here's the breakdown:
Workpad
,WorkpadHeader
, andFullscreenControl
would always re-render because the hotkey handler function was always re-createdWorkpad
would re-render when the workpad's name changedAssetManager
would always re-render if the parent re-rendered because it always created a new state value inmapStateToProps
Workpad
andToolbar
pure, they take no props and this helps stop some re-rendering