Skip to content

Commit 37079bf

Browse files
feat: prevent ugly overscroll bounce on all browsers and sync mobile status bar w/ theme (#527)
feat: prevent overscroll bounce on all browsers and sync mobile status bar with theme - Add overscroll-behavior: none to prevent bounce effect across all browsers - Implement dynamic theme-color meta tag that syncs with site theme toggle - Add THEME_COLORS constant to utils for consistent color references - Update ThemeProvider to set status bar color on theme change Co-authored-by: Tanner Linsley <tannerlinsley@gmail.com>
1 parent 6c54dab commit 37079bf

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

src/components/ThemeProvider.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createClientOnlyFn, createIsomorphicFn } from '@tanstack/react-start'
33
import * as React from 'react'
44
import { createContext, ReactNode, useEffect, useState } from 'react'
55
import { z } from 'zod'
6+
import { THEME_COLORS } from '~/utils/utils'
67

78
const themeModeSchema = z.enum(['light', 'dark', 'auto'])
89
const resolvedThemeSchema = z.enum(['light', 'dark'])
@@ -46,6 +47,14 @@ const updateThemeClass = createClientOnlyFn((themeMode: ThemeMode) => {
4647
if (themeMode === 'auto') {
4748
root.classList.add('auto')
4849
}
50+
51+
const metaThemeColor = document.querySelector('meta[name="theme-color"]')
52+
if (metaThemeColor) {
53+
metaThemeColor.setAttribute(
54+
'content',
55+
newTheme === 'dark' ? THEME_COLORS.dark : THEME_COLORS.light
56+
)
57+
}
4958
})
5059

5160
const setupPreferredListener = createClientOnlyFn(() => {

src/routes/__root.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { authClient } from '../utils/auth.client'
3333

3434
import { LibrariesLayout } from './_libraries/route'
3535
import { TanStackUser } from 'convex/auth'
36+
import { THEME_COLORS } from '~/utils/utils'
3637

3738
export const Route = createRootRouteWithContext<{
3839
queryClient: QueryClient
@@ -49,6 +50,16 @@ export const Route = createRootRouteWithContext<{
4950
name: 'viewport',
5051
content: 'width=device-width, initial-scale=1',
5152
},
53+
{
54+
name: 'theme-color',
55+
content: THEME_COLORS.light,
56+
media: '(prefers-color-scheme: light)',
57+
},
58+
{
59+
name: 'theme-color',
60+
content: THEME_COLORS.dark,
61+
media: '(prefers-color-scheme: dark)',
62+
},
5263
...seo({
5364
title:
5465
'TanStack | High Quality Open-Source Software for Web Developers',

src/styles/app.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ button {
6868
html,
6969
body {
7070
@apply text-gray-900 bg-gray-50 dark:bg-gray-900 dark:text-gray-200;
71+
overscroll-behavior: none;
7172
}
7273

7374
.using-mouse * {

src/utils/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,10 @@ export async function logTime<T>(
175175
console.log(`${lable}: ${(end - start).toLocaleString()} ms`)
176176
return result as any
177177
}
178+
179+
export const THEME_COLORS = {
180+
light: '#f9fafb', // Tailwind gray-50
181+
dark: '#101828', // Tailwind gray-900
182+
} as const
183+
184+
export type ThemeColor = keyof typeof THEME_COLORS

0 commit comments

Comments
 (0)