diff --git a/lib/components/layout.tsx b/lib/components/layout.tsx index a029bbd..4f5e881 100644 --- a/lib/components/layout.tsx +++ b/lib/components/layout.tsx @@ -27,7 +27,17 @@ export const Layout: React.FC> = React.memo(({ ch useEffect(() => setShowAfterRender(true), []) - if (!showAfterRender) return null + if (!showAfterRender) return ( +
+ {children} + +
+ ) return (
diff --git a/lib/components/menu/index.tsx b/lib/components/menu/index.tsx index 0932a7a..a8e8ace 100644 --- a/lib/components/menu/index.tsx +++ b/lib/components/menu/index.tsx @@ -1,10 +1,33 @@ import React, { useEffect, useState } from 'react' +import { useRouter } from 'next/router' import MenuLinks from './menu-links' import MenuSticker from './menu-sticker' +import { useConfigs } from 'lib/config-context' const Menu: React.FC<{}> = () => { + const router = useRouter() + const { isChinese } = useConfigs() const [showAfterRender, setShowAfterRender] = useState(false) useEffect(() => setShowAfterRender(true), []) + useEffect(() => { + const prefetch = async () => { + const urls = isChinese ? [ + '/zh-cn/guide/introduction', + '/zh-cn/components/text', + '/zh-cn/customization', + ] : [ + '/en-us/guide/introduction', + '/en-us/components/text', + '/en-us/customization', + ] + await Promise.all(urls.map(async (url) => { + await router.prefetch(url) + })) + } + prefetch() + .then() + .catch(err => console.log(err)) + }, [isChinese]) if (!showAfterRender) return null return ( diff --git a/lib/components/playground/index.ts b/lib/components/playground/index.ts new file mode 100644 index 0000000..9b8fcf7 --- /dev/null +++ b/lib/components/playground/index.ts @@ -0,0 +1,8 @@ +import dynamic from 'next/dynamic' + +const DynamicPlaygroundWithNoSSR = dynamic( + () => import('./playground'), + { ssr: false } +) + +export default DynamicPlaygroundWithNoSSR diff --git a/lib/components/playground/index.tsx b/lib/components/playground/playground.tsx similarity index 96% rename from lib/components/playground/index.tsx rename to lib/components/playground/playground.tsx index 330b1f1..104bd36 100644 --- a/lib/components/playground/index.tsx +++ b/lib/components/playground/playground.tsx @@ -3,12 +3,10 @@ import { LivePreview, LiveProvider, LiveEditor, LiveError } from 'react-live' import withDefaults from 'components/utils/with-defaults' import useClipboard from 'components/utils/use-clipboard' import { useTheme, useToasts } from 'components' -import { useConfigs } from '../../config-context' +import { useConfigs } from 'lib/config-context' import makeCodeTheme from './code-theme' import RightIcon from '@zeit-ui/react-icons/chevronRight' import CopyIcon from '@zeit-ui/react-icons/copy' -// import RightIcon from 'lib/components/icons/right' -// import CopyIcon from 'lib/components/icons/copy' import Title from './title' interface Props { diff --git a/pages/_document.tsx b/pages/_document.tsx index 31984c5..c6abd75 100644 --- a/pages/_document.tsx +++ b/pages/_document.tsx @@ -1,22 +1,6 @@ import Document, { Html, Head, Main, NextScript } from 'next/document' -import flush from 'styled-jsx/server' -import { DocumentContext, DocumentInitialProps } from 'next/dist/next-server/lib/utils' class MyDocument extends Document { - static async getInitialProps (ctx: DocumentContext): Promise { - const initialProps = await Document.getInitialProps(ctx) - - return { - ...initialProps, - styles: ( - <> - {initialProps.styles} - {flush()} - - ) - } - } - render() { return (