-
SummaryHello. I am not able to use useGlobals hook or ManagerContext inside MDX doc page. It is rendered inside an iframe and no providers are available for global values. {
"globals": "theme:dark",
"viewMode": "docs",
"id": "colors--docs"
} Is there a better way to do this without using internal API? Additional informationstorybook v9.1.1 Create a reproductionNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hi @vpanfilov! I'm Dosu and I’m helping the storybook team. There isn't a supported way to access Storybook globals from MDX doc pages in v9.1.1. This is because MDX docs are rendered in the preview iframe, which doesn't have access to the React context providers that supply globals—so hooks like Community discussions confirm this is a known limitation, and there is no recommended public API or workaround for accessing globals in MDX docs. The architecture intentionally separates manager and preview contexts for performance and UX reasons, so globals are only available in stories and decorators, not in docs pages. If you need to pass data into MDX docs, the best practice is to use args, parameters, or doc blocks, but these don't provide access to globals directly [discussion]. Relevant docs: To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
Ok, seems to be answered in #26589 |
Beta Was this translation helpful? Give feedback.
-
I ended up with code like: const channel = addons.getChannel();
const themeName = channel.last('updateGlobals')?.at(0)?.globals?.theme ?? 'default'; Subscribing to |
Beta Was this translation helpful? Give feedback.
I ended up with code like:
Subscribing to
channel.on('updateGlobals', handler)
inside useEffect didn't work, because component rerenders from scratch after globals change.