-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
perf(v2): more efficient hot reload & consistent filegen #1950
Conversation
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.
Wow what an optimization. Maybe you could tweet/blog about this.
Deploy preview for docusaurus-2 ready! Built with commit 32af3c1 |
Deploy preview for docusaurus-preview ready! Built with commit 32af3c1 |
@@ -18,9 +18,6 @@ import {posixPath} from '@docusaurus/utils'; | |||
const createFakeActions = (routeConfigs: RouteConfig[], contentDir) => { | |||
return { | |||
addRoute: (config: RouteConfig) => { | |||
config.routes.sort((a, b) => |
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.
Previously had to sort it in test because snapshot will always fail previously due to inconsistent routes (async nature). Now no longer need to do that in test
@@ -202,7 +207,7 @@ export default function pluginContentDocs( | |||
docsDir, | |||
docsSidebars, | |||
sourceToPermalink, | |||
permalinkToSidebar, | |||
permalinkToSidebar: objectWithKeySorted(permalinkToSidebar), |
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.
Had to do this because otherwise docsBaseMetadata
(the root file generated) will always change without utilizing cache
c: 'bar', | ||
a: 'baz', | ||
}; | ||
expect(objectWithKeySorted(obj2)).toMatchInlineSnapshot(` |
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.
Even snapshot is consistent now in ordering😃
Sorry, I was too excited to merge this. This is such a crazy optimization. We are one step closer towards the scalability required for versioning! |
On production, removing
|
Motivation
More efficient hot reload & consistent generated file
Note that I set
clientLogLevel
toinfo
in devserver config.Previously, if we start development server and go to home page. We can go to
src/pages/index.js
and just 'save' without changing anythingGIF Preview
Note that there are several files that got disposed by WDS. This is because our generated files (although we have caching in
docusaurus/packages/docusaurus-utils/src/index.ts
Lines 15 to 32 in 87f864e
Explanation
Is considered different from
The generated files can be different because of async nature and keys ordering. We should always provide consistent file generation.
Others:
Have you read the Contributing Guidelines on pull requests?
yes
Test Plan
After this PR
GIF preview
I tried editing the src/pages/index.js for real and its the right behavior
Index.js is detected to have changed, so it is disposed. Registry need to be dispsoed because index.js has changed, and so on.
Extra: Notice the hot reload performance is much faster :)