mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
refactor(v2): avoid synchronous/ blocking operation when possible (#1957)
* perf(v2): avoid synchronous/ blocking operation when possible * save variable
This commit is contained in:
parent
5e445a0011
commit
1235fc9f7e
6 changed files with 85 additions and 76 deletions
|
@ -52,4 +52,10 @@ describe('loadSidebars', () => {
|
|||
const result = loadSidebars(null);
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
|
||||
test('fake sidebars path', () => {
|
||||
expect(() => {
|
||||
loadSidebars('/fake/path');
|
||||
}).toThrowError();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import importFresh from 'import-fresh';
|
||||
import {
|
||||
SidebarItemCategory,
|
||||
|
@ -105,7 +104,7 @@ function normalizeSidebar(sidebars: SidebarRaw): Sidebar {
|
|||
export default function loadSidebars(sidebarPath: string): Sidebar {
|
||||
// We don't want sidebars to be cached because of hotreloading.
|
||||
let allSidebars: SidebarRaw = {};
|
||||
if (sidebarPath && fs.existsSync(sidebarPath)) {
|
||||
if (sidebarPath) {
|
||||
allSidebars = importFresh(sidebarPath) as SidebarRaw;
|
||||
}
|
||||
return normalizeSidebar(allSidebars);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue