Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow preset to nullify theme-provided components overriden by preset plugins #6488

Closed
2 of 7 tasks
reutenkoivan opened this issue Jan 27, 2022 · 5 comments
Closed
2 of 7 tasks
Labels
feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.

Comments

@reutenkoivan
Copy link

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

If you are using "theme" parameter instead of "preset" it's not possible to include custom UI components registered by "getThemePath" method from plugins.

Steps to reproduce

  1. clone this repository
  2. cd website
  3. yarn
  4. yarn build
  5. yarn serve
  6. open http://localhost:3000/
  7. You don't see search input

Expected behavior

  1. go to <root>/website/node_modules/@docusaurus/core/lib/server/index.js
  2. change return from loadPluginConfigs to
return [
        ...presetThemes,
        ...presetPlugins,
        ...standaloneThemes,
        ...standalonePlugins,
    ]
  1. yarn build
  2. yarn serve
  3. now you can see search input

Actual behavior

it happening because in this line alias from plugin overriding by alias from theme-classic.

// themePaths ==== [
//   '@docusaurus/core/lib/client/theme-fallback',
//   '@easyops-cn/docusaurus-search-local/dist/client/client/theme',
//   '@docusaurus/theme-classic/lib-next/theme'
// ]
// returns from "loadThemeAliases"
// {
// --- other aliases---
//   '@theme/SearchBar/EmptyTemplate': '@easyops-cn/docusaurus-search-local/dist/client/client/theme/SearchBar/EmptyTemplate.js',
//   '@theme/SearchBar/SearchBar': '@easyops-cn/docusaurus-search-local/dist/client/client/theme/SearchBar/SearchBar.jsx',
//   '@theme/SearchBar/SuggestionTemplate': '@easyops-cn/docusaurus-search-local/dist/client/client/theme/SearchBar/SuggestionTemplate.js',
//   '@theme/SearchBar/__mocks__/icons': '@easyops-cn/docusaurus-search-local/dist/client/client/theme/SearchBar/__mocks__/icons.js',
//   '@theme/SearchBar/fetchIndexes': '@easyops-cn/docusaurus-search-local/dist/client/client/theme/SearchBar/fetchIndexes.js',
//   '@theme/SearchBar/icons': '@easyops-cn/docusaurus-search-local/dist/client/client/theme/SearchBar/icons.js',
//   '@theme/SearchBar': '@docusaurus/theme-classic/lib-next/theme/SearchBar.js',  <--- Wrong alias
// --- other aliases---
// }

Your environment

  • Public source code:
  • Public site URL:
  • Docusaurus version used: 2.0.0-beta.15
  • Environment name and version (e.g. Chrome 89, Node.js 16.4):
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS):

Reproducible demo

No response

Self-service

  • I'd be willing to fix this bug myself.
@reutenkoivan reutenkoivan added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Jan 27, 2022
@Josh-Cena Josh-Cena added closed: working as intended This issue is intended behavior, there's no need to take any action. and removed status: needs triage This issue has not been triaged by maintainers labels Jan 28, 2022
@Josh-Cena
Copy link
Collaborator

Hey, this is surprising, but working as intended. We want plugin default themes to be overridable by external themes, so the best we can do is always give themes a higher precedence than plugins. If you want to provide themes in your plugin, don't bundle it in your preset with a theme you are trying to override.

I do think something can be done here, for example, the ability for a preset to nullify part of the theme a plugin provides—but of course, we will not tweak the theme loading order. This has already been documented/specced.

@Josh-Cena Josh-Cena changed the title Default theme-classic components override UI components from plugins Allow preset to nullify theme-provided components overriden by preset plugins Jan 28, 2022
@Josh-Cena Josh-Cena added feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. and removed bug An error in the Docusaurus core causing instability or issues with its execution closed: working as intended This issue is intended behavior, there's no need to take any action. labels Jan 28, 2022
@slorber
Copy link
Collaborator

slorber commented Jan 28, 2022

@weareoutman I suggest you present your Docusaurus search plugin as a theme instead of a plugin.

We have docusaurus-theme-search-algolia, and your plugin is similar so it would be better to do the same.

There are not a lot of differences between themes and plugins apart this aliasing ordering.

@reutenkoivan this should work:

  plugins: [
    [
      '@docusaurus/plugin-content-docs',
      {
        path: path.join(__dirname, 'docs'),
        routeBasePath: '/'
      },
    ],
  ],
  themes: [
    ['@docusaurus/theme-classic', {customCss: [require.resolve('./src/css/custom.css')]}],
    '@easyops-cn/docusaurus-search-local',
  ],

@weareoutman
Copy link
Contributor

@slorber Thanks and I just updated our docs about using it as a theme.

@slorber
Copy link
Collaborator

slorber commented Feb 2, 2022

Thanks 👍 I guess we can close now, unless someone reports another use-case

@slorber slorber closed this as completed Feb 2, 2022
@kaushal0107
Copy link

kaushal0107 commented Feb 9, 2023

@weareoutman Thanks for the Theme.
I configured it on my Docusaurus setup from https://github.com/easyops-cn/docusaurus-search-local .
But after Building I'm getting following error.
search-index.json not found
there is no such thing mentioned in the steps.
Please guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.
Projects
None yet
Development

No branches or pull requests

5 participants