From: Eduardo San Martin Morote Date: Mon, 31 Jan 2022 15:06:00 +0000 (+0100) Subject: docs: wip with hydration errors X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e24ea8c2702b6f45bcb8a7e8d2aef56532cb16ba;p=thirdparty%2Fvuejs%2Fpinia.git docs: wip with hydration errors --- diff --git a/packages/docs/.vitepress/theme/Layout.ts b/packages/docs/.vitepress/theme/Layout.ts index a92e620b..06b5fbed 100644 --- a/packages/docs/.vitepress/theme/Layout.ts +++ b/packages/docs/.vitepress/theme/Layout.ts @@ -1,5 +1,5 @@ import Theme from 'vitepress/theme' -import { h, nextTick } from 'vue' +import { h, nextTick, ref } from 'vue' import type { FunctionalComponent } from 'vue' import sponsors from '../components/sponsors.json' import './sponsors.css' @@ -7,19 +7,65 @@ import { darkStorageConfig } from '../theme/dark-theme' import { useDark } from '@vueuse/core' export const Layout: FunctionalComponent = () => { - const showWwAds = - typeof navigator !== 'undefined' && - typeof navigator.language === 'string' && - navigator.language.startsWith('zh') + const showAds = ref(false) const isDark = useDark(darkStorageConfig) - const slots = { - 'sidebar-top': () => - h('div', { class: 'sponsors sponsors-top' }, [ - h('span', 'Platinum Sponsors'), - ...(sponsors.platinum.length - ? sponsors.platinum.map(({ href, imgSrcDark, imgSrcLight, alt }) => + return h( + Theme.Layout, + { + onVnodeMounted() { + console.log('vnode mounted') + nextTick(() => { + console.log('showAds', showAds.value) + showAds.value = + typeof navigator !== 'undefined' && + typeof navigator.language === 'string' && + navigator.language.startsWith('zh') + }) + }, + }, + Object.assign( + { + 'sidebar-top': () => + h('div', { class: 'sponsors sponsors-top' }, [ + h('span', 'Platinum Sponsors'), + ...(sponsors.platinum.length + ? sponsors.platinum.map( + ({ href, imgSrcDark, imgSrcLight, alt }) => + h( + 'a', + { + href, + target: '_blank', + rel: 'noopener', + }, + [ + h('img', { + src: isDark.value ? imgSrcDark : imgSrcLight, + alt, + }), + ] + ) + ) + : [ + h( + 'a', + { + class: 'become-sponsor', + href: 'https://github.com/sponsors/posva', + target: '_blank', + rel: 'noopener', + alt: 'Your logo here', + }, + 'Become a Sponsor!' + ), + ]), + ]), + 'sidebar-bottom': () => + h('div', { class: 'sponsors' }, [ + h('span', 'Sponsors'), + ...sponsors.gold.map(({ href, imgSrcDark, imgSrcLight, alt }) => h( 'a', { @@ -34,65 +80,24 @@ export const Layout: FunctionalComponent = () => { }), ] ) - ) - : [ - h( - 'a', - { - class: 'become-sponsor', - href: 'https://github.com/sponsors/posva', - target: '_blank', - rel: 'noopener', - alt: 'Your logo here', - }, - 'Become a Sponsor!' - ), - ]), - ]), - 'sidebar-bottom': () => - h('div', { class: 'sponsors' }, [ - h('span', 'Sponsors'), - ...sponsors.gold.map(({ href, imgSrcDark, imgSrcLight, alt }) => - h( - 'a', - { - href, - target: '_blank', - rel: 'noopener', - }, - [h('img', { src: isDark.value ? imgSrcDark : imgSrcLight, alt })] - ) - ), - ]), - } - - if (showWwAds) { - slots['page-top-ads'] = () => - h('div', { id: 'wwads-container' }, [ - h('div', { - class: 'wwads-cn wwads-vertical', - 'data-id': 144, - style: { - maxWidth: '150px', - }, - }), - ]) - } - - return h( - Theme.Layout, - { - onVnodeMounted() { - // wait to ticks to fix the problem of SSR with no color scheme - nextTick(() => { - isDark.value = !isDark.value - return nextTick() - }).then(() => { - isDark.value = !isDark.value - }) + ), + ]), }, - }, - slots + showAds.value + ? { + 'page-top-ads': () => + h('div', { id: 'wwads-container' }, [ + h('div', { + class: 'wwads-cn wwads-vertical', + 'data-id': 144, + style: { + maxWidth: '150px', + }, + }), + ]), + } + : {} + ) ) } diff --git a/packages/docs/.vitepress/theme/custom.css b/packages/docs/.vitepress/theme/custom.css index ed0a5c6a..2d34b502 100644 --- a/packages/docs/.vitepress/theme/custom.css +++ b/packages/docs/.vitepress/theme/custom.css @@ -213,10 +213,13 @@ code { } #wwads-container { - position: relative; - float: right; z-index: 9; - margin: 0 0 16px 16px; + margin: 0 auto; + padding: 8px; + max-width: 280px; + /* font-size: 0.75rem; */ + background-color: var(--c-bg-accent); + min-height: 105.38px; /* avoid layout shift on mobile */ } #wwads-container .wwads-text { @@ -227,6 +230,18 @@ code { clear: none !important; } +@media (min-width: 420px) { + #wwads-container { + position: relative; + margin: 0 0 16px 16px; + float: right; + margin: -8px -8px 24px 24px; + width: 146px; + max-width: 100%; + min-height: 200px; + } +} + @media (min-width: 1368px) { #wwads-container { position: fixed; diff --git a/packages/docs/vite.config.ts b/packages/docs/vite.config.ts index a2ab4aa3..33e996b7 100644 --- a/packages/docs/vite.config.ts +++ b/packages/docs/vite.config.ts @@ -32,19 +32,17 @@ function copyPiniaPlugin(): Plugin { return { name: 'copy-pinia', async generateBundle() { - const filePath = path.resolve( - __dirname, - '../pinia/dist/pinia.esm-bundler.js' - ) - - // throws if file doesn't exist - await fs.access(filePath) - - this.emitFile({ - type: 'asset', - fileName: 'pinia.mjs', - source: await fs.readFile(filePath, 'utf-8'), - }) + // const filePath = path.resolve( + // __dirname, + // '../pinia/dist/pinia.esm-bundler.js' + // ) + // // throws if file doesn't exist + // await fs.access(filePath) + // this.emitFile({ + // type: 'asset', + // fileName: 'pinia.mjs', + // source: await fs.readFile(filePath, 'utf-8'), + // }) }, } }