tui: prevent Storybook preview from crashing when useTheme throws an error

Previously, the Storybook preview would crash entirely if useTheme threw an
error, leaving users with a broken interface. Now the preview gracefully handles
theme errors by returning null instead of crashing, ensuring Storybook remains
usable even when theme context is unavailable.
This commit is contained in:
David Hill
2026-03-10 13:49:52 +00:00
parent b06ed8b5f8
commit a87a6bfe60

View File

@@ -20,7 +20,14 @@ function resolveScheme(value: unknown): ColorScheme {
const channel = addons.getChannel()
const Scheme = (props: { value?: unknown }) => {
const theme = useTheme()
const theme = (() => {
try {
return useTheme()
} catch {
return
}
})()
if (!theme) return null
const apply = (value?: unknown) => {
theme.setColorScheme(resolveScheme(value))
}