Skip to content
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(create): run async tasks concurrently #8080

Merged
merged 7 commits into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/create-docusaurus/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,10 @@ export default async function init(
reqTemplate?: string,
cliOptions: CLIOptions = {},
): Promise<void> {
const templates = await readTemplates();
const siteName = await getSiteName(reqName, rootDir);
const [templates, siteName] = await Promise.all([
readTemplates(),
getSiteName(reqName, rootDir)
Josh-Cena marked this conversation as resolved.
Show resolved Hide resolved
]);
const dest = path.resolve(rootDir, siteName);
const source = await getSource(reqTemplate, templates, cliOptions);

Expand Down
88 changes: 44 additions & 44 deletions packages/docusaurus/src/client/clientEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,47 @@
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import ReactDOM from 'react-dom';
import {BrowserRouter} from 'react-router-dom';
import {HelmetProvider} from 'react-helmet-async';

import ExecutionEnvironment from './exports/ExecutionEnvironment';
import App from './App';
import preload from './preload';
import docusaurus from './docusaurus';

declare global {
interface NodeModule {
hot?: {accept: () => void};
}
}

// Client-side render (e.g: running in browser) to become single-page
// application (SPA).
if (ExecutionEnvironment.canUseDOM) {
window.docusaurus = docusaurus;
// For production, attempt to hydrate existing markup for performant
// first-load experience.
// For development, there is no existing markup so we had to render it.
// We also preload async component to avoid first-load loading screen.
const renderMethod =
process.env.NODE_ENV === 'production' ? ReactDOM.hydrate : ReactDOM.render;
preload(window.location.pathname).then(() => {
renderMethod(
<HelmetProvider>
<BrowserRouter>
<App />
</BrowserRouter>
</HelmetProvider>,
document.getElementById('__docusaurus'),
);
});

// Webpack Hot Module Replacement API
if (module.hot) {
// Self-accepting method/ trick
// (https://github.com/webpack/webpack-dev-server/issues/100#issuecomment-290911036)
module.hot.accept();
}
}
import React from 'react';
sanjaiyan-dev marked this conversation as resolved.
Show resolved Hide resolved
import ReactDOM from 'react-dom';
import {BrowserRouter} from 'react-router-dom';
import {HelmetProvider} from 'react-helmet-async';
import ExecutionEnvironment from './exports/ExecutionEnvironment';
import App from './App';
import preload from './preload';
import docusaurus from './docusaurus';
declare global {
interface NodeModule {
hot?: {accept: () => void};
}
}
// Client-side render (e.g: running in browser) to become single-page
// application (SPA).
if (ExecutionEnvironment.canUseDOM) {
window.docusaurus = docusaurus;
// For production, attempt to hydrate existing markup for performant
// first-load experience.
// For development, there is no existing markup so we had to render it.
// We also preload async component to avoid first-load loading screen.
const renderMethod =
process.env.NODE_ENV === 'production' ? ReactDOM.hydrate : ReactDOM.render;
preload(window.location.pathname).then(() => {
renderMethod(
<HelmetProvider>
<BrowserRouter>
<App />
</BrowserRouter>
</HelmetProvider>,
document.getElementById('__docusaurus'),
);
});
// Webpack Hot Module Replacement API
if (module.hot) {
// Self-accepting method/ trick
// (https://github.com/webpack/webpack-dev-server/issues/100#issuecomment-290911036)
module.hot.accept();
}
}