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

Styling discrepancies between dev and build #4098

Open
4 tasks done
dasdawidt opened this issue Aug 1, 2024 · 11 comments
Open
4 tasks done

Styling discrepancies between dev and build #4098

dasdawidt opened this issue Aug 1, 2024 · 11 comments
Labels
bug Something isn't working build Related to the build system help wanted Extra attention is needed upstream Related to the dependencies

Comments

@dasdawidt
Copy link

dasdawidt commented Aug 1, 2024

Describe the bug

Just like the Vite docs, I use custom styles in the index.md file using <style module>. I also use custom components in which I use <style scoped>.

Since I updated from version 1.0.0 to the latest one (the one in the StackBlitz), the built page's styles are broken. In the dev preview everything looks like expected.

Reproduction

Open the StackBlitz Demo with this link.

If it does not run automatically, run npm install && npm run dev. It should look something like this:

image

Then run npm run docs:build && npm run docs:preview and it will look like this:

image

As you can see, the hero image and its background are different and the cards are different as well.

Expected behavior

I expected the built version to look just like the dev preview (or at least very close).

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 AMD Ryzen 5 5500U with Radeon Graphics
    Memory: 6.45 GB / 15.35 GB
  Binaries:
    Node: 21.2.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.5.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.1.2 - ~\AppData\Roaming\npm\pnpm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.19041.4355
  npmPackages:
    vitepress: ^1.3.1 => 1.3.1

Additional context

No response

Validations

@dasdawidt dasdawidt added the bug: pending triage Maybe a bug, waiting for confirmation label Aug 1, 2024
@dasdawidt dasdawidt changed the title Styling discrepancies between dev and prod Styling discrepancies between dev and build Aug 1, 2024
@brc-dd brc-dd added bug Something isn't working and removed bug: pending triage Maybe a bug, waiting for confirmation labels Aug 2, 2024
@brc-dd
Copy link
Member

brc-dd commented Aug 2, 2024

Not sure but it's happening on vitepress 1.0.0 too, at least on stackblitz.

@brc-dd
Copy link
Member

brc-dd commented Aug 2, 2024

Most likely caused by this - vitejs/vite#16588 (the order is wrong now - https://www.diffchecker.com/0EPXuHIs/)

Working fine till vite 5.3.0-beta.1

Please use npm/pnpm overrides till this is resolved.

@brc-dd brc-dd added build Related to the build system upstream Related to the dependencies help wanted Extra attention is needed labels Aug 2, 2024
@chenlei0608
Copy link

chenlei0608 commented Aug 7, 2024

same problem, and pages built using GitHub Actions is normal.
how to resolve it? upgrade vite?

@dasdawidt
Copy link
Author

same problem, and pages built using GitHub Actions is normal. how to resolve it? upgrade vite?

As @brc-dd mentioned, it is working fine till vite 5.3.0-beta.1, so you have to downgrade vite to that version by specifying an override in the package.json like this (for npm):

"overrides": {
  "vitepress": {
      "vite": "5.3.0-beta.1"
  }
},

Or like this (for pnpm):

"pnpm": {
  "overrides": {
      "vite": "5.3.0-beta.1"
  }
}

@chenlei0608
Copy link

I will try, thank you

same problem, and pages built using GitHub Actions is normal. how to resolve it? upgrade vite?

As @brc-dd mentioned, it is working fine till vite 5.3.0-beta.1, so you have to downgrade vite to that version by specifying an override in the package.json like this (for npm):

"overrides": {
  "vitepress": {
      "vite": "5.3.0-beta.1"
  }
},

Or like this (for pnpm):

"pnpm": {
  "overrides": {
      "vite": "5.3.0-beta.1"
  }
}

@ZackBz
Copy link

ZackBz commented Aug 11, 2024

I will try, thank you

same problem, and pages built using GitHub Actions is normal. how to resolve it? upgrade vite?

As @brc-dd mentioned, it is working fine till vite 5.3.0-beta.1, so you have to downgrade vite to that version by specifying an override in the package.json like this (for npm):

"overrides": {
  "vitepress": {
      "vite": "5.3.0-beta.1"
  }
},

Or like this (for pnpm):

"pnpm": {
  "overrides": {
      "vite": "5.3.0-beta.1"
  }
}

Did this work for you? I am seeing this issue between dev preview and build preview and pinning vite to 5.3.0-beta.1 didn't work for me. I am using the latest version of vitepress 1.3.2.

I have this in my package.json. I am using Bun

"overrides": {
    "vite": "5.3.0-beta.1"
  }

@dasdawidt
Copy link
Author

@ZackBz according to the bun docs, your solution should work. The one I proposed specifying that the override is for vitepress does not, as bun currently does not support nested overrides. In my case, the pnpm solution worked, maybe try it using npm or pnpm.

@chenlei0608
Copy link

chenlei0608 commented Aug 12, 2024

@ZackBz , it worked, but i am using npm

Snipaste_2024-08-12_19-11-46

@ZackBz
Copy link

ZackBz commented Aug 13, 2024

@ZackBz according to the bun docs, your solution should work. The one I proposed specifying that the override is for vitepress does not, as bun currently does not support nested overrides. In my case, the pnpm solution worked, maybe try it using npm or pnpm.

Odd, I have added the override to my package.json. I ran npm install and then built and previewed the docs and they still look the same as if I was using Bun. I am also using WhyFrame for component isolation so could be something with that as well. I haven't really had time to look deeper into the issue.

@kmindi
Copy link

kmindi commented Sep 24, 2024

Most likely caused by this - vitejs/vite#16588 (the order is wrong now - https://www.diffchecker.com/0EPXuHIs/)

Working fine till vite 5.3.0-beta.1

Please use npm/pnpm overrides till this is resolved.

I also experienced the issue and could narrow it down to the redefined style definitions in index.md, which are done the same way as the style definition in the theme (src/client/theme-default/styles/vars.css), therefore the last defined one in the created style file takes precedence.

You can work around it if you don't do the styling in the markdown files but put the override of the theme styling in your custom.css (where you override the default theme).

Yet I'am curious if this is not a bug in vite now, because you cannot override with style definitions in the markdown files now anymore, except if this is only related to some names used for the files and the order can be influenced...

@yangmingshan
Copy link

This problem is caused by CSS order, so !important can save you.

:root {
  --vp-home-hero-name-color: transparent !important;
  --vp-home-hero-name-background: -webkit-linear-gradient(315deg, #42d392 25%, #647eff) !important;
  --vp-home-hero-image-background-image: linear-gradient(0deg, #42d39280 50%, #34485e80) !important;
  --vp-home-hero-image-filter: blur(40px) !important;
}

@media (min-width: 640px) {
  :root {
    --vp-home-hero-image-filter: blur(56px) !important;
  }
}

@media (min-width: 960px) {
  :root {
    --vp-home-hero-image-filter: blur(72px) !important;
  }
}

bbcvc added a commit to bbcvc/notes that referenced this issue Nov 15, 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 build Related to the build system help wanted Extra attention is needed upstream Related to the dependencies
Projects
None yet
Development

No branches or pull requests

6 participants