Skip to content
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

[8.x] [Dashboard] [Collapsable Panels] Reduce re-renders (#197343) #198219

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

kibanamachine
Copy link
Contributor

Backport

This will backport the following commits from main to 8.x:

Questions ?

Please refer to the Backport tool documentation

Questions ?

Please refer to the Backport tool documentation

Questions ?

Please refer to the Backport tool documentation

Questions ?

Please refer to the Backport tool documentation

Closes elastic#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]>
(cherry picked from commit b91fa56)
@kibanamachine kibanamachine merged commit 1f9e9e7 into elastic:8.x Oct 29, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants