Skip to content

fix(code-block): use absolute positioning for action buttons to fix clicks in nested scroll containers#498

Open
sleitor wants to merge 2 commits into
vercel:mainfrom
sleitor:fix-494
Open

fix(code-block): use absolute positioning for action buttons to fix clicks in nested scroll containers#498
sleitor wants to merge 2 commits into
vercel:mainfrom
sleitor:fix-494

Conversation

@sleitor
Copy link
Copy Markdown
Contributor

@sleitor sleitor commented Apr 4, 2026

Problem

When streamdown is embedded in a layout with two or more nested scroll containers (e.g., an outer overflow-auto sidebar + an inner overflow-auto chat scroll area), the code block copy/download buttons are visible but unclickable.

The root cause: the sticky + pointer-events-none/auto pattern for the action button wrapper causes browser hit-testing to resolve clicks to the code block container div instead of reaching the buttons when there are multiple overflow: auto ancestors.

Fixes #494

Solution

  • Switch the action button wrapper from position: sticky to position: absolute with top-2 right-2
  • Add position: relative to the CodeBlockContainer so absolute positioning is scoped to the code block

This makes buttons reliably clickable in all scroll-container configurations.

Trade-off: Buttons no longer scroll with long code blocks (they stay fixed at the top-right of the code block). This is the same behavior as the workaround documented in the issue, and arguably cleaner UX — the buttons are always visible and always reachable.

Changes

  • packages/streamdown/lib/code-block/container.tsx: add relative class
  • packages/streamdown/lib/code-block/index.tsx: change outer wrapper from pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end to pointer-events-none absolute top-2 right-2 z-10 flex items-center
  • .changeset/fix-code-block-buttons-absolute.md: patch changeset

Testing

All 982 existing tests pass (pnpm --filter streamdown test). Biome check clean.

…lick events in nested scroll containers

Switches the code block action button wrapper from position:sticky to
position:absolute (with position:relative on the container) so that
hit-testing works correctly in layouts with multiple nested overflow:auto
scroll containers.

Previously, the sticky + pointer-events-none/auto pattern caused browsers
to mis-route click events to the code block wrapper rather than the copy/
download buttons when embedded in 2+ nested scroll containers.

Closes vercel#494
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 4, 2026

@sleitor is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

@vercel vercel Bot left a comment

Choose a reason for hiding this comment

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

Additional Suggestion:

Mermaid block action buttons use sticky positioning that causes click event issues in nested scroll containers, identical to the bug fixed in code blocks.

Fix on Vercel

@manjujidagi
Copy link
Copy Markdown

@sleitor Can you update the vercel (bot) suggested changes, as 'mermaid' also has similar issue

…ks in nested scroll containers

Same fix as code-block (ab0a5ae): switches the mermaid block action button
wrapper from position:sticky to position:absolute so that hit-testing works
correctly in layouts with multiple nested overflow:auto scroll containers.

The mermaid block container already has position:relative, so only the
inner toolbar wrapper needed updating.

Fixes vercel#494
@sleitor
Copy link
Copy Markdown
Contributor Author

sleitor commented May 4, 2026

@manjujidagi Good catch! The Mermaid block action buttons (download/copy/fullscreen toolbar) had the same sticky positioning issue. Extended the fix in commit afbcf11 — changed the toolbar wrapper from sticky top-2 -mt-10 to absolute top-2 right-2 (the mermaid block container already has position:relative).

@manjujidagi
Copy link
Copy Markdown

@sleitor When do you think this will be merged ? I am waiting for this update

@sleitor
Copy link
Copy Markdown
Contributor Author

sleitor commented May 5, 2026

@manjujidagi The fix is ready — the remaining blocker is Vercel team authorization for the deployment preview (the standard bot checkpoint for external contributors). Merge timeline is up to the Vercel/streamdown maintainers, but I'll continue to follow up with them. Thanks for your patience!

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.

Code block copy/download buttons unclickable in nested scroll containers (sticky + pointer-events-none)

2 participants