Skip to content

Commit 3e85b46

Browse files
committed
refactor: improve css treeshaking + avoid layout shift on async components
1 parent b9c9e79 commit 3e85b46

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

src/client/app/mixin.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { App } from 'vue'
1+
import { App, defineAsyncComponent } from 'vue'
22
import { joinPath } from './utils'
33
import { SiteDataRef } from './composables/siteData'
44
import { PageDataRef } from './composables/pageData'
55
import { Content } from './components/Content'
6-
import Debug from './components/Debug.vue'
76
import { ClientOnly } from './components/ClientOnly'
87

98
export function mixinGlobalComputed(
@@ -70,5 +69,10 @@ export function mixinGlobalComponents(app: App) {
7069

7170
app.component('Content', Content)
7271
app.component('ClientOnly', ClientOnly)
73-
app.component('Debug', isProd ? () => null : Debug)
72+
app.component(
73+
'Debug',
74+
isProd
75+
? () => null
76+
: defineAsyncComponent(() => import('./components/Debug.vue'))
77+
)
7478
}

src/client/theme-default/Layout.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import type { DefaultTheme } from './config'
7676
import NavBar from './components/NavBar.vue'
7777
import SideBar from './components/SideBar.vue'
7878
import Page from './components/Page.vue'
79+
7980
const Home = defineAsyncComponent(() => import('./components/Home.vue'))
8081
8182
const NoopComponent = () => null

src/client/theme-default/components/AlgoliaSearchBox.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ function initialize(userOptions: any) {
139139
@media (min-width: 720px) {
140140
.algolia-search-box {
141141
padding-left: 8px;
142+
min-width: 176.3px; /* avoid layout shift */
142143
}
143144
}
144145

src/client/theme-default/components/CarbonAds.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ onMounted(() => {
2828
max-width: 280px;
2929
font-size: .75rem;
3030
background-color: rgba(255, 255, 255, .8);
31+
min-height: 105.38px; /* avoid layout shift on mobile */
3132
}
3233
3334
.carbon-ads::after {
@@ -46,6 +47,7 @@ onMounted(() => {
4647
padding: 8px;
4748
width: 146px;
4849
max-width: 100%;
50+
min-height: 200px;
4951
}
5052
}
5153
@@ -60,40 +62,40 @@ onMounted(() => {
6062
}
6163
}
6264
63-
.carbon-ads ::v-deep(.carbon-img) {
65+
.carbon-ads :deep(.carbon-img) {
6466
float: left;
6567
margin-right: .75rem;
6668
max-width: 100px;
6769
border: 1px solid var(--c-divider);
6870
}
6971
7072
@media (min-width: 420px) {
71-
.carbon-ads ::v-deep(.carbon-img) {
73+
.carbon-ads :deep(.carbon-img) {
7274
float: none;
7375
display: block;
7476
margin-right: 0;
7577
max-width: 130px;
7678
}
7779
}
7880
79-
.carbon-ads ::v-deep(.carbon-img img) {
81+
.carbon-ads :deep(.carbon-img img) {
8082
display: block;
8183
width: 100%;
8284
}
8385
8486
@media (min-width: 420px) {
85-
.carbon-ads ::v-deep(.carbon-text) {
87+
.carbon-ads :deep(.carbon-text) {
8688
padding-top: 8px;
8789
}
8890
}
8991
90-
.carbon-ads ::v-deep(.carbon-text) {
92+
.carbon-ads :deep(.carbon-text) {
9193
display: block;
9294
font-weight: 400;
9395
color: var(--c-text-light);
9496
}
9597
96-
.carbon-ads ::v-deep(.carbon-poweredby) {
98+
.carbon-ads :deep(.carbon-poweredby) {
9799
display: block;
98100
padding-top: 2px;
99101
font-weight: 400;

0 commit comments

Comments
 (0)