-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,12 @@ | |
import globby from 'globby'; | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import {idx, normalizeUrl, docuHash} from '@docusaurus/utils'; | ||
import { | ||
idx, | ||
normalizeUrl, | ||
docuHash, | ||
objectWithKeySorted, | ||
} from '@docusaurus/utils'; | ||
import {LoadContext, Plugin} from '@docusaurus/types'; | ||
|
||
import createOrder from './order'; | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Had to do this because otherwise |
||
}; | ||
}, | ||
|
||
|
@@ -252,7 +257,9 @@ export default function pluginContentDocs( | |
addRoute({ | ||
path: docsBaseRoute, | ||
component: docLayoutComponent, | ||
routes, | ||
routes: routes.sort((a, b) => | ||
a.path > b.path ? 1 : b.path > a.path ? -1 : 0, | ||
), | ||
modules: { | ||
docsMetadata: aliasedSource(docsBaseMetadataPath), | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import { | |
getSubFolder, | ||
normalizeUrl, | ||
posixPath, | ||
objectWithKeySorted, | ||
} from '../index'; | ||
|
||
describe('load utils', () => { | ||
|
@@ -82,6 +83,41 @@ describe('load utils', () => { | |
}); | ||
}); | ||
|
||
test('objectWithKeySorted', () => { | ||
const obj = { | ||
'/docs/adding-blog': '4', | ||
'/docs/versioning': '5', | ||
'/': '1', | ||
'/blog/2018': '3', | ||
'/youtube': '7', | ||
'/users/en/': '6', | ||
'/blog': '2', | ||
}; | ||
expect(objectWithKeySorted(obj)).toMatchInlineSnapshot(` | ||
Object { | ||
"/": "1", | ||
"/blog": "2", | ||
"/blog/2018": "3", | ||
"/docs/adding-blog": "4", | ||
"/docs/versioning": "5", | ||
"/users/en/": "6", | ||
"/youtube": "7", | ||
} | ||
`); | ||
const obj2 = { | ||
b: 'foo', | ||
c: 'bar', | ||
a: 'baz', | ||
}; | ||
expect(objectWithKeySorted(obj2)).toMatchInlineSnapshot(` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even snapshot is consistent now in ordering😃 |
||
Object { | ||
"a": "baz", | ||
"b": "foo", | ||
"c": "bar", | ||
} | ||
`); | ||
}); | ||
|
||
test('genChunkName', () => { | ||
const firstAssert = { | ||
'/docs/adding-blog': 'docs-adding-blog-062', | ||
|
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