-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
feat: add support for browser-based theme config file (docusaurus.theme.js) #9619
base: main
Are you sure you want to change the base?
Conversation
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
⚡️ Lighthouse report for the deploy preview of this PR
|
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.
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 |
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. |
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: export default {
navbar: {
items: [
{
component: React.lazy(() => import("@site/components/navbar/MyNavbarItem")),
props: { someProp: 42 },
isActive: (params) =>
(params.location.pathname === "/"
|| (params.plugin.name === "docs" && params.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
Motivation
Add support for a new browser
docusaurus.theme.tsx
file 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.themeConfig
and 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/