-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Sidebar.js Doesn't Gracefully Ignore Unknown Props #3787
Comments
Hi, Not totally sure to understand what you are trying to do, but you can write your sidebar in any format you want. What matters is that you feed Docusaurus with the correct json format, but you can write your sidebar in yaml and transform it to json with js code if you want to. We forbid unknown keys. because we want to fail-fast, avoid bad configs, typos etc... it's more a feature than a bug. If you want to add a key to your custom sidebar config format, you can, but you'll have to strip those keys. module.exports = removeKeys(myCustomJsonSidebarFormat) If that helps, here's a generic fn we have to transform sidebars:
|
We're trying to programatically update the sidebars.js when adding a new docs page, since this will be done via an Nx schematic. e.g.
would run the create doc schematic, adding a I suppose based on the info you provided, our best bet would be to have a separate "source of truth" (sidebars.schema.js or something like that) that includes the additional meta data we need to programatically transform it when adding a new doc, then as a second step after adding a new doc to the tree, we would convert that source of truth file into the actual sidebars.js, adhering to the Docusaurus structure. Thank you for the info! :) |
yes that's it you could do import myCustomSidebar from "myCustomSidebar.json"
export default removeKeys(myCustomSidebar); Quite related to this other issues where users would like to auto generate the sidebar according to the FS structure, with some potential userland solutions: #3464 Important note: when versioning docs, we snapshot using the docusaurus sidebar format as json, we don't run your custom code on versioned docs anymore (but some users were interested by this option here #3285 (comment)) |
FYI we may allow passing arbitrary attributes, as it can also be useful when you want to customize the theme (ie the theme should receive the attributes too). Let's track it here: #3787 |
🐛 Bug Report
If you add an unknown prop to an otherwise valid saidebars.js, instead of gracefully ignoring the props, the build fails.
Reasoning/Issue This Causes Us
We are using Docusaurus within an Nx monorepo and we want to create a schematic that will auto generate a new docs page and update the sidebar. To do this, we will need to programatically identify which category to add the new docs page into, but without a key, we'd need to rely on the user-facing label. Adding a key property to the sidebar categories would allow us to do that easily, but that breaks Docusaurus.
Our sidebars.js structure:
We plan on adding more categories for libraries, hooks, etc as we go so being able to uniquely identify each category at any level of the sidebar tree without relying on the user-friendly label would be very helpful.
To Reproduce
key
)Expected behavior
The docs should still compile, gracefully ignoring the unknown prop.
Actual Behavior
The docs error, breaking the build.
Error message:
Your Environment
Reproducible Demo
I forked the repo and updated the facebook example to use the categories format to show that works:
https://github.com/justinryder/docusaurus/blob/sidebar-category-working-example/examples/facebook/sidebars.js
Then I updated that working example to add an unknown key to show the bug:
https://github.com/justinryder/docusaurus/blob/sidebar-category-bug-example/examples/facebook/sidebars.js
The text was updated successfully, but these errors were encountered: