1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-06-30 22:26:38 -04:00

tell unblock-transitions script to remove itself when finished

This commit is contained in:
2022-02-18 12:31:57 -05:00
parent 5f977db7f2
commit 17a271eb87
2 changed files with 9 additions and 7 deletions

View File

@ -26,16 +26,14 @@ const Layout = ({ container = true, stickyHeader = true, className, children, ..
}}
/>
{/* kinda a hack to prevent dramatically fading into dark theme if we're immediately setting it on load */}
<style id="no-fade-css">{`.page.no-fade,.page.no-fade *{transition:none!important}`}</style>
{/* dynamically set browser theme color to match the background color */}
{/* dynamically set browser theme color to match the background color; default to light for SSR */}
<meta name="theme-color" content={themes[resolvedTheme || "light"]["background-outer"]} />
</Head>
{/* remove the `.no-fade` class above from body once the page is finished loading */}
{/* this script removes the CSS that blocks transitions (see _document.tsx) once the page is finished loading...
...and removes itself after it has done that: */}
<Script id="unblock-transitions" strategy="lazyOnload">
{`try{document.body.classList.remove("no-fade");document.getElementById("no-fade-css").remove()}catch(e){}`}
{`try{document.getElementById("block-transitions").remove();document.getElementById("unblock-transitions").remove()}catch(e){}`}
</Script>
<div className={classNames(styles.flex, className)} {...rest}>

View File

@ -5,7 +5,11 @@ import * as config from "../lib/config";
const Document = () => {
return (
<Html lang={config.siteLocale?.replace("_", "-")}>
<Head />
<Head>
{/* kinda a hack to prevent dramatically fading into dark theme if we're immediately setting it on load. */}
{/* removed by `<Layout />` once the page is completely finished loading. */}
<style id="block-transitions">{`*,::before,::after{transition:none!important}`}</style>
</Head>
<body>
<Main />
<NextScript />