-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
fix(plugin-docs,theme): refactor docs plugin routes and component tree #7966
Conversation
✅ [V2]
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the deploy preview of this PR
|
Size Change: +592 B (0%) Total Size: 814 kB
ℹ️ View Unchanged
|
Does this supercede #6823? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready to review 👍
export async function createAllRoutes( | ||
param: CreateAllRoutesParam, | ||
): Promise<void> { | ||
const versionRoutes = await buildVersionsRoutes(param); | ||
versionRoutes.forEach((versionRoute) => param.actions.addRoute(versionRoute)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to move all side-effects here. Ideally our route def API should be improved so that we don't need anymore to use actions.createData()
=> we should be able to test this route building more easily
@@ -19,7 +18,7 @@ export default function DocPageLayout({children}: Props): JSX.Element { | |||
const sidebar = useDocsSidebar(); | |||
const [hiddenSidebarContainer, setHiddenSidebarContainer] = useState(false); | |||
return ( | |||
<Layout wrapperClassName={styles.docsWrapper}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout moved upper in the tree: Layout shouldn't unmount/remount when navigating from a doc page to a tag page for example
tag={docVersionSearchTag(version.pluginId, version.version)} | ||
/> | ||
<PageMetadata> | ||
{version.noIndex && <meta name="robots" content="noindex, nofollow" />} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixes the limitation described in #7963, because version noIndex is now also applied to tag pages
@@ -63,6 +63,8 @@ export function sortConfig( | |||
}); | |||
|
|||
routeConfigs.forEach((routeConfig) => { | |||
routeConfig.routes?.sort((a, b) => a.path.localeCompare(b.path)); | |||
if (routeConfig.routes) { | |||
sortConfig(routeConfig.routes, baseUrl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated bug in route sorting algorithm: subroutes should be sorted recursively
necessary to make this PR work otherwise /test/docs/
subroute would appear before test/docs/tag/xyz
and it fails
docsRootComponent: '@theme/DocsRoot', | ||
docVersionRootComponent: '@theme/DocVersionRoot', | ||
docRootComponent: '@theme/DocRoot', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New Root theme component we decided with @Josh-Cena .
@theme/DocPage
becomes @theme/DocRoot
Hierarchy is: @theme/DocsRoot
> @theme/DocVersionRoot
> @theme/DocRoot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On https://deploy-preview-7966--docusaurus-2.netlify.app/docs/tags/:
NotFound
renders Layout
already
Thanks, good catch 😅 wonder how I'll fix that |
Can it be a prop in |
Breaking changes
This refactor significantly changes the docs theme component tree. If you swizzled
@theme/DocPage
, or doc tags pages, you will likely need to upgrade your theme code a bit.The tree of theme components rendering doc routes changed from:
to this new structure
@theme/DocPage
has been renamed to@theme/DocRoot
@theme/DocRoot
(renamed) does not receive aversionMetadata
prop anymore. The new@theme/DocVersionRoot
receives it (upper in the tree), and makes it available in its subtree with theuseDocsVersion()
hook.@theme/DocRoot
(renamed),@theme/DocTagsListPage
and@theme/DocTagDocListPage
do not apply<Layout>
anymore: it's applied in@theme/DocsLayout
(parent of all docs plugin routes)docPageLayoutComponent
has been renamed todocRootComponent
Note there's a clear distinction between:
@theme/DocsRoot
: top-level parent layout component that wraps every docs plugin routes (all versions, docs, generated index, docs tags pages...) and apply the<Layout>
globally@theme/DocRoot
: single doc layout, responsible for displaying the docs sidebar alongside the docs content (markdown or category generated index)Motivation
All the versioned docs pages should have a shared parent layout page. This prevents unmounting/remounting the layout when navigating across docs pages, category-generated index pages, tags pages, and even across versions.
New docs plugin options:
docsRootComponent
: the component that wraps every route of a single doc plugin instancedocVersionRootComponent
: the component that wraps every route of a specific doc versionWith this refactor, tags-related pages are able to use the
useDocsVersion()
hook.Also fixes a bug in the core route sorting algorithm which was not really recursive.
Test Plan
unit tests + preview
Test links
Prod and deploy preview should look exactly the same.
Doc:
Tags list:
Tag page: