Repository navigation
Closed
Labels
bugAn error in the Docusaurus core causing instability or issues with its execution
Description
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Prerequisites
- I'm using the latest version of Docusaurus.
- I have tried the
npm run clearoryarn clearcommand. - I have tried
rm -rf node_modules yarn.lock package-lock.jsonand re-installing packages. - I have tried creating a repro with https://new.docusaurus.io.
- I have read the console error message carefully (if applicable).
Description
I'm using a common set of Tabs and TabItem instances over-and-over again throughout multiple mdx pages. Instead of constantly writing out the groupId, value, and label properties over-and-over again, I tried create custom React components like:
import React, { ReactNode } from 'react';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
export const InstallationGroup = ({ children }: { children: ReactNode }) => (
<Tabs groupId="installation">
{children}
</Tabs>
);
export const Local = ({ children }: { children: ReactNode }) => (
<TabItem value="local" label="Local Installation">
{children}
</TabItem>
);
export const PaaS = ({ children }: { children: ReactNode }) => (
<TabItem value="paas" label="Platform as a Service">
{children}
</TabItem>
);And then in my MDX pages:
import { InstallationGroup, Local, PaaS } from '../../src/components/installation-tabs';
<InstallationGroup>
<Local>
Local install content.
</Local>
<PaaS>
PaaS install content.
</PaaS>
</InstallationGroup>This builds fine, but when I navigate to the page in my browser I get this error:
Docusaurus error: Bad <Tabs> child <Local>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.
I feel like what I'm doing should work fine, but if not, is there another way I can achieve this?
Reproducible demo
Steps to reproduce
I tried getting this to work in codesandbox but its stuck trying to bring up the localhost. I recommend just copying the files I shared above to demo the issue.
Expected behavior
I expect to be able to extend these react components for reusability.
Actual behavior
Error as described.
Your environment
- Public source code: https://github.com/HarperFast/documentation
- Docusaurus version used: 3.9.2
- Environment name and version (e.g. Chrome 89, Node.js 16.4): Chrome, Node 22
- Operating system and version (e.g. Ubuntu 20.04.2 LTS): MacOS
Self-service
- I'd be willing to fix this bug myself.
Metadata
Metadata
Assignees
Labels
bugAn error in the Docusaurus core causing instability or issues with its execution
Activity
Patilpradnesh commentedon Jan 19, 2026
Hi, I’m a first-time contributor and I’ve been working on a small improvement for this issue.
I updated the Tabs error message to clarify that wrapper/custom components around
<TabItem>are not supported, and updated the related test.Before opening a PR, I just wanted to confirm that this approach is acceptable.
Thank you!
Ethan-Arrowood commentedon Jan 19, 2026
Why isn't it possible?
Patilpradnesh commentedon Jan 20, 2026
Thank you for the question — I’m still learning the internals here, so please correct me if my understanding is wrong.
From what I observed in the current implementation,
<Tabs>validates its children by checking the direct React element type (child.type) to ensure it is a<TabItem>.When a wrapper component like
<Local>is used, the direct child is<Local>, not<TabItem>, even though<Local>returns<TabItem>when rendered. Because of this, the current validation logic seems to reject it by design.So my understanding is that this is not a limitation of React itself, but of how
<Tabs>currently inspects its children.That’s why I thought improving the error message and documentation might be a safe first step — but I’d really appreciate your guidance if you think a better approach is possible here.
Ethan-Arrowood commentedon Jan 20, 2026
I'm not a maintainer so it's not my call, but from my understanding of react this check may be too aggressive and this pattern should be fine.
Am I wrong and is this validation correct and necessary?
Or is there better way to validate that would enable this pattern?
--
Aside, there's no harm in opening a PR (or multiple) and iterating there. At least it demonstrates some sort of solutions. You should always feel empowered to open a PR even if it doesn't get approved and merged.
Patilpradnesh commentedon Jan 20, 2026
Thanks for the thoughtful input — that’s really helpful.
I agree the validation may be too strict, and I appreciate the perspective. I’ve gone ahead and opened a PR so we can iterate and discuss the best approach there.
Thanks again for the encouragement!
lab596 commentedon Feb 2, 2026
To the best of my understanding I think this is in place to enable quick Static Site Generation? An explicit check like this enables understanding of which tab is active during rendering isntead of a deep render which would require an execute of every child component to verify the metadata. Not exactly sure but on intial inspection that what it looks like?
slorber commentedon Feb 5, 2026
I agree that the check is too aggressive, and wrapping our components should be allowed.
This historical check (#5674) should be reworked so that it allows custom tabs.
I think this heuristic here is wrong and fails for your case because your tab wrappers do not forward a value prop. Otherwise it would work.
Ultimately, what we want to do here is to prevent typo errors and misusage.
Unfortunately, TypeScript doesn't have "render types" like Flow and it's hard to prevent mistakes at compile time in MDX anyway (these files are not typechecked), so we implemented a poor man's runtime type check.
If someone want to implement a PR that makes the above TabItem wrapper work, but at the same time still prevent usage mistakes, please do so (we have unit tests to cover that component, by the way, and new tests must be added to better support this valid use case).
If no proper solution can be found, I'd rather remove the error entirely so that it doesn't prevent such custom composition/wrapper patterns
slorber commentedon Feb 12, 2026
The problem is more complex to solve than I initially thought, and would require a quite important refactor of the tabs component.
The error being thrown is one thing, but the main problem is that the Tabss implementation assumes that TabItem React elements all have
tabItem.props.valueaccessible, which is not the case with wrappers.I tried removing the failfast error check, and it still fails later in the process because the assumptions we rely on break.
The problem with our API implementation is that we have a single
TabItemcomponent that is used to provide both the tab item button and the tab item panel/content. Somehow, the parent tab component has to extract all the tab item buttons from its children, which doesn't work if items are wrappedJosh-Cena commentedon Feb 12, 2026
The
childrenlist ofTabsis really just a convenience alternative toi.e. you shouldn't see each
TabItemas anything more than sugar for an object literal. If you want to wrapTabItem, you also have to wrapTabsto tellTabshow to extract these values.I don't think we can do significantly better here;
TabItemdoesn't actually render anything by itself. It's just a data carrier of its props.slorber commentedon Feb 12, 2026
@Ethan-Arrowood, in #11733
I'm adding a React context to solve the above limitation.
Maybe not your ideal API, but the following will work if you provide an explicit list of
<Tab values>.You either have to:
slorber commentedon Feb 12, 2026
Agree that this solution also works. You can also pass the "paas" and "local" tabs as distinct props to make things clearer and less order-dependent.
I'm still going to land the PR because using context still makes this a little bit more flexible, and I also took the opportunity to cleanup the code.
Ethan-Arrowood commentedon Feb 17, 2026
Thank you!