Skip to content

Commit

Permalink
Ensure that __DOCS_CONTEXT__ cannot be undefined when using storyshots
Browse files Browse the repository at this point in the history
  • Loading branch information
Pewtro committed Jan 16, 2022
1 parent fb4d3b2 commit 37fa89d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions addons/docs/src/blocks/DocsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DocsContextProps<AnyFramework>> = globalWindow.__DOCS_CONTEXT__;
export const DocsContext: Context<DocsContextProps<AnyFramework>> = globalWindow
? globalWindow.__DOCS_CONTEXT__
: createContext({});

0 comments on commit 37fa89d

Please sign in to comment.