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

fix(codeblock): fix height of codeblock to use DOM recycling scrolling #3711

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

johncowen
Copy link
Contributor

@johncowen johncowen commented Mar 27, 2025

Also see #3152, specifically #3152 (comment)


Looks like the line numbers we render here can cause a massive slowdown in re-renders, specifically when typing to search large configs.

The upstream KCodeBlock that we use for this does have a virtual scroller for the line numbers built in, but because of the nature of some virtual scrollers, and definitely in this case, you need to fix the height of the container of the thing that contains the virtual scroller. This means that the KCodeBlock now controls the scrolling, not the browser window.

Note: I only implemented this in the "full page" XDS Config pages for now, so if you are viewing the PR preview make sure you are looking at it on this page.

Signed-off-by: John Cowen <john.cowen@konghq.com>
Copy link

netlify bot commented Mar 27, 2025

Deploy Preview for kuma-gui ready!

Name Link
🔨 Latest commit d4d5e1e
🔍 Latest deploy log https://app.netlify.com/sites/kuma-gui/deploys/67e686d72d23c200080ee3af
😎 Deploy Preview https://deploy-preview-3711--kuma-gui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@click="refresh"
<div
ref="$el"
>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bit annoyed about this, the return of meaningless divs.

It seems in order to use a ref to get a reference deep in your component tree (in this case *View.vue > XCodeBlock > XLayout), you have to do a load of defineExpose plumbing, which is just going to be brittle and hard to maintain, and at the very least annoying to have to use so much code to get to a deep DOM element.

Instead I just figured I could just wrap the thing in an extra div and get the position of the extra div instead (we need the .top of the XCodeBlock to calculate the height it should be)

ref="$el"
>
<XCodeBlock
:max-height="`${(resize?.target?.innerHeight ?? 0) - ($el?.getBoundingClientRect().top + 146)}`"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally we don't want to hardcode this number, but at the moment it's not obvious how to calculate this exactly, I suspect KCodeBlock's maxHeight doesn't take into account its toolbar.

All in all in order to move forwards, I'd be happy with this magical number for the moment at least. Take into account we'll need to do this in three pages, XDS Config, Stats and Clusters.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to define a min-height also?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 I think from a UX perspective that would potentially result in 2 scrollbars (one on the codeblock one on the window), which I reckon we should avoid

Technically, notice we the max-height is a "feature" of the underlying KCodeBlock, so if we'd want to add a min-height we'd have to add some custom CSS, which in some cases I'd be fine with but considering the above UX point also, I'd definitely be on the side of not adding extra bits.

Copy link
Contributor

@schogges schogges Mar 28, 2025

Choose a reason for hiding this comment

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

Hmmm, in my case I already see two scrollbars (not sure what is causing this). But I don't think that is bad in general. In case there is more stuff added to that view, we need to have another scrollbar. So regardless of the scrollbars I think it would be best to give it a range in which in can grow to improve performance and usability 🤔

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I increased the "magic" number to 200, hopefully you only get one scrollbar now. This is why I'd rather it be calculated, but still I'd be happy with a magic number at least short term. The 2 scrollbars (if they should ever happen) are less bad than a slow search.

Copy link
Contributor

Choose a reason for hiding this comment

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

I increased the "magic" number to 200, hopefully you only get one scrollbar now. This is why I'd rather it be calculated, but still I'd be happy with a magic number at least short term. The 2 scrollbars (if they should ever happen) are less bad than a slow search.

The second scrollbar is gone 🙂
Yeah that "magic" number is not ideal, but should be fine for now. Unfortunately it's not that easy to just let it grow to fill the rest of the screen, at least from my quick fiddling around 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that "magic" number is not ideal, but should be fine for now. Unfortunately it's not that easy to just let it grow to fill the rest of the screen, at least from my quick fiddling around

Yeah for sure, I couldn't find a calculation that was always correct, I'm happy to go with this for now also. Let me roll it out to the other pages, 🤔 we could make an issue for this maybe, brb

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file wraps over GlobalEvents (a 3rd party package I added):

  1. In case we ever want to move, or roll our own.
  2. Maintains our "x is for GUI related compoennts"
  3. Means we can tailor it to our needs, currently we only support window resize events. If we need more we can add them incrementally as and when we need them here.

@johncowen johncowen changed the title fix(codeblock): fix height of codeblock to use dom recycling scrolling fix(codeblock): fix height of codeblock to use DOM recycling scrolling Mar 27, 2025
@johncowen
Copy link
Contributor Author

Taking this out of draft so its clear we are all happy with the approach, there is still work required before we merge, but for the moment we just need to make sure we are all happy with the general approach

@johncowen johncowen marked this pull request as ready for review March 27, 2025 19:58
@johncowen johncowen requested a review from a team as a code owner March 27, 2025 19:58
@johncowen johncowen requested a review from schogges March 27, 2025 19:58
Signed-off-by: John Cowen <john.cowen@konghq.com>
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.

2 participants