Skip to content

refactor(v2): add useThemeConfig hook + cleanup useless theme default values#3394

Merged
slorber merged 8 commits into
facebook:masterfrom
imskr:skr-destruct
Oct 2, 2020
Merged

refactor(v2): add useThemeConfig hook + cleanup useless theme default values#3394
slorber merged 8 commits into
facebook:masterfrom
imskr:skr-destruct

Conversation

@imskr

@imskr imskr commented Sep 3, 2020

Copy link
Copy Markdown
Contributor

Motivation

Have you read the Contributing Guidelines on pull requests?

  • Yes

Test Plan

  • yarn test docusaurus-theme-classic

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@imskr imskr requested a review from lex111 as a code owner September 3, 2020 06:44
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Sep 3, 2020
@docusaurus-bot

docusaurus-bot commented Sep 3, 2020

Copy link
Copy Markdown
Contributor

Deploy preview for docusaurus-2 ready!

Built with commit 65b262a

https://deploy-preview-3394--docusaurus-2.netlify.app

@imskr

imskr commented Sep 3, 2020

Copy link
Copy Markdown
Contributor Author

@slorber tests are failing. Looks like I've done it the wrong way!

Comment thread packages/docusaurus-theme-classic/src/theme/AnnouncementBar/index.tsx Outdated
@imskr

imskr commented Sep 6, 2020

Copy link
Copy Markdown
Contributor Author

Fixed it! Is it good? @slorber

@slorber slorber changed the title refactor(theme-classic): clean default or fallback values refactor(v2): clean default or fallback values Sep 10, 2020

@slorber slorber left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @imskr that almost look good.But there is a place where you read title/scroll config from themeConfig instead of navbar.

According to the current theme validation config (lack of required/default value), navbar can be null. Can you test whether or not it is possible to run a docusaurus site (on master) with navbar = null in config? If the site fails, we can safely add a required() to the Joi schema here and prevent this mistake, but if it works, we should maybe account for this and ensure that we don't destructure navbar before a null check. Config errors should all be thrown ahead of time with validation system.

Also, I think it's worth creating a "useClassicThemeConfig" hook to simplify a bit the code. Can you add it and type it with any returntype for now? We'll figure out to type it better after and how to keep it in sync with the Joi schema in another PR (you can put a // TODO improve typing)

} = {},
isClient,
} = useDocusaurusContext();
const {title, hideOnScroll} = useDocusaurusContext().siteConfig.themeConfig;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong to me, as before the title/hideOnScroll should be read on navbar, not themeConfig.
(take care, navbar can be null)

} = {},
} = useDocusaurusContext();
hideOnScroll = false,
} = useDocusaurusContext().siteConfig.themeConfig.navbar;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

navbar can be null (see Joi validation, there is no .require() call nor .default() so it is optional)

title,
items = [],
hideOnScroll = false,
} = useDocusaurusContext().siteConfig.themeConfig.navbar;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

navbar can be null

@slorber

slorber commented Sep 30, 2020

Copy link
Copy Markdown
Collaborator

Hi @imskr . Do you want me to complete this PR and merge it?

@imskr

imskr commented Sep 30, 2020

Copy link
Copy Markdown
Contributor Author

Hi @imskr . Do you want me to complete this PR and merge it?

Sorry couldn't find time. Yes, please Thank you

@slorber

slorber commented Oct 2, 2020

Copy link
Copy Markdown
Collaborator

thanks @imskr I finished the work and merging the PR now

@slorber slorber changed the title refactor(v2): clean default or fallback values refactor(v2): add useThemeConfig hook + cleanup useless theme default values Oct 2, 2020
@slorber slorber added the pr: maintenance This PR does not produce any behavior differences to end users when upgrading. label Oct 2, 2020
@slorber slorber merged commit 0951eef into facebook:master Oct 2, 2020
mrizwanashiq pushed a commit to mrizwanashiq/docusaurus that referenced this pull request Jun 25, 2026
… values (facebook#3394)

* refactor(theme-classic): clean default or fallback values

* refactor(theme-classic): fix announcementbar undefined error

* refactor(theme-classic): fixed react hook warning error

* refactor(theme-classic): revert prism destruct

* create useThemeConfig and use it whenever possible

* validateThemeConfig => add [] as default value for almost all arrays

* fix tests

Co-authored-by: slorber <lorber.sebastien@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA pr: maintenance This PR does not produce any behavior differences to end users when upgrading.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cleanup themes default/fallback values

4 participants