The Sanity engineering blog is live. Deep dives from our engineers.

Button component error: "Cannot destructure property 'media' of 'theme.sanity'

38 repliesLast updated: Nov 29, 2025

Hi, I'm trying to use the Button component from sanity-ui in a studio plugin, but I"m getting this error:
TypeError: Cannot destructure property 'media' of 'theme.sanity' as it is undefined.
    at responsiveRadiusStyle (/studio/static/js/app.bundle.js:345740:13)
    at Ne (/studio/static/js/app.bundle.js:334335:14863)
    at e.generateAndInjectStyles (/studio/static/js/app.bundle.js:334335:11304)
    at <http://localhost:3333/studio/static/js/app.bundle.js:334335:19082>
    at <http://localhost:3333/studio/static/js/app.bundle.js:334335:19257>
    at styled.button (/studio/static/js/app.bundle.js:334335:19848)
    at renderWithHooks (/studio/static/js/vendor.bundle.js:17945:18)
    at updateForwardRef (/studio/static/js/vendor.bundle.js:19958:20)
    at beginWork (/studio/static/js/vendor.bundle.js:21787:16)
    at HTMLUnknownElement.callCallback (/studio/static/js/vendor.bundle.js:3330:14)
AI Update

This error occurs because sanity-ui components like Button require a proper theme context to function correctly. When you use sanity-ui components in a Studio plugin, they expect to be wrapped in a ThemeProvider with a Sanity theme, but your component is likely missing this context.

The error Cannot destructure property 'media' of 'theme.sanity' means the Button component is trying to access theme.sanity.media in the responsiveRadiusStyle function, but the theme object doesn't have the expected Sanity theme structure.

Quick Fix - Wrap with ThemeProvider:

import { Button, ThemeProvider, studioTheme } from '@sanity/ui'

export function MyPluginComponent() {
  return (
    <ThemeProvider theme={studioTheme}>
      <Button text="Click me" />
    </ThemeProvider>
  )
}

Why this happens:

When building Studio plugins, sanity-ui components need access to the Sanity theme context. If your component is rendered outside the Studio's normal React tree (like in a custom tool or during development), it won't have access to the theme automatically.

Common causes:

Best practice for plugins:

If you're building a proper Studio plugin, the Studio should provide the theme context automatically once your plugin is loaded. You typically shouldn't need to manually add ThemeProvider unless you're creating an isolated component tree. Make sure your plugin dependencies are configured correctly so they use the host Studio's instances of React and sanity-ui.

Show original thread
38 replies

Was this answer helpful?

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Related contributions