-
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
[Lens] Fully unmount React when flyout closes #95359
Conversation
Pinging @elastic/kibana-app (Team:KibanaApp) |
The failure looks real - maybe there's a leftover render function which is not containing an unmount callback?
|
@flash1293 yes, it was a real failure. The editor frame uses an async function to do its rendering, and I am now correctly handling this case. |
if (cleanupRef.current && typeof cleanupRef.current === 'function') { | ||
cleanupRef.current(elementRef.current); | ||
} | ||
unmountComponentAtNode(elementRef.current); |
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.
This PR adds a way to return a cleanup function (even an async one) from the render function, but it seems like this is never used, right?
The
unmountComponentAtNode(elementRef.current);
line is basically a default implementation of the cleanup specific to react and it does all the actual cleanup here.
I guess my question is: Do we actually need the unmount callback logic? Or is it more of a future-facing thing?
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.
Yes, the cleanupRef
is only used in the new tests It's there to maintain the existing assumption that Lens is framework independent.
@elasticmachine merge upstream |
💚 Build SucceededMetrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: |
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.
Tested and works as expected, thanks for explaining!
* [Lens] Fully unmount React when flyout closes * Fix bug with editor frame unmounting * Fix type Co-authored-by: Kibana Machine <[email protected]>
* [Lens] Fully unmount React when flyout closes * Fix bug with editor frame unmounting * Fix type Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Wylie Conlon <[email protected]>
Steps to reproduce:
I18nProvider
elements at the bottom of the inspector, which is rendered as a separate React root.I18nProvider
in the dev tools and verify that there is a matching and visible DOM element.There is a performance penalty associated with this change. The way I compared the performance before and after was by comparing the time to re-open the flyout, and found that it was
0.3ms
to render when the element is kept in the virtual DOM, vs15.9ms
when the element is rendered from the first time. Steps to check:Then I tabbed through each commit cycle in React, and found React executes 9 cycles with this PR, vs 2 cycles before. It also takes much longer. I believe this is a necessary slowdown because keeping the flyout element in virtual DOM causes more problems and is a potential memory leak.
Checklist