Skip to content

Commit

Permalink
refactor: improve css treeshaking + avoid layout shift on async compo…
Browse files Browse the repository at this point in the history
…nents
  • Loading branch information
yyx990803 committed Dec 30, 2020
1 parent b9c9e79 commit 3e85b46
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/client/app/mixin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { App } from 'vue'
import { App, defineAsyncComponent } from 'vue'
import { joinPath } from './utils'
import { SiteDataRef } from './composables/siteData'
import { PageDataRef } from './composables/pageData'
import { Content } from './components/Content'
import Debug from './components/Debug.vue'
import { ClientOnly } from './components/ClientOnly'

export function mixinGlobalComputed(
Expand Down Expand Up @@ -70,5 +69,10 @@ export function mixinGlobalComponents(app: App) {

app.component('Content', Content)
app.component('ClientOnly', ClientOnly)
app.component('Debug', isProd ? () => null : Debug)
app.component(
'Debug',
isProd
? () => null
: defineAsyncComponent(() => import('./components/Debug.vue'))
)
}
1 change: 1 addition & 0 deletions src/client/theme-default/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import type { DefaultTheme } from './config'
import NavBar from './components/NavBar.vue'
import SideBar from './components/SideBar.vue'
import Page from './components/Page.vue'
const Home = defineAsyncComponent(() => import('./components/Home.vue'))
const NoopComponent = () => null
Expand Down
1 change: 1 addition & 0 deletions src/client/theme-default/components/AlgoliaSearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ function initialize(userOptions: any) {
@media (min-width: 720px) {
.algolia-search-box {
padding-left: 8px;
min-width: 176.3px; /* avoid layout shift */
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/client/theme-default/components/CarbonAds.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ onMounted(() => {
max-width: 280px;
font-size: .75rem;
background-color: rgba(255, 255, 255, .8);
min-height: 105.38px; /* avoid layout shift on mobile */
}
.carbon-ads::after {
Expand All @@ -46,6 +47,7 @@ onMounted(() => {
padding: 8px;
width: 146px;
max-width: 100%;
min-height: 200px;
}
}
Expand All @@ -60,40 +62,40 @@ onMounted(() => {
}
}
.carbon-ads ::v-deep(.carbon-img) {
.carbon-ads :deep(.carbon-img) {
float: left;
margin-right: .75rem;
max-width: 100px;
border: 1px solid var(--c-divider);
}
@media (min-width: 420px) {
.carbon-ads ::v-deep(.carbon-img) {
.carbon-ads :deep(.carbon-img) {
float: none;
display: block;
margin-right: 0;
max-width: 130px;
}
}
.carbon-ads ::v-deep(.carbon-img img) {
.carbon-ads :deep(.carbon-img img) {
display: block;
width: 100%;
}
@media (min-width: 420px) {
.carbon-ads ::v-deep(.carbon-text) {
.carbon-ads :deep(.carbon-text) {
padding-top: 8px;
}
}
.carbon-ads ::v-deep(.carbon-text) {
.carbon-ads :deep(.carbon-text) {
display: block;
font-weight: 400;
color: var(--c-text-light);
}
.carbon-ads ::v-deep(.carbon-poweredby) {
.carbon-ads :deep(.carbon-poweredby) {
display: block;
padding-top: 2px;
font-weight: 400;
Expand Down

0 comments on commit 3e85b46

Please sign in to comment.