mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-24 06:45:22 +00:00
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:
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user