Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The style of the header jitters every time the page is refreshed. #4351

Open
4 tasks done
lzdyes opened this issue Nov 10, 2024 · 0 comments
Open
4 tasks done

The style of the header jitters every time the page is refreshed. #4351

lzdyes opened this issue Nov 10, 2024 · 0 comments
Labels
bug Something isn't working theme Related to the theme

Comments

@lzdyes
Copy link

lzdyes commented Nov 10, 2024

Describe the bug

Version: 1.5.0

Built with the latest VitePress version, using the default theme. After the build build is released, the style at the top of the page will shake every time you refresh it, affecting the experience.

Debugging revealed that the issue is caused by a mismatch between the initial styles in the generated HTML file and the styles after subsequent client-side rendering.

After client rendering:

image

Disable JavaScript in your browser:

image

Reproduction

I checked the source code and found that it’s likely caused by the watchPostEffect in VPNavBar.vue.

const classes = ref<Record<string, boolean>>({})

watchPostEffect(() => {
  classes.value = {
    'has-sidebar': hasSidebar.value,
    'home': frontmatter.value.layout === 'home',
    'top': y.value === 0,
    'screen-open': props.isScreenOpen
  }
})

This causes the has-sidebar class to be missing from the header in the initially generated HTML.

In contrast, VPContent.vue has normal initial rendering in the HTML.

  <div
    class="VPContent"
    id="VPContent"
    :class="{
      'has-sidebar': hasSidebar,
      'is-home': frontmatter.layout === 'home'
    }"
  >
image

Expected behavior

You want the header style not to shake when you refresh

System Info

System:
    OS: macOS 14.7
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 21.70 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
  Browsers:
    Brave Browser: 130.1.71.121
    Chrome: 130.0.6723.117
    Safari: 18.0.1
  npmPackages:
    vitepress: ^1.5.0 => 1.5.0

Additional context

No response

Validations

@lzdyes lzdyes added the bug: pending triage Maybe a bug, waiting for confirmation label Nov 10, 2024
@lzdyes lzdyes changed the title The style of the top navigation bar jitters every time the page is refreshed. The style of the header jitters every time the page is refreshed. Nov 10, 2024
@brc-dd brc-dd added bug Something isn't working theme Related to the theme and removed bug: pending triage Maybe a bug, waiting for confirmation labels Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working theme Related to the theme
Projects
None yet
Development

No branches or pull requests

2 participants