Skip to content

"Docs plugin enabled" detection no longer does anything #7207

@Josh-Cena

Description

@Josh-Cena

Because theme-common has a direct dependency on plugin-content-docs, it is no longer possible to make a site without ever installing content-docs (previously discussed in #3360). Not really a big deal because the user can still install theme-classic and plugin-content-blog and pretend she never pulls in content-docs transitively, but it's still not desirable.

We have some checks in our codebase about whether docs is enabled:

// TODO not ideal, see also "useDocs"
export const isDocsPluginEnabled: boolean = !!useAllDocsData;

const NavbarItemComponents: {
// Not really worth typing, as we pass all props down immediately
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[type in Exclude<Types, undefined>]: () => (props: any) => JSX.Element;
} = {
default: () => DefaultNavbarItem,
localeDropdown: () => LocaleDropdownNavbarItem,
search: () => SearchNavbarItem,
dropdown: () => DropdownNavbarItem,
html: () => HtmlNavbarItem,
// Need to lazy load these items as we don't know for sure the docs plugin is
// loaded. See https://github.com/facebook/docusaurus/issues/3360
/* eslint-disable @typescript-eslint/no-var-requires, global-require */
docsVersion: () => require('@theme/NavbarItem/DocsVersionNavbarItem').default,
docsVersionDropdown: () =>
require('@theme/NavbarItem/DocsVersionDropdownNavbarItem').default,
doc: () => require('@theme/NavbarItem/DocNavbarItem').default,
docSidebar: () => require('@theme/NavbarItem/DocSidebarNavbarItem').default,
/* eslint-enable @typescript-eslint/no-var-requires, global-require */
} as const;

Because we are now always directly importing these hooks from @docusaurus/plugin-content-docs/client instead of letting the docs plugin register theme aliases, these things always statically exist. We should either remove the checks, or dynamically import content-docs/client everywhere (better IMO in terms of bundle size)

Metadata

Metadata

Assignees

No one assigned

    Labels

    better engineeringNot a bug or feature requestdomain: themeRelated to the default theme components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions