From f03479f69ef0c1dc6b19835e3b1c5b73d4ab970c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Thu, 8 Jul 2021 20:26:55 +0200 Subject: [PATCH] test(v2): dogfooding: add huge sidebar for testing purposes (#5130) * dogfoog: add huge sidebar for testing purposes * Add standalone doc + build-size tracking --- .github/workflows/v2-build-size-report.yml | 2 +- .../src/theme/DocSidebar/index.tsx | 10 ++-- website/docusaurus.config.js | 1 + website/dogfooding/docs-tests-sidebars.js | 49 +++++++++++++++++++ website/dogfooding/docs-tests/standalone.md | 3 ++ 5 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 website/dogfooding/docs-tests-sidebars.js create mode 100644 website/dogfooding/docs-tests/standalone.md diff --git a/.github/workflows/v2-build-size-report.yml b/.github/workflows/v2-build-size-report.yml index ba972a000e..d24d65f1bf 100644 --- a/.github/workflows/v2-build-size-report.yml +++ b/.github/workflows/v2-build-size-report.yml @@ -26,7 +26,7 @@ jobs: with: repo-token: '${{ secrets.GITHUB_TOKEN }}' build-script: 'build:v2:en' - pattern: '{website/build/assets/js/main*js,website/build/assets/css/styles*css,website/build/index.html,website/build/blog/**/introducing-docusaurus/*,website/build/docs/introduction/index.html,website/.docusaurus/globalData.json}' + pattern: '{website/build/assets/js/main*js,website/build/assets/css/styles*css,website/.docusaurus/globalData.json,website/build/index.html,website/build/blog/**/introducing-docusaurus/*,website/build/docs/index.html,website/build/docs/introduction/index.html,website/build/docs-tests/index.html,website/build/docs-tests/standalone/index.html}' strip-hash: '\.([^;]\w{7})\.' minimum-change-threshold: 30 compression: 'none' diff --git a/packages/docusaurus-theme-classic/src/theme/DocSidebar/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocSidebar/index.tsx index ae96ae86b5..01c893bca7 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocSidebar/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocSidebar/index.tsx @@ -58,9 +58,13 @@ const DocSidebarItems = memo(function DocSidebarItems({ )); }); -function DocSidebarItem(props): JSX.Element { +function DocSidebarItem(props): JSX.Element | null { switch (props.item.type) { case 'category': + // Never render empty categories + if (props.item.items.length === 0) { + return null; + } return ; case 'link': default: @@ -104,10 +108,6 @@ function DocSidebarItemCategory({ } }, [isActive, wasActive, collapsed]); - if (items.length === 0) { - return null; - } - return (
  • ({ + type: 'link', + href: '/', + label: `Link ${index} (level ${currentLevel + 1})`, + })); + + const categoryItems = [...Array(categoriesCount).keys()].map((index) => ({ + type: 'category', + label: `Category ${index} (level ${currentLevel + 1})`, + items: generateRecursive(maxLevel, currentLevel + 1), + })); + + return [...linkItems, ...categoryItems]; + } + + return generateRecursive(maxLevel); +} diff --git a/website/dogfooding/docs-tests/standalone.md b/website/dogfooding/docs-tests/standalone.md new file mode 100644 index 0000000000..5103ded42c --- /dev/null +++ b/website/dogfooding/docs-tests/standalone.md @@ -0,0 +1,3 @@ +# Standalone doc + +This doc is not in any sidebar, on purpose, to measure the build size impact of the huge sidebar