Replies: 7 comments
-
Tooltip is a very quirky component, so I can see it might have this kind of issue. It might be good to put together a unit test case that replicates this and help prevent regressions when the problem is fixed (cc @ciampo @mirka who may be interested in this).
A render won't usually cause a focus loss. Even a full render of an app won't unless something purposely changes around the focused element when react has reconciled and is updating the DOM. A render is usually the term for calling a function component or calling the I feel it's worth mentioning this as there's often an impression that rendering in React is bad. It may be bad for performance if it happens too often, but shouldn't really cause other issues unless there's buggy code in a component. There's some info here on reconciliation - https://reactjs.org/docs/reconciliation.html. I imagine what's happening in tooltip is something like that 'Elements Of Different Types' section. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the ping! We are planning on rewriting I second what @talldan wrote above — here's an example of a bug caused by reconciliation that we fixed recently #43508 |
Beta Was this translation helpful? Give feedback.
-
@talldan thanks for your feedback.
Terminology: by 'full re-rendering' I didn't mean the React 'render'. That's React terminology. I did mean re-rendering in the browser (or re-painting, if you like) as in: an element gets removed and re-injected, triggering a full re-rendering of a portion of the page. I know that happens when React isn't able to reconcile. You can actually test this Tooltip behavior on #43952
Animated GIF to better illustrate: |
Beta Was this translation helpful? Give feedback.
-
@afercia is this still an issue now that #48222 has been merged? |
Beta Was this translation helpful? Give feedback.
-
@fabiankaegy yes this appears to still be a problem. To reproduce:
As I mentioned above, right now the only workaround is to force the tooltip to always be rendered by setting the |
Beta Was this translation helpful? Give feedback.
-
I'm not sure this is really something that |
Beta Was this translation helpful? Give feedback.
-
Moving the conversation to issue #56522 |
Beta Was this translation helpful? Give feedback.
-
Splitting this out from #43952, see there for a an actual use case.
Turns out that setting a Tooltip conditionally may trigger a full re-rendering of the button the tooltip is set to.
A full re-rendering is less than ideal for a couple reasons:
There are legitimate cases where we would want to set a Tooltip conditionally, for example:
Right now, the only workaround is to force the tooltip to always be rendered by setting the
showTooltip
prop to true. However, it doesn't make much sense to show both visible text and a tooltip. For example, a button with text 'Save' and also a tooltip with text 'Save' is pointless.I guess one option would be refactoring the Tooltip component to always mount the tooltip and switch is visibility with CSS. I'm not sure there are other ways, any thoughts and considerations are very welcome.
The main point here is to avoid a full re-rendering of the button (or other interactive control) the Tooltip it associated with.
Beta Was this translation helpful? Give feedback.
All reactions