Skip to content
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

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

Merged
merged 8 commits into from
Oct 2, 2020

Conversation

imskr
Copy link
Contributor

@imskr imskr commented Sep 3, 2020

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

docusaurus-bot commented Sep 3, 2020

Deploy preview for docusaurus-2 ready!

Built with commit 65b262a

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

@imskr
Copy link
Contributor Author

imskr commented Sep 3, 2020

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

@imskr
Copy link
Contributor Author

imskr commented Sep 6, 2020

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

@slorber slorber left a comment

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

slorber commented Sep 30, 2020

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

@imskr
Copy link
Contributor Author

imskr commented Sep 30, 2020

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

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

@slorber
Copy link
Collaborator

slorber commented Oct 2, 2020

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