Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 19, 2025

Fixes the page jitter/shake issue when the search modal opens by compensating for the scrollbar width, following the same approach as VitePress.

Problem

When the search modal opens, hiding the body scrollbar caused the page content to shift to the right, creating a jarring visual effect.

Solution

Instead of adding a configuration option, this implements the standard fix by:

  1. Calculating the scrollbar width: window.innerWidth - document.documentElement.clientWidth
  2. Adding padding-right equal to the scrollbar width when hiding body overflow
  3. Removing the padding when restoring overflow

This ensures the page content stays in the exact same position when the modal opens and closes.

Changes Made

  • Modified search-modal.ts willUpdate method to calculate and apply padding compensation
  • Updated demo page (index.html) to demonstrate the fix with scrollable content
  • No configuration needed - works automatically for all users
  • No breaking changes

Visual Proof

Before opening modal (with scrollbar):
Before

After opening modal (no layout shift):
After

The page content stays perfectly aligned - no jitter or shift!

Testing

  • ✅ Build passes successfully
  • ✅ Linting passes
  • ✅ Security scan passed (0 alerts)
  • ✅ Visual verification confirms no layout shift

Fixes #62

Original prompt

This section details on the original issue you should resolve

<issue_title>搜索组件导致页面抖动问题</issue_title>
<issue_description>Image

页面滚动条隐藏导致整体页面内容右移:

Image

参考 vitepress 实例,搜索组件显示不会导致页面滚动条隐藏:

Image

希望提供配置项,决定是否隐藏滚动条,谢谢❤。
</issue_description>

Comments on the Issue (you are @copilot in this section)

@ruibaby /kind improvement

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

减少当搜索框打开时,网页整体的抖动问题

@f2c-ci-robot f2c-ci-robot bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Nov 19, 2025
@ruibaby
Copy link
Member

ruibaby commented Nov 20, 2025

@copilot I don’t think it’s necessary to add a parameter to control lockScroll. Could we instead address the offset issue caused by hiding the body scrollbar when the search modal is open?

Copy link
Contributor Author

Copilot AI commented Nov 20, 2025

@copilot I don’t think it’s necessary to add a parameter to control lockScroll. Could we instead address the offset issue caused by hiding the body scrollbar when the search modal is open?

You're absolutely right! I've removed the lockScroll configuration parameter and implemented a proper fix that addresses the offset issue directly.

The solution calculates the scrollbar width and adds equivalent padding to the body when hiding overflow, preventing any layout shift. This is the standard approach used by VitePress and other modern UI libraries.

Changes in commit 1cadad6:

  • Calculate scrollbar width: window.innerWidth - document.documentElement.clientWidth
  • Add padding-right equal to scrollbar width when modal opens
  • Remove padding when modal closes

Visual proof:
Before (with scrollbar): https://github.com/user-attachments/assets/08830eed-5046-486a-aa59-0cad4f04ca5c
After (no shift): https://github.com/user-attachments/assets/1873d6c0-10d4-498a-9794-bef44963dc1e

The page content now stays perfectly aligned with no jitter!

Copilot AI changed the title [WIP] Fix page shaking issue caused by search component Fix page jitter by compensating for scrollbar width Nov 20, 2025
@ruibaby ruibaby marked this pull request as ready for review November 20, 2025 03:23
@f2c-ci-robot f2c-ci-robot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Nov 20, 2025
Copy link
Member

@ruibaby ruibaby left a comment

Choose a reason for hiding this comment

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

/lgtm

@f2c-ci-robot f2c-ci-robot bot added the lgtm Indicates that a PR is ready to be merged. label Nov 20, 2025
@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Nov 20, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ruibaby

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 20, 2025
@f2c-ci-robot f2c-ci-robot bot merged commit 104a972 into main Nov 20, 2025
3 checks passed
@ruibaby ruibaby deleted the copilot/fix-page-shaking-issue branch November 20, 2025 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

搜索组件导致页面抖动问题

2 participants