Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Draft
OzakIOne wants to merge13 commits intofacebook:main
base:main
Choose a base branch
Loading
fromOzakIOne:ozaki/themeconfig

Conversation

@OzakIOne
Copy link
Contributor

@OzakIOneOzakIOne commentedDec 7, 2023
edited by slorber
Loading

Motivation

Add support for a new browserdocusaurus.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 serializedsiteConfig.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/

@facebook-github-botfacebook-github-bot added the CLA SignedSigned Facebook CLA labelDec 7, 2023
@netlify
Copy link

netlifybot commentedDec 7, 2023
edited
Loading

[V2]

Builtwithout sensitive environment variables

NameLink
🔨 Latest commit161c727
🔍 Latest deploy loghttps://app.netlify.com/sites/docusaurus-2/deploys/65858c5920ff8200085bedcc
😎 Deploy Previewhttps://deploy-preview-9619--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to yourNetlify site configuration.

@github-actions
Copy link

github-actionsbot commentedDec 7, 2023
edited
Loading

⚡️ Lighthouse report for the deploy preview of this PR

URLPerformanceAccessibilityBest PracticesSEOPWAReport
/🟠 69🟢 98🟢 100🟢 100🟠 89Report
/docs/installation🟢 90🟢 98🟢 100🟢 100🟠 89Report
/docs/category/getting-started🟠 76🟢 100🟢 100🟢 90🟠 89Report
/blog🟠 68🟢 100🟢 100🟢 90🟠 89Report
/blog/preparing-your-site-for-docusaurus-v3🟠 65🟢 97🟢 100🟢 100🟠 89Report
/blog/tags/release🟢 95🟢 100🟢 100🟠 80🟠 89Report
/blog/tags🟠 74🟢 100🟢 100🟢 90🟠 89Report

@slorberslorber added pr: new featureThis PR adds a new API or behavior. to backportThis PR is planned to be backported to a stable version of Docusaurus labelsDec 7, 2023
Copy link
Collaborator

@Josh-CenaJosh-Cena left a 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.

@slorberslorber changed the titlefeat: theme configfeat: add support for browser-based theme config file (docusaurus.theme.js)Dec 7, 2023
@slorber
Copy link
Collaborator

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

@Josh-Cena
Copy link
Collaborator

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
Copy link
Collaborator

slorber commentedDec 8, 2023
edited
Loading

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" likeBeforeBlogSidebar because swizzle wrap is a good alternative to add a component above/under an existing one. Swizzle remains a useful tool for these scenarios.


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"&&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: {
Copy link
ContributorAuthor

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
Copy link

+1 for Theming: use custom components as navbar/sidebar/footer items

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@Josh-CenaJosh-CenaJosh-Cena left review comments

@slorberslorberAwaiting requested review from slorberslorber will be requested when the pull request is marked ready for reviewslorber is a code owner

Assignees

No one assigned

Labels

CLA SignedSigned Facebook CLApr: new featureThis PR adds a new API or behavior.to backportThis PR is planned to be backported to a stable version of Docusaurus

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@OzakIOne@slorber@Josh-Cena@100tomer@facebook-github-bot

[8]ページ先頭

©2009-2025 Movatter.jp