Skip to content

Perf: make rendering of collapsed sidebar categories lazy #4753

@slorber

Description

@slorber

💥 Proposal

Note to myself: before implementing that, let's add an artificially large sidebar to Docusaurus so that our build-size bot can measure the HTML page size and track regressions!

We have some sites that have extremely large sidebars (sometimes related to generated doc pages from code).

Rendering the same large sidebar, again and again, can lead to perf problems:

  • increased server-side rendering build times
  • increased static HTML pages

For example, Demisto reported the issue: demisto/content-docs#616 (comment)

They were able to remove 12min of build time, by simply not rendering the sidebar on the server at all, and only rendering it after React hydration:

import React from 'react';
import BrowserOnly from '@docusaurus/BrowserOnly';
import DocSidebar from '@theme-original/DocSidebar';

function DocSidebarBrowser(props) {
  return (
    <BrowserOnly fallback={<div>Sidebar...</div>}>
      {() => <DocSidebar {...props} />}
    </BrowserOnly>
  );
}

export default DocSidebarBrowser;

In my opinion, it is not a good solution:

Navigating from the homepage to a doc with a huge sidebar is also a slow experience, as the whole sidebar is currently rendered (even if it is fully collapsed), slowing down the navigation.

A possible solution is to have an option to optimize the sidebar by making it lazier:

  • Collapsed category childrens do not need to be rendered on the server, as they are not visible
  • We don't need to render them on the client immediately before the user click on the category to expand it

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalThis issue is a proposal, usually non-trivial change

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions