Last active
May 7, 2024 13:43
-
-
Save SpenceDiNicolantonio/e4bc3e3619644800d8fa82ffd70e4521 to your computer and use it in GitHub Desktop.
FOUC Off (Svelte) #svelte #fouc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- This component disables CSS transitions until onMount fires, in order to avoid FOUC --> | |
<script lang="ts"> | |
import { tick } from 'svelte'; | |
// Adds 'mounted' class to body to signal that transitions should be enabled | |
$effect(() => { | |
tick().then(() => document.firstElementChild?.setAttribute('data-mounted', 'true')); | |
}); | |
</script> | |
<style> | |
:global(html:not([data-mounted]), html:not([data-mounted]) *) { | |
transition: none !important; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment