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

Presets allow illegal option attributes #4239

Closed
slorber opened this issue Feb 17, 2021 · 0 comments · Fixed by #5831
Closed

Presets allow illegal option attributes #4239

slorber opened this issue Feb 17, 2021 · 0 comments · Fixed by #5831
Labels
bug An error in the Docusaurus core causing instability or issues with its execution mlh Major League Hacking Fellowship status: claimed Issue has been claimed by a contributor who plans to work on it.

Comments

@slorber
Copy link
Collaborator

slorber commented Feb 17, 2021

This issue is for Major League Hacking fellows only.

🐛 Bug Report

Docusaurus aims to be "fail-fast" and validate strictly the configuration to prevent user mistakes.

We have found that some user sites are using wrong preset configs by mistake:
https://github.com/facebookincubator/CG-SQL/blob/master/website/docusaurus.config.js#L129

presets: [
    [
      '@docusaurus/preset-classic',
      {
        // ...
        googleAnalytics: {
          // ...
        },
       // ...
      },
    ],
  ],

The mistake here is that googleAnalytics should be a themeConfig attribute, not a preset option. This lead to a site running in production without Google Analytics.

We should prevent users to do such mistakes and reject such bad configuration.

We have a way for plugins to validate their own options, but we don't have this for presets.
I don't think we need that for presets because the presets just "forward" their options to plugins, and the options end up being validated strictly.

The problem is mostly for "unknown preset attributes" that are silently ignored.

Solution

Keep it simple, no need for a new lifecycle.
Just modify packages/docusaurus-preset-classic/src/index.js

If the preset options object contains unknown keys that are not forwarded to any preset plugin then those keys should be rejected with a user-friendly error message

@slorber slorber added bug An error in the Docusaurus core causing instability or issues with its execution status: claimed Issue has been claimed by a contributor who plans to work on it. mlh Major League Hacking Fellowship labels Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution mlh Major League Hacking Fellowship status: claimed Issue has been claimed by a contributor who plans to work on it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant