Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
feat: add support for browser-based theme config file (docusaurus.theme.js)#9619
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
netlifybot commentedDec 7, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
✅ [V2]Builtwithout sensitive environment variables
To edit notification comments on pull requests, go to yourNetlify site configuration. |
github-actionsbot commentedDec 7, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
⚡️ Lighthouse report for the deploy preview of this PR
|
Josh-Cena left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'm not sure if this is the right design, but I also don't know if I have much to say.
We have always said "all config files you write are server-side; client-side customizations are to be done through swizzling and custom CSS". And indeed, I don't see how announcement/footer items can't be done through safe swizzling. This just seems like one extra way to do things.
slorber commentedDec 7, 2023
Here this is not only theme customizations but also theme extensions. You shouldn't need to swizzle to provide custom mdx components, navbar items, or simply use callbacks to enable/disable navbar items. Too often we encounter limits due to unserializable configs. Swizzle remains the way to customize existing theme components, but here the goal is not really to customize existing components. This design is already widely used by other tools, for example:https://nextra.site/docs/docs-theme/theme-configuration |
Josh-Cena commentedDec 7, 2023
Okay, fair enough. One or two years ago, our plan was still to provide "dummy components" that one could swizzle and inject additional logic, but maybe this is fine too. |
slorber commentedDec 8, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
As far as I remember, we decided that it was not needed to have such "dummy components" like With this new proposal, the goal is to give another way to customize that is not super well covered by swizzle. For example: exportdefault{navbar:{items:[{component:React.lazy(()=>import("@site/components/navbar/MyNavbarItem")),props:{someProp:42},isActive:(params)=>(params.location.pathname==="/"||(params.plugin.name==="docs"&¶ms.plugin.id==="default"))},],},mdxComponents:{a:React.lazy(()=>import("@site/components/MyCustomMarkdownLink"))MyComp:React.lazy(()=>import("@site/components/MyComp"))},}; This should allow to integrate with Suspense and make it easier to code split and lazy load custom components on demand as user navigates, instead of loading all of them upfront eagerly. |
| const isDev = process.env.NODE_ENV === 'development'; | ||
| export default { | ||
| announcementBar: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
process is not defined for agolia however no error reported for navbar Debug label with isDev
100tomer commentedMar 9, 2025
+1 for Theming: use custom components as navbar/sidebar/footer items |
Uh oh!
There was an error while loading.Please reload this page.
Motivation
Add support for a new browser
docusaurus.theme.tsxfile to declare the Docusaurus theme config.Using a browser-based file unlocks many other features, including the ability to pass unserializable data such as React components and callbacks.
Some features it unlocks, or improves the DX:
This feature is designed to be v3 retro-compatible and easy to adopt incrementally. The new theme config gets merged into the old serialized
siteConfig.themeConfigand it's possible to slowly migrate your theme config to the new file.Test Plan
unit tests + dogfood + preview
Test links
https://deploy-preview-9619--docusaurus-2.netlify.app/