Skip to content

Commit 557f797

Browse files
authored
docs: dark mode not applied properly in landing page (vitejs#20492)
1 parent 68c5a82 commit 557f797

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

docs/.vitepress/theme/styles/landing.css

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,11 @@
44

55
html:has(.landing) {
66
--vp-c-bg: #101010;
7-
87
background-color: #101010;
9-
10-
body {
11-
background-color: #101010;
12-
}
138
}
149

1510
.landing {
1611
overflow-x: hidden;
17-
background-color: #101010;
1812

1913
* {
2014
-webkit-font-smoothing: antialiased !important;

docs/index.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
title: Vite
33
titleTemplate: Next Generation Frontend Tooling
4+
# add `dark` here to apply dark mode on initial load,
5+
# since `onMounted` doesn't run during SSR
46
pageClass: landing dark
57

68
layout: home
@@ -10,6 +12,9 @@ markdownStyles: false
1012
---
1113

1214
<script setup>
15+
import { useData } from 'vitepress'
16+
import { onBeforeUnmount, onMounted, ref } from 'vue'
17+
1318
import Hero from '.vitepress/theme/components/landing/1. hero-section/HeroSection.vue'
1419
import FeatureSection from './.vitepress/theme/components/landing/2. feature-section/FeatureSection.vue'
1520
import FrameworksSection from './.vitepress/theme/components/landing/3. frameworks-section/FrameworksSection.vue'
@@ -24,6 +29,16 @@ import FeatureFlexiblePlugins from './.vitepress/theme/components/landing/2. fea
2429
import FeatureTypedAPI from './.vitepress/theme/components/landing/2. feature-section/FeatureTypedAPI.vue'
2530
import FeatureSSRSupport from './.vitepress/theme/components/landing/2. feature-section/FeatureSSRSupport.vue'
2631
import FeatureCI from './.vitepress/theme/components/landing/2. feature-section/FeatureCI.vue'
32+
33+
const { isDark } = useData()
34+
35+
onMounted(() => {
36+
document.documentElement.classList.add('dark')
37+
})
38+
39+
onBeforeUnmount(() => {
40+
document.documentElement.classList.toggle('dark', isDark.value)
41+
})
2742
</script>
2843

2944
<div class="VPHome">

pnpm-workspace.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ patchedDependencies:
2020
peerDependencyRules:
2121
allowedVersions:
2222
vite: "*"
23-
ignoreMissing:
24-
- "@algolia/client-search"
25-
- "postcss"
26-
- "search-insights"
2723
packageExtensions:
2824
sass-embedded:
2925
peerDependencies:

0 commit comments

Comments
 (0)