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

Out of order language tabs #546

Closed
Gijsdeman opened this issue Apr 14, 2023 · 8 comments
Closed

Out of order language tabs #546

Gijsdeman opened this issue Apr 14, 2023 · 8 comments
Labels
bug Something isn't working roadmap Features or bug fixes planned for future release

Comments

@Gijsdeman
Copy link
Contributor

Describe the bug

When using the language tabs are configured in a different order than shown in customization, the tabs seem to no longer switch properly between languages anymore.

Expected behavior

The language to update when switching between language tabs.

Current behavior

Language gets stuck on a language and does not load the language of the currently selected tab.

Steps to reproduce

Adding the following languageTabs to the themeConfig will cause the language to render as intended.

languageTabs: [ { highlight: "bash", language: "curl", logoClass: "bash", }, { highlight: "python", language: "python", logoClass: "python", variant: "requests", }, { highlight: "go", language: "go", logoClass: "go", }, { highlight: "javascript", language: "nodejs", logoClass: "nodejs", variant: "axios", }, { highlight: "php", language: "php", logoClass: "php", } ],

However, when changing the position of PHP language (or any other language), causes the tabs to no longer function properly.

languageTabs: [ { highlight: "bash", language: "curl", logoClass: "bash", }, { highlight: "php", language: "php", logoClass: "php", }, { highlight: "python", language: "python", logoClass: "python", variant: "requests", }, { highlight: "go", language: "go", logoClass: "go", }, { highlight: "javascript", language: "nodejs", logoClass: "nodejs", variant: "axios", } ],

Screenshots

image

image

Context

PHP or shell has preference within the wanted documentation, so I prefer to have it as the first two options available. This is not a huge issue in general, but would be nice to be able to do this.

Your Environment

Version used:

  • docusaurus-plugin-openapi-docs: 1.7.0
  • mozilla firefox for ubuntu: 111.0.1
@Gijsdeman Gijsdeman added the bug Something isn't working label Apr 14, 2023
@welcome-to-palo-alto-networks

🎉 Thanks for opening your first issue here! Welcome to the community!

@sserrata
Copy link
Member

Hi @Gijsdeman, thanks for reporting.

The variant is currently a required property. We'll update the examples in the documentation.

@sserrata
Copy link
Member

Actually, it seems that it's only "required" once the default order is changed. This smells more like a bug. We'll investigate a bit more and will keep you updated.

@CheyiLin
Copy link

CheyiLin commented Aug 3, 2023

Same here with Docusaurus 2.4.1 and plugin 2.0.0-beta.3.

languageTabs: [
  {
    highlight: "bash",
    language: "curl",
    logoClass: "bash",
    variant: "cURL",
  },
  {
    highlight: "go",
    language: "go",
    logoClass: "go",
    variant: "native",
  },
  {
    highlight: "javascript",
    language: "nodejs",
    logoClass: "nodejs",
    variant: "axios",
  },
],

With the languageTabs config above, click tab go or nodejs will crash:

image

@pepopowitz
Copy link

I also just ran into this. Some potentially helpful information:

Potential source of the bug

The crash message includes the "Available values" of variants for the current languageTab. Those available variant values appear to align with the order of the default languageTabs, as defined in CodeSnippets/index. In other words, whichever languageTab you define 3rd will be looking for one of the variants defined as the 3rd default, i.e. Go's native variant.

I see that there's some config merging going on in that component. I suspect that the merging is resulting in most properties taking on the customized sequence of languageTabs, but not updating the associated variants property. (Which would make sense, if we're not defining the variants property in our reordered configuration.)

A workaround

On a whim, I tried defining the variants property on each of the reordered languageTabs elements in my configuration. It works! The page no longer crashes, and all languages/variants display properly.

So I guess if the tabs are reordered, both the variant and variants properties become required, for any tab that is in a different position than its default.

As an example, this configuration for the previous comment functions correctly for me, with Docusaurus v2.4.1 and plugin v2.0.0-beta.4:

languageTabs: [
  {
    highlight: "bash",
    language: "curl",
    logoClass: "bash",
    variant: "cURL",
  },
  {
    highlight: "go",
    language: "go",
    logoClass: "go",
    variant: "native",
    variants: ["native"],
  },
  {
    highlight: "javascript",
    language: "nodejs",
    logoClass: "nodejs",
    variant: "axios",
    variants: ["native", "axios", "request", "unirest"],
  },
],

@derekaug
Copy link

I also just ran into this. Some potentially helpful information:

Potential source of the bug

The crash message includes the "Available values" of variants for the current languageTab. Those available variant values appear to align with the order of the default languageTabs, as defined in CodeSnippets/index. In other words, whichever languageTab you define 3rd will be looking for one of the variants defined as the 3rd default, i.e. Go's native variant.

I see that there's some config merging going on in that component. I suspect that the merging is resulting in most properties taking on the customized sequence of languageTabs, but not updating the associated variants property. (Which would make sense, if we're not defining the variants property in our reordered configuration.)

A workaround

On a whim, I tried defining the variants property on each of the reordered languageTabs elements in my configuration. It works! The page no longer crashes, and all languages/variants display properly.

So I guess if the tabs are reordered, both the variant and variants properties become required, for any tab that is in a different position than its default.

As an example, this configuration for the previous comment functions correctly for me, with Docusaurus v2.4.1 and plugin v2.0.0-beta.4:

languageTabs: [
  {
    highlight: "bash",
    language: "curl",
    logoClass: "bash",
    variant: "cURL",
  },
  {
    highlight: "go",
    language: "go",
    logoClass: "go",
    variant: "native",
    variants: ["native"],
  },
  {
    highlight: "javascript",
    language: "nodejs",
    logoClass: "nodejs",
    variant: "axios",
    variants: ["native", "axios", "request", "unirest"],
  },
],

also noticed that if I want to remove a variant / reorder a variant - it doesn't appear to work. for instance, I just wanted to show native and axios under nodejs but it always uses the default variants. I suspect this is due to how lodash.merge merges the variants array here: https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/blob/v3.0.0/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/CodeSnippets/index.tsx#L179

@sserrata sserrata added the roadmap Features or bug fixes planned for future release label Jun 28, 2024
@sserrata
Copy link
Member

adding to roadmap with the goal of expanding support for more languages and allow flexible ordering/inclusion

@sserrata
Copy link
Member

sserrata commented Jul 2, 2024

Addressed in #862

@sserrata sserrata closed this as completed Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working roadmap Features or bug fixes planned for future release
Projects
None yet
Development

No branches or pull requests

5 participants