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

Trigger update when container resizes #28

Open
wants to merge 1 commit into
base: v5
Choose a base branch
from

Conversation

mmuzikar
Copy link

@mmuzikar mmuzikar commented May 9, 2023

The containerRef didn't trigger any update on resize, which caused the log viewer to update only on scroll:
Peek 2023-05-09 09-55.webm

Now the component updates when the container resizes:
Peek 2023-05-09 13-57

if (containerRef && containerRef.current) {
window.addEventListener('resize', callbackResize);
observer = new ResizeObserver((event) => {
setEmptyState({});
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried calling callbackResize here put it interfered with scrolling behavior (resize is called even for scrolling).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[curious-question]: Are we using setEmptyState as a way to rerender the component, could be possible to use setLoading(false) as well? would that work?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setLoading(false): Same behavior as before the fix
setLoading(true) or setResizing(true): the log container is empty

Comment on lines +181 to +186
if (!(containerRef && containerRef.current)) {
return;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To prevent manipulation of DOM when the timer callback happens after the container was closed.

@mturley
Copy link

mturley commented Jan 11, 2024

This seems related to #55

if (containerRef && containerRef.current) {
window.addEventListener('resize', callbackResize);
observer = new ResizeObserver((event) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you check the event type here @mmuzikar? if event.type === 'scroll' then we don't do the callbackResize, otherwise we could use callbackResize.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the event in the ResizeObserver? Because there is no type there. Or is this comment meant for the line above?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I mean the event here, sorry I thought this is an HTML DOM event here.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaoDaoNoCode I took another look at this and realized Drawer has an onResize callback. I wonder if somehow you could come at it from that angle instead, and somehow trigger the LogViewer to recalculate its layout imperatively when the drawer is resized. It would of course be nice to have a general solution where the LogViewer handles this itself, but perhaps that would be less hacky? I'm not sure how you would trigger it from outside the LogViewer, just a thought.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaoDaoNoCode I took another look at this and realized Drawer has an onResize callback. I wonder if somehow you could come at it from that angle instead, and somehow trigger the LogViewer to recalculate its layout imperatively when the drawer is resized. It would of course be nice to have a general solution where the LogViewer handles this itself, but perhaps that would be less hacky? I'm not sure how you would trigger it from outside the LogViewer, just a thought.

@mturley I tried using onResize callback on drawer in this PR: opendatahub-io/odh-dashboard#2184
Discussion : opendatahub-io/odh-dashboard#2184 (comment)
But it didn't work as expected. onResize it was not recalcualting the lineHeight. Line height recalculation was happening when the window resizes.

GIF:
Screencast from 2023-11-20 17-55-51.webm

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated my PR with the changes you requested, I am not sure I'm following the conversation as I am no React expert, if you have a better idea on how to fix this issue, I can close this and let you do it the right way :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants