You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LogViewer does not initialize styles correctly when its container is hidden on first render (e.g. within the TabContent for a tab that is not initially selected)
#55
Open
mturley opened this issue
Dec 5, 2023
· 0 comments
We have a set of Tabs with TabContent components. They are rendered the standard way, where all TabContents are rendered regardless of which is active and the non-active tabs get a hidden attribute in the DOM.
One of the tabs which is not the default (its first render gets that hidden attribute) contains a LogViewer. When we switch to the Logs tab and the LogViewer's container becomes visible, the LogViewer's contents appear empty until something else triggers a re-render (such as resizing the window). However, if we change the code so that the Logs tab is the default tab (the LogViewer's first render is in a container that is not hidden), it works as expected.
This appears to be happening because of the way containerRef.current.clientHeight and .clientWidth are used in the createList function here. clientHeight and clientWidth resolve to 0 for hidden elements, so the List gets rendered with 0 height and 0 width. The container changing from hidden to non-hidden does not trigger a re-render in the LogViewer, so the List only gets its height and width set correctly when createList is called again after something else triggers a re-render.
One possible solution to this would be to add some kind of listener or observer that can detect that the containerRef.current element has become visible and have it trigger a re-render similarly to how resizing the window does. This could be done with an IntersectionObserveras described in this blog post.
I was able to reproduce the bug in the docs example here by opening the source of the basic example and editing it to have an additional "hidden" checkbox which defaults to true and applies a hidden attribute on a <div> wrapping the LogViewer. I would link a CodeSandbox showing this but it appears the sandbox generator on the site is broken (at least for this example). Adding an IntersectionObserver in the console while reproducing it in this way, I can detect that visibility changing.
The text was updated successfully, but these errors were encountered:
Found while investigating a bug that came up in opendatahub-io/odh-dashboard#2184 (comment) . See related Slack discussion here (Red Hat internal).
We have a set of
Tabs
withTabContent
components. They are rendered the standard way, where allTabContent
s are rendered regardless of which is active and the non-active tabs get ahidden
attribute in the DOM.One of the tabs which is not the default (its first render gets that
hidden
attribute) contains a LogViewer. When we switch to the Logs tab and the LogViewer's container becomes visible, the LogViewer's contents appear empty until something else triggers a re-render (such as resizing the window). However, if we change the code so that the Logs tab is the default tab (the LogViewer's first render is in a container that is nothidden
), it works as expected.This appears to be happening because of the way
containerRef.current.clientHeight
and.clientWidth
are used in thecreateList
function here.clientHeight
andclientWidth
resolve to 0 for hidden elements, so theList
gets rendered with 0 height and 0 width. The container changing fromhidden
to non-hidden
does not trigger a re-render in the LogViewer, so the List only gets its height and width set correctly whencreateList
is called again after something else triggers a re-render.One possible solution to this would be to add some kind of listener or observer that can detect that the
containerRef.current
element has become visible and have it trigger a re-render similarly to how resizing the window does. This could be done with anIntersectionObserver
as described in this blog post.I was able to reproduce the bug in the docs example here by opening the source of the basic example and editing it to have an additional "hidden" checkbox which defaults to true and applies a hidden attribute on a
<div>
wrapping the LogViewer. I would link a CodeSandbox showing this but it appears the sandbox generator on the site is broken (at least for this example). Adding an IntersectionObserver in the console while reproducing it in this way, I can detect that visibility changing.The text was updated successfully, but these errors were encountered: