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

fix(v2): Added back support for optional logo field in theme-classic navbarConfig #3611

Merged
merged 3 commits into from
Oct 21, 2020
Merged

fix(v2): Added back support for optional logo field in theme-classic navbarConfig #3611

merged 3 commits into from
Oct 21, 2020

Conversation

SamChou19815
Copy link
Contributor

Motivation

Fix #3610.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Comment out the logo field in docusaurus website's docusaurus.config.js, like:

  // ...
  navbar: {
      hideOnScroll: true,
      title: 'Docusaurus',
      /* logo: {
        alt: 'Docusaurus Logo',
        src: 'img/docusaurus.svg',
        srcDark: 'img/docusaurus_keytar.svg',
      },
      */
  // ...
  }

Without this change, site will crash:
Screen Shot 2020-10-19 at 14 56 12

With this change, site will load as usual, without the logo:
Screen Shot 2020-10-19 at 14 55 59

Related PRs

N/A

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Oct 19, 2020
Copy link
Contributor

@lex111 lex111 left a comment

Choose a reason for hiding this comment

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

Maybe we can make the logo object optional in the validation scheme?

logo: Joi.object({
alt: Joi.string().allow(''),
src: Joi.string().required(),
srcDark: Joi.string(),
href: Joi.string(),
target: Joi.string(),
}),

@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Oct 19, 2020

Deploy preview for docusaurus-2 ready!

Built without sensitive environment variables with commit bf593e0

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

@SamChou19815
Copy link
Contributor Author

SamChou19815 commented Oct 19, 2020

Maybe we can make the logo object optional in the validation scheme?

logo: Joi.object({
alt: Joi.string().allow(''),
src: Joi.string().required(),
srcDark: Joi.string(),
href: Joi.string(),
target: Joi.string(),
}),

I think it's already optional here, since there is no .required() for this object, and my build failed with SSR error due to this bug instead of validation error.

@lex111 Oh I see your point. I have moved the default value to the config validation code.

@SamChou19815
Copy link
Contributor Author

Reverted to the old logo = {} approach in useLogo.ts. Making {} as default value doesn't work since the validator expects logo.src to be nonnull.

@lex111
Copy link
Contributor

lex111 commented Oct 19, 2020

Hmm, wouldn't the optional() work in our case?

 logo: Joi.object({ 
   alt: Joi.string().allow(''), 
   src: Joi.string().required(), 
   srcDark: Joi.string(), 
   href: Joi.string(), 
   target: Joi.string(), 
 }).optional(), 

@SamChou19815
Copy link
Contributor Author

Hmm, wouldn't the optional() work in our case?

 logo: Joi.object({ 
   alt: Joi.string().allow(''), 
   src: Joi.string().required(), 
   srcDark: Joi.string(), 
   href: Joi.string(), 
   target: Joi.string(), 
 }).optional(), 

I think optional is already the default, so adding optional doesn't help at all.

@slorber
Copy link
Collaborator

slorber commented Oct 20, 2020

My mistake, didn't see this code could fail.

@SamChou19815 the idea of the PR was to remove all the default values from the theme, so I'd rather avoid reintroducing "logo = {}" in the theme.

The following does not work?

 logo: Joi.object({ 
   alt: Joi.string().allow(''), 
   src: Joi.string().required(), 
   srcDark: Joi.string(), 
   href: Joi.string(), 
   target: Joi.string(), 
 }).default({}), 

Afaik the default value is not run against the validators by Joi

@SamChou19815
Copy link
Contributor Author

@slorber I tried this approach in the first few commits, but it failed tests.

Currently, the src field in logo field is required. If we simply add .default({}). It will complain about src missing.

logo: Joi.object({
alt: Joi.string().allow(''),
src: Joi.string().required(),
srcDark: Joi.string(),
href: Joi.string(),
target: Joi.string(),
}),

If we want to add .default({}), we also need make src field optional, which is what the client code in useLogo.ts implicitly implied and it doesn't really make sense.

@slorber slorber added the pr: bug fix This PR fixes a bug in a past release. label Oct 21, 2020
@slorber
Copy link
Collaborator

slorber commented Oct 21, 2020

Ok so let's merge it this way for now, and we'll figure out how to refactor this useLogo hook later

@slorber slorber merged commit 003b457 into facebook:master Oct 21, 2020
@SamChou19815 SamChou19815 deleted the fix-3610 branch October 21, 2020 13:36
@lex111 lex111 added this to the v2.0.0-alpha.67 milestone Nov 17, 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: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v2] Alpha 66 breaks classic site without logo
5 participants