Skip to content

@storybook/addon-ondevice-controls theme context not provided to PropForm componentΒ #821

@alexshadie

Description

@alexshadie

Description

When using @storybook/addon-ondevice-controls v10.1.0 with @storybook/react-native v10.1.0, the Controls addon fails with a theme context error when trying to render the controls panel.

Error

TypeError: Cannot read property 'size' of undefined
at theme.typography.size.s2
in PropForm.js

The error occurs because the PropForm component uses styled components from @storybook/react-native-theming which expect the theme to come from a ThemeProvider context, but theme.typography is undefined when accessed.

Environment

  • @storybook/react-native: 10.1.0
  • @storybook/addon-ondevice-controls: 10.1.0
  • @storybook/addon-ondevice-actions: 10.1.0
  • react-native: 0.76.1
  • react: 18.3.1

Steps to Reproduce

  1. Set up React Native Storybook with the Controls addon:

.storybook/main.ts:

import type { StorybookConfig } from "@storybook/react-native"

const config: StorybookConfig = {
    stories: ["../src/components-ui/**/*.stories.?(ts|tsx|js|jsx)"],
    addons: [
        "@storybook/addon-ondevice-controls",
        "@storybook/addon-ondevice-actions",
    ],
}

export default config

.storybook/Storybook.tsx:

import AsyncStorage from "@react-native-async-storage/async-storage"
import { view } from "./storybook.requires"

const StorybookUI = view.getStorybookUI({
  storage: AsyncStorage,
})

export default StorybookUI
  1. Create a story with args
  2. Run the app and navigate to Storybook
  3. Tap the edit icon (bottom right) to open the Controls panel
  4. Error appears: TypeError: Cannot read property 'size' of undefined

Investigation

The PropForm component in @storybook/addon-ondevice-controls/dist/PropForm.js uses styled components that reference theme properties:

const Label = styled.Text(({ theme }) => ({
    fontSize: theme.typography.size.s2 - 1,  // <- Error here
    fontWeight: 'bold',
    color: theme.color.defaultText,
}));

The FullUI component in @storybook/react-native-ui does wrap everything with ThemeProvider:

const FullUI = ({ storage, theme, storyHash, story, children }) => {
  return (
    <ThemeProvider theme={theme}>
      {/* ... */}
    </ThemeProvider>
  );
};

However, the theme context is not reaching the PropForm component, causing theme.typography to be undefined.

Attempted Solutions

  1. Passing theme via getStorybookUI - Did not resolve the issue
  2. Adding theme to preview.tsx parameters - Did not resolve the issue
  3. Using default theme (no custom theme config) - Still fails with the same error

Workaround

Temporarily disable the Controls addon in main.ts:

const config: StorybookConfig = {
    stories: ["../src/components-ui/**/*.stories.?(ts|tsx|js|jsx)"],
    addons: [
        // "@storybook/addon-ondevice-controls", // Disabled due to theme bug
        "@storybook/addon-ondevice-actions",
    ],
}

Expected Behavior

The Controls addon should render without errors, allowing users to interactively modify component props through the controls panel.

Additional Context

This appears to be a regression or incompatibility between the addon and the theming system in v10.1.0. The theme is being passed to FullUI but not propagating correctly to the addon panels.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions