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(theme-classic): allow tabs with number as value #5732

Merged
merged 6 commits into from
Oct 21, 2021

Conversation

Josh-Cena
Copy link
Collaborator

@Josh-Cena Josh-Cena commented Oct 18, 2021

Motivation

Fix #5729. I'm not sure if we should remove the check for value entirely, but let's just trust the users more since we don't know what they will present.

Edit. The issue is just caused by a too strict type check. Widening the checking solved it.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Fixed test cases

@netlify
Copy link

netlify bot commented Oct 18, 2021

✔️ [V2]
Built without sensitive environment variables

🔨 Explore the source changes: fb8e7cf

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/6170c360b6aa780008f865a6

😎 Browse the preview: https://deploy-preview-5732--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Oct 18, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟢 Performance 94
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-5732--docusaurus-2.netlify.app/

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.

Isn't there another solution where we keep this check?

throw new Error(
`Docusaurus error: Bad <Tabs> child <${
// @ts-expect-error: guarding against unexpected cases
typeof child.type === 'string' ? child.type : child.type.name
Copy link
Collaborator

Choose a reason for hiding this comment

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

Error: Docusaurus error: Bad child : all children of the component should be , and every should have a unique "value" prop.

=> should not print "undefined", maybe child.type.name is wrong or does not work in all cases?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This I'm actually not sure. I think it's because they're using the staging preview which is prod, so the name info is gone.

@@ -37,24 +25,11 @@ function TabsComponent(props: Props): JSX.Element {
groupId,
className,
} = props;
const children = Children.map(props.children, (child) => {
if (isValidElement(child) && isTabItem(child)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMHO the real problem is in this test: it should pass but for some reason doesn't. Wonder what is child. I expect it to be a tab but maybe React does a weird thing and gives an array?

Maybe use Children.toArray at the beginning?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note this might break because the user is using dynamic tabs with a single element in the array.

image

Children.map may return a single mapped element here, instead of an array

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I actually don't know how Children.toArray or Children.map operates. I suppose you know more about React than I do🤪 Any materials that cover this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ugh, it's because of a very dumb thing: their value is a number, not a string.

https://github.com/mit-dormcon/website/blame/broken-tabs/docs/archive.mdx#L19

I think we should just widen the check to typeof comp.props.value !== 'undefined'. Thanks for compelling me to look deeper into this😄

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah 😄 great you could find the cause

Signed-off-by: Josh-Cena <[email protected]>
Signed-off-by: Josh-Cena <[email protected]>
Signed-off-by: Josh-Cena <[email protected]>
@Josh-Cena Josh-Cena changed the title fix(theme-classic): allow dynamic tabs configuration fix(theme-classic): allow tabs with number as value Oct 21, 2021
@slorber
Copy link
Collaborator

slorber commented Oct 21, 2021

LGTM 👍

@slorber slorber added the pr: bug fix This PR fixes a bug in a past release. label Oct 21, 2021
@slorber slorber merged commit c2eda4a into facebook:main Oct 21, 2021
@Josh-Cena Josh-Cena deleted the tabs-fix branch October 21, 2021 10:45
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.

Dynamic tabs configuration doesn't work with 2.0.0-beta.7
3 participants