-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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(v2): refactor routes.ts + add route hash for chunkNames key #3001
Conversation
Deploy preview for docusaurus-2 ready! Built with commit 9beb8c9 |
// Important: the layout component should not end with /, | ||
// as it conflicts with the home doc | ||
// Workaround fix for https://github.com/facebook/docusaurus/issues/2917 | ||
const docsPath = docsBaseRoute === '/' ? '' : docsBaseRoute; |
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.
feature permits to remove that temporary hack that's not needed anymore
@@ -21,7 +24,8 @@ function ComponentCreator(path: string): ReturnType<typeof Loadable> { | |||
}); | |||
} | |||
|
|||
const chunkNames = routesChunkNames[path]; | |||
const chunkNamesKey = `${path}-${hash}`; |
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 prefered reconstructing the chunkNamesKey with the same logic on client because chunkNamesKey already contains the path so this would look more messy if user inspects .docusaurus folder, and would also take more place
routesPaths.push(routePath); | ||
} | ||
|
||
function genRouteChunkNames( |
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.
fn extracted, not really modified
: '' | ||
}}`; | ||
return str; | ||
}; |
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.
trying to encapsulate all string codegen here
: '' | ||
} | ||
`, | ||
), |
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.
warning I put recently, can be removed now because conflits are unlikely to happen
ready to review |
@@ -187,3 +157,44 @@ export default [ | |||
routesPaths, | |||
}; | |||
} | |||
|
|||
function genRouteChunkNames( | |||
// TODO instead of passing a mutating the registre, return a registry slice? |
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.
Typo - Register
Motivation
See #2917
Fix potential weird merge behavior when a parent route and its child has the exact same path.
To avoid potential conflicts, smallHash(route) is added at the end of the chunknames key.
Also refactors the routes.ts file by splitting a bit the logic and trying to make it more readable than before (inline code generation strings do not help for readability)
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
tests + preview