From 37fa89ddab75da42fef993e57aa08593e263bbde Mon Sep 17 00:00:00 2001 From: Putro Date: Sun, 16 Jan 2022 16:22:16 +0100 Subject: [PATCH] Ensure that __DOCS_CONTEXT__ cannot be undefined when using storyshots --- addons/docs/src/blocks/DocsContext.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/docs/src/blocks/DocsContext.ts b/addons/docs/src/blocks/DocsContext.ts index 3fada361a323..e539f2739c6e 100644 --- a/addons/docs/src/blocks/DocsContext.ts +++ b/addons/docs/src/blocks/DocsContext.ts @@ -12,9 +12,11 @@ export type { DocsContextProps }; // the React component tree. // This was specifically a problem with the Vite builder. /* eslint-disable no-underscore-dangle */ -if (globalWindow.__DOCS_CONTEXT__ === undefined) { +if (globalWindow && globalWindow.__DOCS_CONTEXT__ === undefined) { globalWindow.__DOCS_CONTEXT__ = createContext({}); globalWindow.__DOCS_CONTEXT__.displayName = 'DocsContext'; } -export const DocsContext: Context> = globalWindow.__DOCS_CONTEXT__; +export const DocsContext: Context> = globalWindow + ? globalWindow.__DOCS_CONTEXT__ + : createContext({});