Skip to content

Commit 8c21ac7

Browse files
committed
Website: fix two FOUC flickers on page load
- Add inline `<style>` in `<head>` to set light background before first paint, preventing dark→light flash for `prefers-color-scheme: light` users - Add inline `<script>` in `<head>` to detect newsletter subscription state from `localStorage` and add `.newsletter-hidden` class before paint, preventing the mail icon from appearing then vanishing - Add `.newsletter-hidden [data-newsletter-nav]` CSS rule in `global.css` to back the class-based hiding
1 parent 61fe290 commit 8c21ac7

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

apps/website/src/layouts/Layout.astro

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ const {
7878
})}
7979
/>
8080

81+
{/* Prevent light-mode FOUC: set background before first paint */}
82+
<style is:inline>
83+
@media (prefers-color-scheme: light) {
84+
html:not([data-force-dark]) { background-color: #fafaf8; }
85+
}
86+
</style>
87+
88+
{/* Hide newsletter icon before first paint if user already subscribed/dismissed */}
89+
<script is:inline>
90+
try {
91+
if (
92+
localStorage.getItem('newsletter-subscribed') === 'true' ||
93+
localStorage.getItem('newsletter-dismissed') === 'true' ||
94+
localStorage.getItem('newsletter-cta-dismissed') === 'true'
95+
) {
96+
document.documentElement.classList.add('newsletter-hidden')
97+
}
98+
} catch (e) {}
99+
</script>
100+
81101
{/* Umami analytics — self-hosted, cookieless */}
82102
{
83103
import.meta.env.PUBLIC_UMAMI_WEBSITE_ID && (

apps/website/src/styles/global.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ body {
6161
overflow-x: hidden;
6262
}
6363

64+
/* Hide newsletter elements before JS hydration if user already subscribed/dismissed */
65+
.newsletter-hidden [data-newsletter-nav] {
66+
display: none;
67+
}
68+
6469
/* Selection */
6570
::selection {
6671
background-color: var(--color-accent);

0 commit comments

Comments
 (0)