Skip to content

Commit

Permalink
fix(v2): fix useEffect infinite loop in blogOnly mode (#5097)
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber authored Jun 30, 2021
1 parent ab3821c commit 0f14421
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ import {
GetActivePluginOptions,
} from '../../client/docsClientUtils';

// Important to use a constant object to avoid React useEffect executions etc...,
// see https://github.com/facebook/docusaurus/issues/5089
const StableEmptyObject = {};

// Not using useAllPluginInstancesData() because in blog-only mode, docs hooks are still used by the theme
// We need a fail-safe fallback when the docs plugin is not in use
export const useAllDocsData = (): Record<string, GlobalPluginData> =>
// useAllPluginInstancesData('docusaurus-plugin-content-docs');
useGlobalData()['docusaurus-plugin-content-docs'] ?? {};
useGlobalData()['docusaurus-plugin-content-docs'] ?? StableEmptyObject;

export const useDocsData = (pluginId: string | undefined): GlobalPluginData =>
usePluginData('docusaurus-plugin-content-docs', pluginId) as GlobalPluginData;
Expand Down

0 comments on commit 0f14421

Please sign in to comment.