Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/components/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const getSystemTheme = createIsomorphicFn()

const updateThemeClass = createClientOnlyFn((themeMode: ThemeMode) => {
const root = document.documentElement
root.classList.add('theme-switching')

root.classList.remove('light', 'dark', 'auto')
const newTheme = themeMode === 'auto' ? getSystemTheme() : themeMode
root.classList.add(newTheme)
Expand All @@ -57,6 +59,15 @@ const updateThemeClass = createClientOnlyFn((themeMode: ThemeMode) => {
newTheme === 'dark' ? THEME_COLORS.dark : THEME_COLORS.light,
)
}

// Force reflow so the no-transition styles apply to the theme change,
// then remove the class on the next frame so subsequent interactions animate.
void root.offsetHeight
requestAnimationFrame(() => {
requestAnimationFrame(() => {
root.classList.remove('theme-switching')
})
})
})

const getNextTheme = createClientOnlyFn((current: ThemeMode): ThemeMode => {
Expand Down
9 changes: 9 additions & 0 deletions src/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
@custom-variant auto (&:is(.auto, .auto *));
@custom-variant aria-current (&[aria-current="location"]);

html.theme-switching,
html.theme-switching *,
html.theme-switching *::before,
html.theme-switching *::after {
transition: none !important;
animation-duration: 0s !important;
animation-delay: 0s !important;
}

@theme {
/* Breakpoints */
--breakpoint-xs: 480px;
Expand Down
Loading