From db5e50e68767cbea02490bf9a020c940686cb5ce Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Fri, 9 Feb 2024 15:17:17 +0100 Subject: [PATCH 1/2] docs: add warning and improve error log --- .../src/client/index.ts | 13 ++++++++++--- website/docs/blog.mdx | 6 ++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/client/index.ts b/packages/docusaurus-plugin-content-docs/src/client/index.ts index 335729b898fd..5d72d657f4ed 100644 --- a/packages/docusaurus-plugin-content-docs/src/client/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/client/index.ts @@ -143,9 +143,16 @@ export function useActiveVersion( export function useActiveDocContext( pluginId: string | undefined, ): ActiveDocContext { - const data = useDocsData(pluginId); - const {pathname} = useLocation(); - return getActiveDocContext(data, pathname); + try { + const data = useDocsData(pluginId); + const {pathname} = useLocation(); + return getActiveDocContext(data, pathname); + } catch (error) { + throw new Error( + 'It seems that you are using a doc plugin feature while the doc plugin seems to be disabled in `docusaurus.config.js`.', + error as Error, + ); + } } /** * Useful to say "hey, you are not on the latest docs version, please switch" diff --git a/website/docs/blog.mdx b/website/docs/blog.mdx index 43a0c23a53d2..cd0a3dad9440 100644 --- a/website/docs/blog.mdx +++ b/website/docs/blog.mdx @@ -625,6 +625,12 @@ Don't forget to delete the existing homepage at `./src/pages/index.js` or else t ::: +:::warning + +Don't forget to delete element of type doc in `docusaurus.config.js` in the navbar for example or else Docusaurus will crash. + +::: + :::tip There's also a "Docs-only mode" for those who only want to use the docs. Read [Docs-only mode](./guides/docs/docs-introduction.mdx) for detailed instructions or a more elaborate explanation of `routeBasePath`. From 4414a5f3d895010a9e9f395aea5c5e7869b6b0e0 Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Fri, 9 Feb 2024 18:02:38 +0100 Subject: [PATCH 2/2] refactor --- .../src/client/index.ts | 31 ++++++++++--------- website/docs/blog.mdx | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/client/index.ts b/packages/docusaurus-plugin-content-docs/src/client/index.ts index 5d72d657f4ed..32dd0d926133 100644 --- a/packages/docusaurus-plugin-content-docs/src/client/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/client/index.ts @@ -86,10 +86,20 @@ export const useAllDocsData = (): {[pluginId: string]: GlobalPluginData} => } | undefined) ?? StableEmptyObject; -export const useDocsData = (pluginId: string | undefined): GlobalPluginData => - usePluginData('docusaurus-plugin-content-docs', pluginId, { - failfast: true, - }) as GlobalPluginData; +export const useDocsData = (pluginId: string | undefined): GlobalPluginData => { + try { + return usePluginData('docusaurus-plugin-content-docs', pluginId, { + failfast: true, + }) as GlobalPluginData; + } catch (error) { + throw new Error( + `You are using a feature of the Docusaurus docs plugin, but this plugin does not seem to be enabled${ + pluginId === 'Default' ? '' : ` (pluginId=${pluginId}` + }`, + {cause: error as Error}, + ); + } +}; // TODO this feature should be provided by docusaurus core export function useActivePlugin( @@ -143,16 +153,9 @@ export function useActiveVersion( export function useActiveDocContext( pluginId: string | undefined, ): ActiveDocContext { - try { - const data = useDocsData(pluginId); - const {pathname} = useLocation(); - return getActiveDocContext(data, pathname); - } catch (error) { - throw new Error( - 'It seems that you are using a doc plugin feature while the doc plugin seems to be disabled in `docusaurus.config.js`.', - error as Error, - ); - } + const data = useDocsData(pluginId); + const {pathname} = useLocation(); + return getActiveDocContext(data, pathname); } /** * Useful to say "hey, you are not on the latest docs version, please switch" diff --git a/website/docs/blog.mdx b/website/docs/blog.mdx index cd0a3dad9440..1fb3ace11c1b 100644 --- a/website/docs/blog.mdx +++ b/website/docs/blog.mdx @@ -627,7 +627,7 @@ Don't forget to delete the existing homepage at `./src/pages/index.js` or else t :::warning -Don't forget to delete element of type doc in `docusaurus.config.js` in the navbar for example or else Docusaurus will crash. +If you disable the docs plugin, don't forget to delete references to the docs plugin elsewhere in your configuration file. Notably, make sure to remove the docs-related navbar items. :::