Files
supabase/apps/studio/pages/_app.tsx
cc540ff302 feat(studio): add safe theme colour controls (#49804)
## What kind of change does this PR introduce?

Feature.

## What is the current behaviour?

Studio Appearance preferences only select a theme mode. The underlying
theme colours cannot be adjusted, and the existing proof of concept
allowed unsafe combinations and introduced a bespoke Slider variant.

## What is the new behaviour?

- Preserves the existing System, Dark, Light, and Classic Dark theme
options. Classic Dark remains a fixed preset.
- Adds four theme colour controls using the existing Supabase Slider
unchanged. Each control presents a consistent 0 to 100 scale mapped to
bounded light and dark ranges.
- Previews colour changes while dragging and persists them once the
interaction finishes, including rapid pointer gestures.
- Stores light and dark overrides separately, validates stored values,
clamps legacy values, and removes overrides that return to their shipped
defaults.
- Adds concise descriptions for Chroma, Contrast, Surface, and Elevation
step, with a scoped Reset action shown only when the active theme
differs from its defaults.
- Keeps Slider in a stable shared chunk so production builds do not
create a circular dependency between generated UI chunks.

| Before | After |
| --- | --- |
| <img width="1448" height="1284" alt="CleanShot 2026-09-15 at 14 33
53@2x"
src="https://github.com/user-attachments/assets/d55151c7-b2a9-40c6-9468-e77ae685ac38"
/> | <img width="1454" height="1958" alt="CleanShot 2026-09-15 at 17 48
47@2x"
src="https://github.com/user-attachments/assets/9d302e67-76cc-4341-948c-81713dea2e93"
/> |

## To test

1. Open `/account/me` and scroll to Appearance.
2. Switch between System, Dark, Light, and Classic Dark. Confirm the
same four modes remain available in the account theme menu.
3. Confirm Classic Dark retains its existing appearance and does not
show theme colour controls.
4. In System, Dark, or Light, move each Theme colors slider to both
ends. Confirm the dashboard previews the change, remains readable, and
the theme cards do not shift or remount.
5. Reload the page and confirm colour changes persist separately for
Light and Dark.
6. Return all sliders to their defaults, or select Reset, and confirm
the Reset action disappears.
7. In System mode, change the operating system theme and confirm each
resolved mode restores its own colour settings.

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com>
2026-09-17 10:33:59 +10:00

256 lines
11 KiB
TypeScript

import '@/styles/code.css'
import '@/styles/globals.css'
import '@/styles/graphiql-base.css'
import '@/styles/grid.css'
import '@/styles/markdown-preview.css'
import '@/styles/monaco.css'
import '@/styles/react-data-grid-logs.css'
import '@/styles/reactflow.css'
import '@/styles/storage.css'
import '@/styles/stripe.css'
import '@/styles/ui.css'
import 'react-data-grid/lib/styles.css'
import 'ui-patterns/ShimmeringLoader/index.css'
import * as Sentry from '@sentry/nextjs'
import { HydrationBoundary, QueryClientProvider } from '@tanstack/react-query'
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import {
FeatureFlagProvider,
getFlags,
TelemetryTagManager,
ThemeProvider,
useThemeSandbox,
} from 'common'
import MetaFaviconsPagesRouter from 'common/MetaFavicons/pages-router'
import dayjs from 'dayjs'
import customParseFormat from 'dayjs/plugin/customParseFormat'
import duration from 'dayjs/plugin/duration'
import relativeTime from 'dayjs/plugin/relativeTime'
import timezone from 'dayjs/plugin/timezone'
import utc from 'dayjs/plugin/utc'
import { DevToolbar, DevToolbarProvider, DevToolbarTrigger, type ExtraTab } from 'dev-tools'
import dynamic from 'next/dynamic'
import Head from 'next/head'
import { NuqsAdapter } from 'nuqs/adapters/next/pages'
import { ErrorInfo, useCallback, useEffect, useState, type ComponentProps } from 'react'
import { ErrorBoundary } from 'react-error-boundary'
import { TooltipProvider } from 'ui'
import { TimestampInfoProvider } from 'ui-patterns/TimestampInfo'
import { AppearanceSettingsProvider } from '@/components/interfaces/App/AppearanceSettingsProvider'
import { StudioCommandMenu } from '@/components/interfaces/App/CommandMenu'
import { StudioCommandProvider as CommandProvider } from '@/components/interfaces/App/CommandMenu/StudioCommandProvider'
import { FeaturePreviewContextProvider } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'
import { FeaturePreviewModal } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewModal'
import { IndirectTaxDeclarationModal } from '@/components/interfaces/App/IndirectTaxDeclarationModal'
import { MonacoThemeProvider } from '@/components/interfaces/App/MonacoThemeProvider'
import { RouteValidationWrapper } from '@/components/interfaces/App/RouteValidationWrapper'
import { MainScrollContainerProvider } from '@/components/layouts/MainScrollContainerContext'
import { BannerStackProvider } from '@/components/ui/BannerStack/BannerStackProvider'
import { GlobalErrorBoundaryState } from '@/components/ui/ErrorBoundary/GlobalErrorBoundaryState'
import { GlobalShortcuts } from '@/components/ui/GlobalShortcuts/GlobalShortcuts'
import { getCLIReleaseVersion } from '@/data/misc/cli-release-version-query'
import { useRootQueryClient } from '@/data/query-client'
import { inter, manrope, sourceCodePro } from '@/fonts'
import { useCustomContent } from '@/hooks/custom-content/useCustomContent'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
import { AuthProvider } from '@/lib/auth'
import { configureMonacoLoader } from '@/lib/configure-monaco-loader'
import { API_URL, BASE_PATH, IS_PLATFORM, useDefaultProvider } from '@/lib/constants'
import { TimezoneProvider, useTimezone } from '@/lib/datetime'
import { ProfileProvider } from '@/lib/profile'
import { Telemetry } from '@/lib/telemetry'
import { ToastErrorTracker } from '@/lib/toast-errors'
import { Toaster } from '@/lib/toaster'
import { AiAssistantStateContextProvider } from '@/state/ai-assistant-state'
import type { AppPropsWithLayout } from '@/types'
dayjs.extend(customParseFormat)
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(relativeTime)
dayjs.extend(duration)
// Keep dev-only components out of the production bundle
const env = process.env.NEXT_PUBLIC_ENVIRONMENT
const IS_DEV_TOOLBAR_ENABLED = env === 'local' || env === 'staging'
const ResourceWarningsTab = IS_DEV_TOOLBAR_ENABLED
? dynamic(() =>
import('@/components/ui/DevToolbar/ResourceWarningsTab').then((m) => m.ResourceWarningsTab)
)
: () => null
const ProjectStatusTab = IS_DEV_TOOLBAR_ENABLED
? dynamic(() =>
import('@/components/ui/DevToolbar/ProjectStatusTab').then((m) => m.ProjectStatusTab)
)
: () => null
const devToolbarExtraTabs: ExtraTab[] = IS_DEV_TOOLBAR_ENABLED
? [
{ id: 'warnings', label: 'Warnings', content: <ResourceWarningsTab /> },
{ id: 'project-status', label: 'Project Status', content: <ProjectStatusTab /> },
]
: []
const FeatureFlagProviderWithOrgContext = ({
children,
...props
}: ComponentProps<typeof FeatureFlagProvider>) => {
const { data: selectedOrganization } = useSelectedOrganizationQuery({ enabled: IS_PLATFORM })
const cloudProvider = useDefaultProvider()
const getConfigCatFlags = useCallback(
(userEmail?: string) => {
const customAttributes: Record<string, string> = {}
if (cloudProvider) customAttributes.cloud_provider = cloudProvider
if (selectedOrganization?.plan?.id) customAttributes.plan = selectedOrganization.plan.id
return getFlags(userEmail, customAttributes)
},
[cloudProvider, selectedOrganization?.plan?.id]
)
return (
<FeatureFlagProvider
{...props}
getConfigCatFlags={getConfigCatFlags}
organizationSlug={selectedOrganization?.slug ?? undefined}
>
{children}
</FeatureFlagProvider>
)
}
const TimestampInfoTimezoneBridge = ({ children }: { children: React.ReactNode }) => {
const { timezone } = useTimezone()
return <TimestampInfoProvider timezone={timezone}>{children}</TimestampInfoProvider>
}
configureMonacoLoader()
// [Joshen TODO] Once we settle on the new nav layout - we'll need a lot of clean up in terms of our layout components
// a lot of them are unnecessary and introduce way too many cluttered CSS especially with the height styles that make
// debugging way too difficult. Ideal scenario is we just have one AppLayout to control the height and scroll areas of
// the dashboard, all other layout components should not be doing that
function CustomApp({ Component, pageProps }: AppPropsWithLayout) {
const queryClient = useRootQueryClient()
const { appTitle } = useCustomContent(['app:title'])
const [isCLI, setIsCLI] = useState(false)
const getLayout = Component.getLayout ?? ((page) => page)
const errorBoundaryHandler = (error: Error, _info: ErrorInfo) => {
Sentry.withScope(function (scope) {
scope.setTag('globalErrorBoundary', true)
const eventId = Sentry.captureException(error)
// Attach the Sentry event ID to the error object so it can be accessed by the error boundary
if (eventId && error && typeof error === 'object') {
;(error as any).sentryId = eventId
}
})
console.error(error.stack)
}
useThemeSandbox()
const isTestEnv = process.env.NEXT_PUBLIC_NODE_ENV === 'test'
// [Joshen] Should target hosted staging, local dev, and local CLI only
const isNonProdEnv = (IS_PLATFORM && process.env.NEXT_PUBLIC_ENVIRONMENT !== 'prod') || isCLI
const checkCliEnvironment = async () => {
const data = await getCLIReleaseVersion()
if (!!data.current) setIsCLI(true)
}
useEffect(() => {
if (!IS_PLATFORM) checkCliEnvironment()
}, [])
return (
<QueryClientProvider client={queryClient}>
<ErrorBoundary FallbackComponent={GlobalErrorBoundaryState} onError={errorBoundaryHandler}>
<NuqsAdapter>
<HydrationBoundary state={pageProps.dehydratedState}>
<AuthProvider>
<FeatureFlagProviderWithOrgContext API_URL={API_URL} enabled={IS_PLATFORM}>
<ProfileProvider>
<TimezoneProvider>
<TimestampInfoTimezoneBridge>
<Head>
<title>{appTitle ?? 'Supabase'}</title>
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
<meta property="og:image" content={`${BASE_PATH}/img/supabase-og.png`} />
<meta name="googlebot" content="notranslate" />
{/* [Alaister]: This has to be an inline style tag here and not a separate component due to next/font */}
<style
dangerouslySetInnerHTML={{
__html: `:root{--font-sans:${inter.style.fontFamily};--font-heading:${manrope.style.fontFamily};--font-source-code-pro:${sourceCodePro.style.fontFamily};}`,
}}
/>
{/* Speed up initial API loading times by pre-connecting to the API domain */}
{IS_PLATFORM && (
<link
rel="preconnect"
href={new URL(API_URL).origin}
crossOrigin="use-credentials"
/>
)}
</Head>
<MetaFaviconsPagesRouter
includeManifest
applicationName="Supabase Studio"
route={isNonProdEnv ? '/favicon/staging' : '/favicon'}
/>
<TooltipProvider>
<RouteValidationWrapper>
<ThemeProvider>
<DevToolbarProvider apiUrl={API_URL}>
<AiAssistantStateContextProvider>
<CommandProvider>
<BannerStackProvider>
<FeaturePreviewContextProvider>
<MainScrollContainerProvider>
{getLayout(<Component {...pageProps} />)}
</MainScrollContainerProvider>
<GlobalShortcuts />
<StudioCommandMenu />
<FeaturePreviewModal />
<IndirectTaxDeclarationModal />
</FeaturePreviewContextProvider>
</BannerStackProvider>
<Toaster />
<MonacoThemeProvider />
<AppearanceSettingsProvider />
</CommandProvider>
</AiAssistantStateContextProvider>
<DevToolbar extraTabs={devToolbarExtraTabs} />
<DevToolbarTrigger />
</DevToolbarProvider>
</ThemeProvider>
</RouteValidationWrapper>
</TooltipProvider>
<Telemetry />
<ToastErrorTracker />
{!isTestEnv && (
<ReactQueryDevtools initialIsOpen={false} buttonPosition="bottom-left" />
)}
</TimestampInfoTimezoneBridge>
</TimezoneProvider>
</ProfileProvider>
</FeatureFlagProviderWithOrgContext>
</AuthProvider>
</HydrationBoundary>
</NuqsAdapter>
<TelemetryTagManager />
</ErrorBoundary>
</QueryClientProvider>
)
}
export default CustomApp