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

CodeSnippets can't display if languageTabs isn't present in docusaurus theme config #870

Closed
ElliotFriend opened this issue Jul 3, 2024 · 2 comments

Comments

@ElliotFriend
Copy link
Contributor

Hi, @sserrata!! 👋🏻

Super excited for the v3.0.0 release! I know it's been a lot of work, and I'm so thankful for everything you've done!!

Working on getting my project updated, and I hit a snag with the recent code snippets ordering feature. Looks like if siteConfig.themeConfig.languageTabs is either a) absent from the config, or b) an empty array, docusaurus will hit a runtime error complaining: TypeError: Cannot read properties of undefined (reading 'samples')

Screenshot 2024-07-03 at 2 55 19 PM

I think it might be crashing because if userDefinedLanguageSet is nullish, the filtered and then merged language set ends up being empty.

I was able to use patch-package to patch the built plugin. Here is the diff that solved my problem:

diff --git a/node_modules/docusaurus-theme-openapi-docs/lib/theme/ApiExplorer/CodeSnippets/index.js b/node_modules/docusaurus-theme-openapi-docs/lib/theme/ApiExplorer/CodeSnippets/index.js
index 53f4f65..e5ab3ca 100644
--- a/node_modules/docusaurus-theme-openapi-docs/lib/theme/ApiExplorer/CodeSnippets/index.js
+++ b/node_modules/docusaurus-theme-openapi-docs/lib/theme/ApiExplorer/CodeSnippets/index.js
@@ -220,7 +220,7 @@ function CodeSnippets({ postman, codeSamples }) {
   const auth = (0, hooks_1.useTypedSelector)((state) => state.auth);
   // User-defined languages array
   // Can override languageSet, change order of langs, override options and variants
-  const userDefinedLanguageSet = siteConfig?.themeConfig?.languageTabs;
+  const userDefinedLanguageSet = siteConfig?.themeConfig?.languageTabs || exports.languageSet;
   // Filter languageSet by user-defined langs
   const filteredLanguageSet = exports.languageSet.filter((ls) => {
     return userDefinedLanguageSet?.some((lang) => {

This issue body was partially generated by patch-package.

@sserrata
Copy link
Member

sserrata commented Jul 3, 2024

Hi @ElliotFriend, I was just troubleshooting this very issue. I'll try to get a fix out ASAP. Thanks!

@sserrata
Copy link
Member

sserrata commented Jul 3, 2024

Released v3.0.1 with fix

@sserrata sserrata closed this as completed Jul 3, 2024
ElliotFriend added a commit to ElliotFriend/stellar-docs that referenced this issue Jul 3, 2024
ElliotFriend added a commit to stellar/stellar-docs that referenced this issue Jul 10, 2024
* upgrade package versions

* convert docusaurus config to typescript

* change dependency version for katex and math plugins

* re-add sentry plugin

* remove old docLayoutComponent config for platforms plugin

* update redocly config file, regenerate openapi docs

* fix compilation errors for MDX v3

* update sidebars files, re-swizzle ApiExplorer theme component

* add temporary patch for code samples issue

Refs: PaloAltoNetworks/docusaurus-openapi-docs/issues/870

* adjust sidebar generator for main docs plugin

* re-swizzle a couple theme components into typescript

* even more swizzling of components

* resolve the build failures

* upgrade openapi plugin, remove no-longer-necessary patch

* format and lint everything

* upgrade Dockerfile and gh workflow to nodejs 20

* downgrade an openrpc package, linting/formatting changes

* temporarily increase the container node memory to get it to build

* check for "MDXUl" and "ul" in attribute table lists

* regenerate openapi docs

* remove dependencies for unused features in dapps challenge

* formatting/linting the dapps challenge commented parts

* fix broken links

* so many broken anchors to fix

* enable mdx1 compatibility for old-style heading IDs

* throw error for broken links again

* reformat some links in a hubble analyst guide
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants