Skip to content

Conversation

@endiliey
Copy link
Contributor

@endiliey endiliey commented Oct 8, 2019

Motivation

This PR is an attempt to make our docs data structure to be more efficient while achieving the same functionality. This should solve scalability problem #1782

  • Delete useless metadata
  • Colocate related metadata better
    Previously, we have something called docsMetadata that contains all the metadata of all docs pages. It is used as a lookup table for certain doc page to convert id into its corresponding metadata like title and permalink. This poses a huge problem because as the number of docs grow bigger, the client bundle size will increase linearly.

Current docu v2 docs for example, the docsMetadata itself is alrd ~15kb
before2

With this PR, the docsMetadata is just ~2kb
after2

In fact, this PR makes our build time much faster and consume less memory as well

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

  • Website prev and next button is working properly
  • The docs sidebar is still working like previously
  • Changed test passes

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Oct 8, 2019
@endiliey endiliey requested a review from yangshun October 8, 2019 17:03
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Oct 8, 2019

Deploy preview for docusaurus-2 ready!

Built with commit 5269f01

https://deploy-preview-1815--docusaurus-2.netlify.com

@docusaurus-bot
Copy link
Contributor

Deploy preview for docusaurus-preview ready!

Built with commit 0680354

https://deploy-preview-1815--docusaurus-preview.netlify.com

@docusaurus-bot
Copy link
Contributor

Deploy preview for docusaurus-preview ready!

Built with commit 5269f01

https://deploy-preview-1815--docusaurus-preview.netlify.com

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome perf wins! I'll look the data structure in more detail later and see whether we can improve the sidebar with this also.

Actually I was thinking of leaving this legacy plugin in and creating the new plugin with new components, that's why I added legacy to the name. Do you think that approach is necessary?

@endiliey
Copy link
Contributor Author

endiliey commented Oct 9, 2019

that's why I added legacy to the name. Do you think that approach is necessary?

i think it will be hard to maintain two plugins with different component

see whether we can improve the sidebar with this also.

actually the sidebar has been improved also. instead of doing the lookup table client side, we do it server side (at build time) instead. The sidebar component will only receive a very-easy-to-digest props

of course more improvement can be done

@yangshun
Copy link
Contributor

yangshun commented Oct 9, 2019

i think it will be hard to maintain two plugins with different component

I don't intend to maintain the legacy one, just keep it there. But I guess we could just move things now. Only users who swizzled the doc components need to re-implement their doc components because the data structure has changed. No that many people swizzled I think.

actually the sidebar has been improved also.

Ah I meant the React component, to collapse categories if the page is not active, expand when item is active. I could tackle this later :)

Feel free to merge first!

@yangshun yangshun changed the title feat(v2): better docs metadata refactor(v2): better docs metadata Oct 9, 2019
@endiliey endiliey merged commit e7ba8af into master Oct 9, 2019
@endiliey endiliey deleted the endiliey/remove-docsMetadata branch October 9, 2019 06:34
@endiliey
Copy link
Contributor Author

endiliey commented Oct 9, 2019

Ah I meant the React component, to collapse categories if the page is not active, expand when item is active. I could tackle this later :)

Sure thing. To find current page you might want to pass location props to the sidebar as well.

<DocLegacySidebar docsSidebars={docsSidebars} sidebar={sidebar} />

- <DocLegacySidebar docsSidebars={docsSidebars} sidebar={sidebar} />
+ <DocLegacySidebar location={location} docsSidebars={docsSidebars} sidebar={sidebar} />

The sidebar content data structure will look like this. It's only either category or link type

[
      {
        "type": "category",
        "label": "Guides",
        "items": [
          {
            "type": "link",
            "label": "Creating Pages",
            "href": "/docs/creating-pages"
          },
          {
            "type": "link",
            "label": "Styling and Layout",
            "href": "/docs/styling-layout"
          },
          {
            "type": "category",
            "label": "Docs",
            "items": [
              {
                "type": "link",
                "label": "Markdown Features",
                "href": "/docs/markdown-features"
              },
              {
                "type": "link",
                "label": "Sidebar",
                "href": "/docs/sidebar"
              }
            ]
          },
          {
            "type": "link",
            "label": "Blog",
            "href": "/docs/blog"
          },
          {
            "type": "link",
            "label": "Analytics",
            "href": "/docs/analytics"
          }
        ]
      }
    ]

@yangshun
Copy link
Contributor

yangshun commented Oct 9, 2019

I'm working on it now, have a PR almost up!

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

Labels

CLA Signed Signed Facebook CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants