Skip to content

fix(ui): prevent double vertical scrollbars in latex math rendering#2967

Open
Siddhu2k04 wants to merge 1 commit into
Chainlit:mainfrom
Siddhu2k04:fix/2949-latex-double-scrollbar
Open

fix(ui): prevent double vertical scrollbars in latex math rendering#2967
Siddhu2k04 wants to merge 1 commit into
Chainlit:mainfrom
Siddhu2k04:fix/2949-latex-double-scrollbar

Conversation

@Siddhu2k04

@Siddhu2k04 Siddhu2k04 commented Jun 19, 2026

Copy link
Copy Markdown

Fix duplicate vertical scrollbar when LaTeX rendering is enabled

Summary

This PR fixes an issue where enabling latex=true in config.toml could cause two vertical scrollbars to appear in the chat UI when rendering LaTeX content.

Root Cause

The chat interface already provides a scrollable container for messages. When LaTeX content is rendered, the math wrapper may introduce additional overflow behavior, creating a nested scroll container and resulting in duplicate vertical scrollbars.

Changes

  • Removed unnecessary vertical overflow handling from LaTeX rendering containers.

  • Restricted LaTeX elements to horizontal scrolling only when needed.

  • Ensured the main chat container remains the sole vertical scroll region.

  • Preserved existing LaTeX rendering behavior and layout.

Before

  • latex=true enabled.

  • Sending multiple messages containing LaTeX equations eventually displays two vertical scrollbars.

After

  • Only one vertical scrollbar is displayed.

  • LaTeX equations render correctly.

  • Normal chat scrolling behavior remains unchanged.

Testing

Reproduction Steps

  1. Enable latex=true in config.toml.

  2. Run the following application:

import chainlit as cl

@cl.on_message
async def main(message: cl.Message):
await cl.Message(
content="Here is the quadratic formula:\n$$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$$"
).send()

  1. Start Chainlit.

  2. Send messages multiple times until the chat becomes scrollable.

Results

Scenario Result
Before Fix Two vertical scrollbars appear
After Fix Only one vertical scrollbar appears
WhatsApp Image 2026-06-19 at 7 42 58 AM

References

Co-Authored-By: Antigravity <noreply@google.com>
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working frontend Pertains to the frontend. labels Jun 19, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 1 file

Re-trigger cubic

@Siddhu2k04

Copy link
Copy Markdown
Author

Hi @asvishnyakov and @sandangel,

I've submitted a fix for #2949 and verified that it resolves the duplicate vertical scrollbar issue when LaTeX rendering is enabled.

Could you please review the PR when you have a chance? Any feedback is appreciated.

Thanks! 🚀

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 14 days with no activity.

@github-actions github-actions Bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Jul 4, 2026
@tjroamer

tjroamer commented Jul 8, 2026

Copy link
Copy Markdown

Please someone to merge this PR? We need this issue to be fixed in the production. Thanks in advance.

@github-actions github-actions Bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Jul 9, 2026
@tmueller-hsetu

Copy link
Copy Markdown

The CSS approach in this PR (setting overflow-y: hidden on .katex, .katex-display etc.) did not resolve the issue in our case.

After digging into frontend/src/components/chat/ScrollContainer.tsx, we found the actual root cause: the outer wrapper <div> at line 196 has overflow-y-auto even though it only exists to position the scroll-to-bottom button (absolute). When LaTeX content is rendered and the inner scroll div grows, both divs trigger their own scrollbar simultaneously.

The fix that worked for us was changing the outer wrapper from overflow-y-auto to overflow-hidden in ScrollContainer.tsx:

// frontend/src/components/chat/ScrollContainer.tsx, line 196

// Before
<div className="relative flex flex-col flex-grow overflow-y-auto">

// After
<div className="relative flex flex-col flex-grow overflow-hidden">

This makes the inner <div ref={ref} ... overflow-y-auto> the sole scrollable container, which is the intended behavior. The scroll-to-bottom button positioning is unaffected since it uses absolute.

Since we couldn't patch the source directly, we applied this as a JS workaround via MutationObserver:

document.querySelectorAll('div.relative.flex-grow.overflow-y-auto').forEach(wrapper => {
    if (wrapper.querySelector(':scope > div.overflow-y-auto')) {
        wrapper.style.overflowY = 'hidden';
    }
});

Would suggest updating this PR to target ScrollContainer.tsx instead of the KaTeX elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working frontend Pertains to the frontend. size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UI displays two vertical scrollbars with enabled latex rendering

3 participants