Skip to content

fix(Modal): use percentage sizing to prevent scrollbar flash#744

Merged
huyenltnguyen merged 2 commits intofreeCodeCamp:mainfrom
garyeung:fix-scrollbar
Feb 8, 2026
Merged

fix(Modal): use percentage sizing to prevent scrollbar flash#744
huyenltnguyen merged 2 commits intofreeCodeCamp:mainfrom
garyeung:fix-scrollbar

Conversation

@garyeung
Copy link
Contributor

@garyeung garyeung commented Feb 8, 2026

Checklist:

Closes #743

@garyeung garyeung requested a review from a team as a code owner February 8, 2026 01:27
Copy link
Member

@huyenltnguyen huyenltnguyen left a comment

Choose a reason for hiding this comment

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

Please provide more context on the issue and the fix, specifically the root cause and how the changes address it.

@huyenltnguyen huyenltnguyen added the status: waiting update To be applied to PR if a maintainer/reviewer has left a feedback and follow up is needed from OP label Feb 8, 2026
Copy link
Member

@huyenltnguyen huyenltnguyen left a comment

Choose a reason for hiding this comment

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

For posterity, the root cause is:

The container has:

position: fixed;
inset: 0;
overflow: scroll;

The Dialog (child of container) has:

width: 100vw;
height: 100vh;

The conflict:

  • Container with overflow: scroll reserves space for scrollbars
  • Dialog is sized at 100vw × 100vh = full viewport, meaning Dialog is larger than the container's available content area
  • This creates overflow in both directions

During the close transition, there's a rendering frame where:

  • The modal is transitioning out
  • The container still has overflow: scroll enforced, while overflow: hidden set to the body is lifted (set by Headless UI, to enable body scroll lock)
  • The Dialog at 100vw × 100vh overflows the container's content box
  • The scrollbars become visible on the container element
  • When the modal completely fades out, these scrollbars disappear with it

This does not seem happen on modal open. It's probably because the transition happens quickly and body scroll lock is applied immediately, so there's no visual frame where the overflow scrollbars are noticeable.


The fix is to change Dialog's width and height to full, so it now sizes to 100% of container, not 100% of viewport.

{/* Full-screen container of the panel */}
<div
className={`fixed inset-0 flex items-start justify-center p-[10px] md:pt-[30px] md:pb-[30px] overflow-scroll`}
className={`fixed inset-0 flex items-start justify-center p-[10px] md:pt-[30px] md:pb-[30px] overflow-hidden`}
Copy link
Member

Choose a reason for hiding this comment

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

The overflow property should at least be auto. Otherwise, the content will get cut off if it's taller than the container.

@huyenltnguyen huyenltnguyen changed the title fix(ui): hide scrollbar for Modal fix(Modal): use percentage sizing to prevent scrollbar flash Feb 8, 2026
@huyenltnguyen huyenltnguyen merged commit 5ff3e00 into freeCodeCamp:main Feb 8, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting update To be applied to PR if a maintainer/reviewer has left a feedback and follow up is needed from OP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Modal causes scrollbar "flash" and layout shift on close in Chrome

2 participants