Skip to content

Replace Radix UI dialog overlay with custom overlay to fix layout shift in VSCode webview#24

Merged
kubrickcode merged 1 commit intomainfrom
fix-dialog-overlay-padding
Sep 20, 2025
Merged

Replace Radix UI dialog overlay with custom overlay to fix layout shift in VSCode webview#24
kubrickcode merged 1 commit intomainfrom
fix-dialog-overlay-padding

Conversation

@kubrickcode
Copy link
Owner

  • Replace DialogPrimitive.Overlay with simple div using absolute positioning
  • Add manual scroll lock with body.dialog-open class
  • Fix background padding changes when dialog opens in VSCode environment

issue #23

…ft in VSCode webview

  - Replace DialogPrimitive.Overlay with simple div using absolute positioning
  - Add manual scroll lock with body.dialog-open class
  - Fix background padding changes when dialog opens in VSCode environment

issue #23
@kubrickcode kubrickcode self-assigned this Sep 20, 2025
@gemini-code-assist
Copy link

Summary of Changes

Hello @kubrickcode, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request aims to resolve an annoying layout shift issue experienced in the VSCode webview when dialogs are opened. The solution involves replacing the default Radix UI dialog overlay with a custom-built one, which allows for precise control over its positioning and behavior. Additionally, a manual scroll lock mechanism has been introduced to prevent background content from shifting or scrolling when a dialog is active, ensuring a smoother user experience.

Highlights

  • Custom Dialog Overlay: Replaced the DialogPrimitive.Overlay component from Radix UI with a custom div element to gain more control over its behavior and styling.
  • Manual Scroll Lock: Implemented a manual scroll lock mechanism by adding and removing a dialog-open class to the document.body, which then applies overflow: hidden via CSS.
  • VSCode Webview Layout Fix: Addressed and resolved the issue of background padding changes and layout shifts that occurred when dialogs were opened within the VSCode webview environment.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@kubrickcode
Copy link
Owner Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request replaces the Radix UI dialog overlay with a custom implementation to fix a layout shift issue in VSCode webviews. The changes include a new CustomOverlay React component that manually manages body scroll-locking via a CSS class, and a corresponding CSS rule. My review focuses on improving the robustness of the scroll-locking mechanism to handle multiple dialogs and on CSS best practices. Overall, this is a good solution to the problem described.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request replaces the Radix UI dialog overlay with a custom implementation to resolve a layout shift issue within VSCode webviews. The changes involve creating a new CustomOverlay component that manually manages a dialog-open class on the <body> to lock scrolling, and updating the CSS to apply overflow: hidden. The approach is sound, but I have a couple of suggestions to improve the robustness and maintainability of the implementation.

Comment on lines +51 to +57
React.useEffect(() => {
document.body.classList.add('dialog-open');

return () => {
document.body.classList.remove('dialog-open');
};
}, []);

Choose a reason for hiding this comment

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

high

The current implementation for scroll locking by toggling the dialog-open class on document.body is not robust against multiple dialogs being open concurrently. If two dialogs are open and one is closed, it will remove the dialog-open class, re-enabling scrolling while the second dialog is still open.

To fix this, you would need to track the number of active dialogs. A common approach is to use a module-level counter that is incremented when a dialog mounts and decremented when it unmounts. The class on <body> would only be added when the counter goes from 0 to 1, and removed when it goes from 1 to 0.

If the application design guarantees that only one dialog can be open at any time, the current approach is acceptable, but it would be good practice to add a comment to the useEffect hook to clarify this assumption for future maintainability.

Comment on lines +125 to +127
body.dialog-open {
overflow: hidden !important;
}

Choose a reason for hiding this comment

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

medium

Using !important is generally discouraged as it can make styles harder to manage and override later, because it breaks the natural CSS cascade. While it might be necessary in this case to override styles injected by the VSCode webview environment, it's important to document why it's being used. Please add a comment explaining the necessity of !important here.

body.dialog-open {
  /* Using !important is necessary to override VSCode webview styles and prevent layout shift. */
  overflow: hidden !important;
}

@kubrickcode kubrickcode merged commit ad66b98 into main Sep 20, 2025
2 checks passed
@kubrickcode kubrickcode deleted the fix-dialog-overlay-padding branch October 6, 2025 08:42
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.

1 participant