Skip to content

Error when using a single TabItem component within parent Tabs component #8591

Closed

Description

@farlowdw

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

Using a single TabItem component within a parent Tabs component causes a Uncaught TypeError: children.map is not a function error (this was not the case before the recent 2.3.0 release, as far as I can tell).

With the new release, if I visit /docs/success in the linked example repo, where two TabItem components are nested within a parent Tabs component, then everything works fine:

ill-3

If, however, I visit /docs/fail, where a single TabItem component is within a parent Tabs component, then the page crashes due to a children.map is not a function error:

ill-4

Inspecting the console makes it clear why this error is occurring:

ill-2

After looking at the file containing the offending line of code, I decided to log children and the error became clear.

With a single item:

log-1

With two items:

log-2

A very superficial hack "resolves" the problem (at least in terms of getting the page not to crash):

ill-1

Reproducible demo

https://stackblitz.com/edit/github-wahvzn

Steps to reproduce

  1. Visit the repro link and observe the failure by navigating to /docs/fail. Then observe the success by visiting /docs/success.

Expected behavior

Continuity in terms of how TabItem components are rendered. Plurality should not matter. There are cases where it may be desirable to use a single TabItem within Tabs such as illustrating how to do things in different coding languages but only having time in the moment to do so for a single language.

Actual behavior

A page should not crash due to the presence of only a single TabItem within Tabs. I can't imagine this was an intentional design decision (since this worked fine in previous versions).

Your environment

Repro demo and source code (made using docusaurus.new): https://stackblitz.com/edit/github-wahvzn?file=docs/fail.md

Self-service

  • I'd be willing to fix this bug myself.

Activity

  1. added
    bug
    status: needs triage
    on Jan 27, 2023
  2. removed
    status: needs triage
    on Jan 28, 2023
  3. Josh-Cena commented on Jan 28, 2023

    @Josh-Cena
    Collaborator

    Thanks for the report. Just curious: are you actually going to use a single tab item in production? Or is this just an annoyance for local development?

  4. added this to the 2.3.1 milestone on Jan 28, 2023
  5. farlowdw commented on Jan 28, 2023

    @farlowdw
    Author

    @Josh-Cena Mostly the latter; however, I do have one project with a bunch of single tabs currently because I'm lazy and have only added content for Python instead of other languages, as referenced in the expected behavior for this bug -- when I mentioned "there are cases" I was really referencing that project with suboptimal tab use.

  6. dabeeeenster commented on Jan 30, 2023

    @dabeeeenster

    +1 for 1 tab in Prod. I'm using this here: https://docs.flagsmith.com/clients/server-side#logging and IMHO this would be the most appropriate formatting, even tho 1 tab element sounds a bit odd, it works here.

    Screen Grab for if we modify the formatting waiting for this fix:

    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions