Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Dashboard] [Collapsable Panels] Reduce re-renders (#197343)
Closes #191131 ## Summary This PR greatly reduces the number of React re-renders that happen as panels get dragged around and/or resized. Now, the actions that trigger a panel to get rendered are as follows: 1. Obviously, when the grid first loads, every panel has to be rendered. 2. When a panel gets dragged from one row to the next, both the original row and the new row will re-render all of their panels because the panel IDs in both rows changed - however, because of the `key` prop on the `GridPanel` component, only the **dragged** panel will actually be fully re-mounted. 3. When a panel gets collapsed and expanded, all panels in that row will get re-mounted and rendered. 4. When a panel ID gets changed (this currently isn't possible, but in theory, this would also trigger the panel to get re-rendered due to the `key` prop on the `GridPanel` component) In order to accomplish this, we are now handling **all style changes** via a subscription rather than setting the CSS directly; so, as the `gridLayout$` behaviour subjects publishes changes, we update the row + panel styles via the panel reference. This allows us to change how the grid looks without triggering React to rerender the entire panel. **How to Test:** Add a `console.log` to the `renderPanelContents` in `examples/grid_example/public/app.tsx` - this will tell you when a panel is getting re-rendered. ### Checklist - [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels) - [ ] This will appear in the **Release Notes** and follow the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information