Repository navigation
polish(theme-classic): guard against potential definition mistakes in Tabs - #5674
Conversation
|
✔️ [V2] 🔨 Explore the source changes: 6b76bc9 🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/6167fc0fef601400075a9148 😎 Browse the preview: https://deploy-preview-5674--docusaurus-2.netlify.app |
|
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-5674--docusaurus-2.netlify.app/ |
defaultValue is nonexistentdefaultValue is nonexistent + check for children type
defaultValue is nonexistent + check for children typedefaultValue is nonexistent + check for children type
defaultValue is nonexistent + check for children type916ad4e to
1fa5775
Compare
1fa5775 to
c399614
Compare
That's just the same as not providing the prop: we search in the children for |
| * @param comparator Compares two values and returns `true` if they are equal (duplicated). | ||
| * @returns Value of the elements `v` that have a preceding element `u` where `comparator(u, v) === true`. Values within the returned array are not guaranteed to be unique. | ||
| */ | ||
| export function getDuplicateValues<T>( |
There was a problem hiding this comment.
I'd suggest reusing method names from lodash for simplicity: intersection / intersectionBy would be a more powerful abstraction:
Also adding a little test for it with/without iteratee/comparator
There was a problem hiding this comment.
Actually—I've never used Lodash myself and I kind of feel lucky that I never got into Lodash's mindset🌚
I fail to see how intersection is related to getDuplicateValues though, since mine is only working on one array
There was a problem hiding this comment.
Actually—I've never used Lodash myself and I kind of feel lucky that I never got into Lodash's mindset🌚
Not sure what you mean here. Lodash is a bit heavy for frontend but it remains a powerful abstraction to achieve many data transformations. JS is improving and adding some Lodash-like methods over time.
I fail to see how intersection is related to getDuplicateValues though, since mine is only working on one array
Oh you are right I'm dumb 🤪 this is a different API and Lodash doesn't have anything for duplicates
There was a problem hiding this comment.
Lodash is a bit heavy for frontend but it remains a powerful abstraction to achieve many data transformations.
Yeah, just meant that when I think of algorithms, I directly think in ES array methods, not the Lodash arsenal.
There was a problem hiding this comment.
What I mean is that they thought about method names carefully. If something does not exist in JS and exist in Lodash, reusing method name of lodash (or at least getting some inspiration) is not a bad idea.
There's nothing related to duplicates in lodash afaik so not applicable in this case.
Still I'd probably not name it as getDuplicateValues because it's not a method name that looks like any lodash or native JS array method name either. I'd rather name it simply duplicates
| </>, | ||
| ); | ||
| }).toMatchInlineSnapshot(`[Function]`); // This is just a check that the function returns. We don't care about the actual DOM. | ||
| }); |
There was a problem hiding this comment.
What about adding a test to cover that <CustomTabItem value="1"/> would lead to the same final JSX (non-shallow) than <TabItem value="1"/>
I don't think we dogfood this case on our site yet so it's worth adding it to ensure this behavior remains possible over time
Thanks for adding those tests BTW, we need to start somewhere 😅
There was a problem hiding this comment.
I don't really understand what magic a CustomTabItem could do🧐 There's no styling / logic here anyways—is there a use-case?
There was a problem hiding this comment.
Users could decorate a tab with a BrowserWindow comp or whatever they want, and add extra logic if they want.
This should work (and used to work)
<CustomTabs>
<CustomTabItem value="v1">Tab 1</CustomTabItem>
<CustomTabItem value="v2">Tab 2</CustomTabItem>
</CustomTabs>This should also work but would be more verbose:
<Tabs>
<TabItem value="v1">
<BrowserWindow>Tab 1</BrowserWindow>
</TabItem>
<TabItem value="v2">
<BrowserWindow>Tab 2</BrowserWindow>
</TabItem>
</Tabs>I'd like to add a new MDX infra so that themes and sites can register MDX shortcodes without any need to import anything:
<tabs>
<tab-item value="v1" link="https://tab1link.com">
Tab 1
</tab-item>
<tab-item value="v2" link="https://tab2link.com">
Tab 2
</tab-item>
</tabs>tab-item could be replaced by MDX by:
function CustomTabItem({ children, link }) {
return (
<TabItem>
<BrowserWindow>
<div>{children}</div>
<footer>
<Link to={link}>Tab link</Link>
</footer>
</BrowserWindow>
</TabItem>
);
}That's why we must ensure that this behavior is preserved other time
There was a problem hiding this comment.
Okay, I see. react-test-renderer renders the JSX to actual DOM, so if we are to verify the rendering result, we get HTML. Do you just want to check it gets accepted, or do you want the actual DOM to match (which I can't see... why it would not)?
There was a problem hiding this comment.
Actually, as I went down the rabbit hole, verifying it works and getting the DOM structure is non-trivial, because it's hooked into complicated things like docusaurus context and some scroll position utils🧐 I'm struggling with making it all work. Maybe if we are to improve the testing infra, we should create a dummy Layout?
There was a problem hiding this comment.
Let's move on, I'd like to release soon, we'll figure out how to test this later and provide better test infra for the whole theme. This likely requires some extra refactorings
| </>, | ||
| ); | ||
| }).toMatchInlineSnapshot(`[Function]`); // This is just a check that the function returns. We don't care about the actual DOM. | ||
| }); |
There was a problem hiding this comment.
Let's move on, I'd like to release soon, we'll figure out how to test this later and provide better test infra for the whole theme. This likely requires some extra refactorings
Breaking changes
defaultValue={null}if you want to tabs initially selectedMotivation
Followup from here: #5647 (comment)
Have you read the Contributing Guidelines on pull requests?
Yes