Skip to content

Instantly share code, notes, and snippets.

@SpenceDiNicolantonio
Last active May 7, 2024 13:43
Show Gist options
  • Save SpenceDiNicolantonio/e4bc3e3619644800d8fa82ffd70e4521 to your computer and use it in GitHub Desktop.
Save SpenceDiNicolantonio/e4bc3e3619644800d8fa82ffd70e4521 to your computer and use it in GitHub Desktop.
FOUC Off (Svelte) #svelte #fouc
<!-- 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