@docusaurus/core 2.0.0-beta.fbdeefcac → 2.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/bin/beforeCli.mjs +140 -0
- package/bin/{docusaurus.js → docusaurus.mjs} +79 -118
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +10 -8
- package/lib/client/App.d.ts +2 -3
- package/lib/client/App.js +31 -28
- package/lib/client/BaseUrlIssueBanner/index.d.ts +27 -0
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +25 -14
- package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
- package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
- package/lib/client/ClientLifecyclesDispatcher.js +39 -0
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +8 -13
- package/lib/client/PendingNavigation.d.ts +17 -3
- package/lib/client/PendingNavigation.js +47 -72
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → SiteMetadataDefaults.d.ts} +1 -2
- package/lib/client/SiteMetadataDefaults.js +21 -0
- package/lib/{choosePort.d.ts → client/browserContext.d.ts} +5 -5
- package/lib/client/browserContext.js +22 -0
- package/lib/client/clientEntry.js +14 -9
- package/lib/client/docusaurus.d.ts +12 -6
- package/lib/client/docusaurus.js +30 -43
- package/lib/client/docusaurusContext.d.ts +12 -0
- package/lib/client/docusaurusContext.js +25 -0
- package/lib/client/exports/BrowserOnly.d.ts +3 -5
- package/lib/client/exports/BrowserOnly.js +14 -8
- package/lib/client/exports/ComponentCreator.d.ts +6 -2
- package/lib/client/exports/ComponentCreator.js +75 -42
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +37 -0
- package/lib/client/exports/ExecutionEnvironment.js +7 -8
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.d.ts +2 -2
- package/lib/client/exports/Interpolate.js +20 -49
- package/lib/client/exports/Link.d.ts +4 -10
- package/lib/client/exports/Link.js +38 -38
- package/lib/client/exports/Translate.d.ts +1 -1
- package/lib/client/exports/Translate.js +14 -9
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/isInternalUrl.js +1 -1
- package/lib/client/exports/renderRoutes.d.ts +1 -2
- package/lib/client/exports/renderRoutes.js +1 -2
- package/lib/client/exports/router.d.ts +1 -1
- package/lib/client/exports/router.js +1 -1
- package/lib/client/exports/useBaseUrl.js +11 -14
- package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
- package/lib/client/exports/useDocusaurusContext.js +3 -9
- package/lib/client/exports/useGlobalData.d.ts +4 -3
- package/lib/client/exports/useGlobalData.js +6 -13
- package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
- package/lib/client/exports/useIsBrowser.js +11 -0
- package/lib/client/exports/useRouteContext.d.ts +8 -0
- package/lib/client/exports/useRouteContext.js +15 -0
- package/lib/client/flat.d.ts +12 -2
- package/lib/client/flat.js +19 -15
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +14 -10
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +12 -32
- package/lib/client/preload.d.ts +3 -4
- package/lib/client/preload.js +5 -12
- package/lib/client/routeContext.d.ts +13 -0
- package/lib/client/routeContext.js +31 -0
- package/lib/client/serverEntry.d.ts +10 -0
- package/lib/client/serverEntry.js +108 -146
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +45 -0
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +2 -26
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +50 -116
- package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/NotFound/index.d.ts} +2 -1
- package/lib/client/theme-fallback/NotFound/index.js +19 -18
- package/lib/client/theme-fallback/Root/index.d.ts +10 -0
- package/lib/client/theme-fallback/Root/index.js +2 -6
- package/lib/client/{exports/context.js → theme-fallback/SiteMetadata/index.d.ts} +2 -2
- package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
- package/lib/commands/build.d.ts +6 -2
- package/lib/commands/build.js +81 -64
- package/lib/commands/clear.d.ts +7 -1
- package/lib/commands/clear.js +34 -21
- package/lib/commands/deploy.d.ts +5 -2
- package/lib/commands/deploy.js +94 -81
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +9 -11
- package/lib/commands/serve.d.ts +8 -2
- package/lib/commands/serve.js +29 -28
- package/lib/commands/start.d.ts +9 -2
- package/lib/commands/start.js +109 -101
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +106 -0
- package/lib/commands/swizzle/common.d.ts +33 -0
- package/lib/commands/swizzle/common.js +56 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +200 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +84 -0
- package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
- package/lib/commands/swizzle/context.js +24 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +119 -0
- package/lib/commands/swizzle/prompts.d.ts +12 -0
- package/lib/commands/swizzle/prompts.js +110 -0
- package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
- package/lib/commands/swizzle/tables.js +113 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +106 -0
- package/lib/commands/writeHeadingIds.d.ts +2 -6
- package/lib/commands/writeHeadingIds.js +22 -81
- package/lib/commands/writeTranslations.d.ts +4 -5
- package/lib/commands/writeTranslations.js +46 -25
- package/lib/index.d.ts +9 -9
- package/lib/index.js +14 -14
- package/lib/server/brokenLinks.d.ts +4 -17
- package/lib/server/brokenLinks.js +67 -56
- package/lib/server/clientModules.d.ts +12 -0
- package/lib/server/clientModules.js +20 -0
- package/lib/server/config.d.ts +5 -2
- package/lib/server/config.js +29 -6
- package/lib/server/configValidation.d.ts +4 -4
- package/lib/server/configValidation.js +86 -41
- package/lib/server/getHostPort.d.ts +14 -0
- package/lib/server/getHostPort.js +79 -0
- package/lib/server/htmlTags.d.ts +12 -0
- package/lib/server/htmlTags.js +62 -0
- package/lib/server/i18n.d.ts +3 -13
- package/lib/server/i18n.js +21 -55
- package/lib/server/index.d.ts +28 -13
- package/lib/server/index.js +83 -165
- package/lib/server/plugins/configs.d.ts +51 -0
- package/lib/server/plugins/configs.js +101 -0
- package/lib/server/plugins/index.d.ts +9 -8
- package/lib/server/plugins/index.js +73 -137
- package/lib/server/plugins/init.d.ts +6 -5
- package/lib/server/plugins/init.js +44 -109
- package/lib/server/plugins/moduleShorthand.d.ts +9 -0
- package/lib/server/plugins/moduleShorthand.js +46 -0
- package/lib/server/plugins/pluginIds.d.ts +5 -1
- package/lib/server/plugins/pluginIds.js +12 -7
- package/lib/server/plugins/presets.d.ts +12 -0
- package/lib/server/plugins/presets.js +49 -0
- package/lib/server/plugins/routeConfig.d.ts +11 -0
- package/lib/server/plugins/routeConfig.js +54 -0
- package/lib/server/plugins/synthetic.d.ts +20 -0
- package/lib/server/plugins/synthetic.js +111 -0
- package/lib/server/routes.d.ts +39 -7
- package/lib/server/routes.js +182 -95
- package/lib/server/siteMetadata.d.ts +12 -0
- package/lib/server/siteMetadata.js +81 -0
- package/lib/server/translations/translations.d.ts +14 -19
- package/lib/server/translations/translations.js +40 -72
- package/lib/server/translations/translationsExtractor.d.ts +10 -4
- package/lib/server/translations/translationsExtractor.js +158 -122
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +7 -9
- package/lib/webpack/aliases/index.d.ts +34 -0
- package/lib/webpack/aliases/index.js +106 -0
- package/lib/webpack/base.d.ts +3 -4
- package/lib/webpack/base.js +45 -57
- package/lib/webpack/client.d.ts +3 -3
- package/lib/webpack/client.js +12 -19
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
- package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -25
- package/lib/webpack/plugins/CleanWebpackPlugin.js +33 -17
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
- package/lib/webpack/plugins/WaitPlugin.js +1 -1
- package/lib/webpack/server.d.ts +5 -5
- package/lib/webpack/server.js +21 -12
- package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
- package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
- package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
- package/lib/webpack/utils.d.ts +15 -31
- package/lib/webpack/utils.js +61 -182
- package/package.json +81 -77
- package/bin/beforeCli.js +0 -100
- package/lib/.tsbuildinfo +0 -1
- package/lib/choosePort.js +0 -105
- package/lib/client/.eslintrc.js +0 -29
- package/lib/client/.tsbuildinfo +0 -1
- package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
- package/lib/client/client-lifecycles-dispatcher.js +0 -27
- package/lib/client/nprogress.css +0 -36
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/commands/commandUtils.d.ts +0 -3
- package/lib/commands/commandUtils.js +0 -21
- package/lib/commands/swizzle.d.ts +0 -9
- package/lib/commands/swizzle.js +0 -245
- package/lib/constants.d.ts +0 -18
- package/lib/constants.js +0 -23
- package/lib/server/client-modules/index.js +0 -14
- package/lib/server/duplicateRoutes.d.ts +0 -10
- package/lib/server/duplicateRoutes.js +0 -38
- package/lib/server/html-tags/htmlTags.js +0 -40
- package/lib/server/html-tags/index.d.ts +0 -9
- package/lib/server/html-tags/index.js +0 -43
- package/lib/server/loadSetup.d.ts +0 -9
- package/lib/server/loadSetup.js +0 -25
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +0 -9
- package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
- package/lib/server/presets/index.d.ts +0 -11
- package/lib/server/presets/index.js +0 -48
- package/lib/server/themes/alias.d.ts +0 -8
- package/lib/server/themes/alias.js +0 -40
- package/lib/server/themes/index.d.ts +0 -12
- package/lib/server/themes/index.js +0 -47
- package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
- package/lib/server/versions/__fixtures__/package.json +0 -3
- package/lib/server/versions/__tests/index.test.js +0 -25
- package/lib/server/versions/index.d.ts +0 -10
- package/lib/server/versions/index.js +0 -50
- package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
- package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
- package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
- package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
- package/lib/webpack/sharedModuleAliases.d.ts +0 -10
- package/lib/webpack/sharedModuleAliases.js +0 -18
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { type ReactElement } from 'react';
|
|
8
|
+
import type { ClientModule } from '@docusaurus/types';
|
|
9
|
+
import type { Location } from 'history';
|
|
10
|
+
export declare function dispatchLifecycleAction<K extends keyof ClientModule>(lifecycleAction: K, ...args: Parameters<NonNullable<ClientModule[K]>>): () => void;
|
|
11
|
+
declare function ClientLifecyclesDispatcher({ children, location, previousLocation, }: {
|
|
12
|
+
children: ReactElement;
|
|
13
|
+
location: Location;
|
|
14
|
+
previousLocation: Location | null;
|
|
15
|
+
}): JSX.Element;
|
|
16
|
+
export default ClientLifecyclesDispatcher;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { useLayoutEffect } from 'react';
|
|
8
|
+
import clientModules from '@generated/client-modules';
|
|
9
|
+
export function dispatchLifecycleAction(lifecycleAction, ...args) {
|
|
10
|
+
const callbacks = clientModules.map((clientModule) => {
|
|
11
|
+
const lifecycleFunction = (clientModule.default?.[lifecycleAction] ??
|
|
12
|
+
clientModule[lifecycleAction]);
|
|
13
|
+
return lifecycleFunction?.(...args);
|
|
14
|
+
});
|
|
15
|
+
return () => callbacks.forEach((cb) => cb?.());
|
|
16
|
+
}
|
|
17
|
+
function scrollAfterNavigation(location) {
|
|
18
|
+
const { hash } = location;
|
|
19
|
+
if (!hash) {
|
|
20
|
+
window.scrollTo(0, 0);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const id = decodeURIComponent(hash.substring(1));
|
|
24
|
+
const element = document.getElementById(id);
|
|
25
|
+
element?.scrollIntoView();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function ClientLifecyclesDispatcher({ children, location, previousLocation, }) {
|
|
29
|
+
useLayoutEffect(() => {
|
|
30
|
+
if (previousLocation !== location) {
|
|
31
|
+
if (previousLocation) {
|
|
32
|
+
scrollAfterNavigation(location);
|
|
33
|
+
}
|
|
34
|
+
dispatchLifecycleAction('onRouteDidUpdate', { previousLocation, location });
|
|
35
|
+
}
|
|
36
|
+
}, [previousLocation, location]);
|
|
37
|
+
return children;
|
|
38
|
+
}
|
|
39
|
+
export default ClientLifecyclesDispatcher;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import { ReactNode } from 'react';
|
|
7
|
+
import { type ReactNode } from 'react';
|
|
8
8
|
declare type LinksCollector = {
|
|
9
9
|
collectLink: (link: string) => void;
|
|
10
10
|
};
|
|
@@ -13,8 +13,8 @@ declare type StatefulLinksCollector = LinksCollector & {
|
|
|
13
13
|
};
|
|
14
14
|
export declare const createStatefulLinksCollector: () => StatefulLinksCollector;
|
|
15
15
|
export declare const useLinksCollector: () => LinksCollector;
|
|
16
|
-
export declare
|
|
16
|
+
export declare function LinksCollectorProvider({ children, linksCollector, }: {
|
|
17
17
|
children: ReactNode;
|
|
18
18
|
linksCollector: LinksCollector;
|
|
19
|
-
})
|
|
19
|
+
}): JSX.Element;
|
|
20
20
|
export {};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import React, { useContext
|
|
7
|
+
import React, { useContext } from 'react';
|
|
8
8
|
export const createStatefulLinksCollector = () => {
|
|
9
9
|
// Set to dedup, as it's not useful to collect multiple times the same link
|
|
10
10
|
const allLinks = new Set();
|
|
@@ -12,20 +12,15 @@ export const createStatefulLinksCollector = () => {
|
|
|
12
12
|
collectLink: (link) => {
|
|
13
13
|
allLinks.add(link);
|
|
14
14
|
},
|
|
15
|
-
getCollectedLinks: () =>
|
|
16
|
-
return [...allLinks];
|
|
17
|
-
},
|
|
15
|
+
getCollectedLinks: () => [...allLinks],
|
|
18
16
|
};
|
|
19
17
|
};
|
|
20
|
-
const Context = createContext({
|
|
18
|
+
const Context = React.createContext({
|
|
21
19
|
collectLink: () => {
|
|
22
|
-
//
|
|
23
|
-
// we only use the broken links checker server-side
|
|
20
|
+
// No-op for client. We only use the broken links checker server-side.
|
|
24
21
|
},
|
|
25
22
|
});
|
|
26
|
-
export const useLinksCollector = () =>
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return React.createElement(Context.Provider, { value: linksCollector }, children);
|
|
31
|
-
};
|
|
23
|
+
export const useLinksCollector = () => useContext(Context);
|
|
24
|
+
export function LinksCollectorProvider({ children, linksCollector, }) {
|
|
25
|
+
return <Context.Provider value={linksCollector}>{children}</Context.Provider>;
|
|
26
|
+
}
|
|
@@ -4,6 +4,20 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import '
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import type { Location } from 'history';
|
|
9
|
+
declare type Props = {
|
|
10
|
+
readonly location: Location;
|
|
11
|
+
readonly children: JSX.Element;
|
|
12
|
+
};
|
|
13
|
+
declare type State = {
|
|
14
|
+
nextRouteHasLoaded: boolean;
|
|
15
|
+
};
|
|
16
|
+
declare class PendingNavigation extends React.Component<Props, State> {
|
|
17
|
+
private previousLocation;
|
|
18
|
+
private routeUpdateCleanupCb;
|
|
19
|
+
constructor(props: Props);
|
|
20
|
+
shouldComponentUpdate(nextProps: Props, nextState: State): boolean;
|
|
21
|
+
render(): JSX.Element;
|
|
22
|
+
}
|
|
23
|
+
export default PendingNavigation;
|
|
@@ -5,19 +5,23 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
|
-
import { Route
|
|
9
|
-
import
|
|
10
|
-
import
|
|
8
|
+
import { Route } from 'react-router-dom';
|
|
9
|
+
import ClientLifecyclesDispatcher, { dispatchLifecycleAction, } from './ClientLifecyclesDispatcher';
|
|
10
|
+
import ExecutionEnvironment from './exports/ExecutionEnvironment';
|
|
11
11
|
import preload from './preload';
|
|
12
|
-
import normalizeLocation from './normalizeLocation';
|
|
13
|
-
import './nprogress.css';
|
|
14
|
-
nprogress.configure({ showSpinner: false });
|
|
15
12
|
class PendingNavigation extends React.Component {
|
|
13
|
+
previousLocation;
|
|
14
|
+
routeUpdateCleanupCb;
|
|
16
15
|
constructor(props) {
|
|
17
16
|
super(props);
|
|
18
17
|
// previousLocation doesn't affect rendering, hence not stored in state.
|
|
19
18
|
this.previousLocation = null;
|
|
20
|
-
this.
|
|
19
|
+
this.routeUpdateCleanupCb = ExecutionEnvironment.canUseDOM
|
|
20
|
+
? dispatchLifecycleAction('onRouteUpdate', {
|
|
21
|
+
previousLocation: null,
|
|
22
|
+
location: this.props.location,
|
|
23
|
+
})
|
|
24
|
+
: () => { };
|
|
21
25
|
this.state = {
|
|
22
26
|
nextRouteHasLoaded: true,
|
|
23
27
|
};
|
|
@@ -25,74 +29,45 @@ class PendingNavigation extends React.Component {
|
|
|
25
29
|
// Intercept location update and still show current route until next route
|
|
26
30
|
// is done loading.
|
|
27
31
|
shouldComponentUpdate(nextProps, nextState) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (routeDidChange) {
|
|
33
|
-
const nextLocation = normalizeLocation(nextProps.location);
|
|
34
|
-
this.startProgressBar(delay);
|
|
35
|
-
// Save the location first.
|
|
36
|
-
this.previousLocation = normalizeLocation(this.props.location);
|
|
37
|
-
this.setState({
|
|
38
|
-
nextRouteHasLoaded: false,
|
|
39
|
-
});
|
|
40
|
-
// Load data while the old screen remains.
|
|
41
|
-
preload(routes, nextLocation.pathname)
|
|
42
|
-
.then(() => {
|
|
43
|
-
clientLifecyclesDispatcher.onRouteUpdate({
|
|
44
|
-
previousLocation: this.previousLocation,
|
|
45
|
-
location: nextLocation,
|
|
46
|
-
});
|
|
47
|
-
// Route has loaded, we can reset previousLocation.
|
|
48
|
-
this.previousLocation = null;
|
|
49
|
-
this.setState({
|
|
50
|
-
nextRouteHasLoaded: true,
|
|
51
|
-
}, this.stopProgressBar);
|
|
52
|
-
const { hash } = nextLocation;
|
|
53
|
-
if (!hash) {
|
|
54
|
-
window.scrollTo(0, 0);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
const id = decodeURIComponent(hash.substring(1));
|
|
58
|
-
const element = document.getElementById(id);
|
|
59
|
-
if (element) {
|
|
60
|
-
element.scrollIntoView();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
.catch((e) => console.warn(e));
|
|
65
|
-
return false;
|
|
32
|
+
if (nextProps.location === this.props.location) {
|
|
33
|
+
// `nextRouteHasLoaded` is false means there's a pending route transition.
|
|
34
|
+
// Don't update until it's done.
|
|
35
|
+
return nextState.nextRouteHasLoaded;
|
|
66
36
|
}
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
37
|
+
// props.location being different means the router is trying to navigate to
|
|
38
|
+
// a new route. We will preload the new route.
|
|
39
|
+
const nextLocation = nextProps.location;
|
|
40
|
+
// Save the location first.
|
|
41
|
+
this.previousLocation = this.props.location;
|
|
42
|
+
this.setState({ nextRouteHasLoaded: false });
|
|
43
|
+
this.routeUpdateCleanupCb = dispatchLifecycleAction('onRouteUpdate', {
|
|
44
|
+
previousLocation: this.previousLocation,
|
|
45
|
+
location: nextLocation,
|
|
46
|
+
});
|
|
47
|
+
// Load data while the old screen remains. Force preload instead of using
|
|
48
|
+
// `window.docusaurus`, because we want to avoid loading screen even when
|
|
49
|
+
// user is on saveData
|
|
50
|
+
preload(nextLocation.pathname)
|
|
51
|
+
.then(() => {
|
|
52
|
+
this.routeUpdateCleanupCb();
|
|
53
|
+
this.setState({ nextRouteHasLoaded: true });
|
|
54
|
+
})
|
|
55
|
+
.catch((e) => {
|
|
56
|
+
console.warn(e);
|
|
57
|
+
// If chunk loading failed, it could be because the path to a chunk
|
|
58
|
+
// no longer exists due to a new deployment. Force refresh the page
|
|
59
|
+
// instead of just not navigating.
|
|
60
|
+
window.location.reload();
|
|
61
|
+
});
|
|
62
|
+
return false;
|
|
92
63
|
}
|
|
93
64
|
render() {
|
|
94
65
|
const { children, location } = this.props;
|
|
95
|
-
|
|
66
|
+
// Use a controlled <Route> to trick all descendants into rendering the old
|
|
67
|
+
// location.
|
|
68
|
+
return (<ClientLifecyclesDispatcher previousLocation={this.previousLocation} location={location}>
|
|
69
|
+
<Route location={location} render={() => children}/>
|
|
70
|
+
</ClientLifecyclesDispatcher>);
|
|
96
71
|
}
|
|
97
72
|
}
|
|
98
|
-
export default
|
|
73
|
+
export default PendingNavigation;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import Head from '@docusaurus/Head';
|
|
9
|
+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
10
|
+
import useBaseUrl from '@docusaurus/useBaseUrl';
|
|
11
|
+
export default function SiteMetadataDefaults() {
|
|
12
|
+
const { siteConfig: { favicon, title }, i18n: { currentLocale, localeConfigs }, } = useDocusaurusContext();
|
|
13
|
+
const faviconUrl = useBaseUrl(favicon);
|
|
14
|
+
const { htmlLang, direction: htmlDir } = localeConfigs[currentLocale];
|
|
15
|
+
return (<Head>
|
|
16
|
+
<html lang={htmlLang} dir={htmlDir}/>
|
|
17
|
+
<title>{title}</title>
|
|
18
|
+
<meta property="og:title" content={title}/>
|
|
19
|
+
{favicon && <link rel="icon" href={faviconUrl}/>}
|
|
20
|
+
</Head>);
|
|
21
|
+
}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
import React, { type ReactNode } from 'react';
|
|
8
|
+
export declare const Context: React.Context<boolean>;
|
|
9
|
+
export declare function BrowserContextProvider({ children, }: {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React, { useEffect, useState } from 'react';
|
|
8
|
+
// Encapsulate the logic to avoid React hydration problems
|
|
9
|
+
// See https://www.joshwcomeau.com/react/the-perils-of-rehydration/
|
|
10
|
+
// On first client-side render, we need to render exactly as the server rendered
|
|
11
|
+
// isBrowser is set to true only after a successful hydration
|
|
12
|
+
// Note, isBrowser is not part of useDocusaurusContext() for perf reasons
|
|
13
|
+
// Using useDocusaurusContext() (much more common need) should not trigger
|
|
14
|
+
// re-rendering after a successful hydration
|
|
15
|
+
export const Context = React.createContext(false);
|
|
16
|
+
export function BrowserContextProvider({ children, }) {
|
|
17
|
+
const [isBrowser, setIsBrowser] = useState(false);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
setIsBrowser(true);
|
|
20
|
+
}, []);
|
|
21
|
+
return <Context.Provider value={isBrowser}>{children}</Context.Provider>;
|
|
22
|
+
}
|
|
@@ -5,23 +5,28 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
|
-
import
|
|
8
|
+
import ReactDOM from 'react-dom';
|
|
9
9
|
import { BrowserRouter } from 'react-router-dom';
|
|
10
|
-
import
|
|
10
|
+
import { HelmetProvider } from 'react-helmet-async';
|
|
11
11
|
import ExecutionEnvironment from './exports/ExecutionEnvironment';
|
|
12
12
|
import App from './App';
|
|
13
13
|
import preload from './preload';
|
|
14
14
|
import docusaurus from './docusaurus';
|
|
15
|
-
// Client-side render (e.g: running in browser) to become single-page
|
|
15
|
+
// Client-side render (e.g: running in browser) to become single-page
|
|
16
|
+
// application (SPA).
|
|
16
17
|
if (ExecutionEnvironment.canUseDOM) {
|
|
17
18
|
window.docusaurus = docusaurus;
|
|
18
|
-
// For production, attempt to hydrate existing markup for performant
|
|
19
|
+
// For production, attempt to hydrate existing markup for performant
|
|
20
|
+
// first-load experience.
|
|
19
21
|
// For development, there is no existing markup so we had to render it.
|
|
20
|
-
//
|
|
21
|
-
const renderMethod = process.env.NODE_ENV === 'production' ? hydrate : render;
|
|
22
|
-
preload(
|
|
23
|
-
renderMethod(
|
|
24
|
-
|
|
22
|
+
// We also preload async component to avoid first-load loading screen.
|
|
23
|
+
const renderMethod = process.env.NODE_ENV === 'production' ? ReactDOM.hydrate : ReactDOM.render;
|
|
24
|
+
preload(window.location.pathname).then(() => {
|
|
25
|
+
renderMethod(<HelmetProvider>
|
|
26
|
+
<BrowserRouter>
|
|
27
|
+
<App />
|
|
28
|
+
</BrowserRouter>
|
|
29
|
+
</HelmetProvider>, document.getElementById('__docusaurus'));
|
|
25
30
|
});
|
|
26
31
|
// Webpack Hot Module Replacement API
|
|
27
32
|
if (module.hot) {
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
1
7
|
declare global {
|
|
2
8
|
const __webpack_require__: {
|
|
3
9
|
gca: (name: string) => string;
|
|
4
10
|
};
|
|
5
11
|
interface Navigator {
|
|
6
|
-
connection
|
|
12
|
+
connection?: {
|
|
7
13
|
effectiveType: string;
|
|
8
14
|
saveData: boolean;
|
|
9
15
|
};
|
|
10
16
|
}
|
|
11
17
|
}
|
|
12
|
-
declare const
|
|
13
|
-
prefetch
|
|
14
|
-
preload
|
|
15
|
-
}
|
|
16
|
-
export default
|
|
18
|
+
declare const _default: Readonly<{
|
|
19
|
+
prefetch(routePath: string): false | Promise<void[]>;
|
|
20
|
+
preload(routePath: string): false | Promise<void[]>;
|
|
21
|
+
}>;
|
|
22
|
+
export default _default;
|
package/lib/client/docusaurus.js
CHANGED
|
@@ -10,64 +10,51 @@ import routes from '@generated/routes';
|
|
|
10
10
|
import prefetchHelper from './prefetch';
|
|
11
11
|
import preloadHelper from './preload';
|
|
12
12
|
import flat from './flat';
|
|
13
|
-
const fetched =
|
|
14
|
-
const loaded =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
return false;
|
|
24
|
-
};
|
|
25
|
-
const canPrefetch = (routePath) => !isSlowConnection() && !loaded[routePath] && !fetched[routePath];
|
|
26
|
-
const canPreload = (routePath) => !isSlowConnection() && !loaded[routePath];
|
|
27
|
-
const flatten = (arrays) => Array.prototype.concat.apply([], arrays);
|
|
13
|
+
const fetched = new Set();
|
|
14
|
+
const loaded = new Set();
|
|
15
|
+
// If user is on slow or constrained connection.
|
|
16
|
+
const isSlowConnection = () => navigator.connection?.effectiveType.includes('2g') ||
|
|
17
|
+
navigator.connection?.saveData;
|
|
18
|
+
const canPrefetch = (routePath) => !isSlowConnection() && !loaded.has(routePath) && !fetched.has(routePath);
|
|
19
|
+
const canPreload = (routePath) => !isSlowConnection() && !loaded.has(routePath);
|
|
20
|
+
const getChunkNamesToLoad = (path) => Object.entries(routesChunkNames)
|
|
21
|
+
.filter(
|
|
28
22
|
// Remove the last part containing the route hash
|
|
29
23
|
// input: /blog/2018/12/14/Happy-First-Birthday-Slash-fe9
|
|
30
24
|
// output: /blog/2018/12/14/Happy-First-Birthday-Slash
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return flatten(Object.entries(routesChunkNames)
|
|
34
|
-
.filter(([routeNameWithHash]) => removeRouteNameHash(routeNameWithHash) === path)
|
|
35
|
-
.map(([, routeChunks]) => {
|
|
36
|
-
// flat() is useful for nested chunk names, it's not like array.flat()
|
|
37
|
-
return Object.values(flat(routeChunks));
|
|
38
|
-
}));
|
|
39
|
-
};
|
|
25
|
+
([routeNameWithHash]) => routeNameWithHash.replace(/-[^-]+$/, '') === path)
|
|
26
|
+
.flatMap(([, routeChunks]) => Object.values(flat(routeChunks)));
|
|
40
27
|
const docusaurus = {
|
|
41
|
-
prefetch
|
|
28
|
+
prefetch(routePath) {
|
|
42
29
|
if (!canPrefetch(routePath)) {
|
|
43
30
|
return false;
|
|
44
31
|
}
|
|
45
|
-
|
|
46
|
-
fetched[routePath] = true;
|
|
32
|
+
fetched.add(routePath);
|
|
47
33
|
// Find all webpack chunk names needed.
|
|
48
34
|
const matches = matchRoutes(routes, routePath);
|
|
49
|
-
const chunkNamesNeeded =
|
|
35
|
+
const chunkNamesNeeded = matches.flatMap((match) => getChunkNamesToLoad(match.route.path));
|
|
50
36
|
// Prefetch all webpack chunk assets file needed.
|
|
51
|
-
chunkNamesNeeded.
|
|
52
|
-
// "__webpack_require__.gca" is
|
|
53
|
-
//
|
|
54
|
-
// eslint-disable-next-line
|
|
37
|
+
return Promise.all(chunkNamesNeeded.map((chunkName) => {
|
|
38
|
+
// "__webpack_require__.gca" is injected by ChunkAssetPlugin. Pass it
|
|
39
|
+
// the name of the chunk you want to load and it will return its URL.
|
|
40
|
+
// eslint-disable-next-line camelcase
|
|
55
41
|
const chunkAsset = __webpack_require__.gca(chunkName);
|
|
56
|
-
// In some cases, webpack might decide to optimize further
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
|
|
42
|
+
// In some cases, webpack might decide to optimize further, leading to
|
|
43
|
+
// the chunk assets being merged to another chunk. In this case, we can
|
|
44
|
+
// safely filter it out and don't need to load it.
|
|
45
|
+
if (chunkAsset && !chunkAsset.includes('undefined')) {
|
|
46
|
+
return prefetchHelper(chunkAsset);
|
|
60
47
|
}
|
|
61
|
-
|
|
62
|
-
|
|
48
|
+
return Promise.resolve();
|
|
49
|
+
}));
|
|
63
50
|
},
|
|
64
|
-
preload
|
|
51
|
+
preload(routePath) {
|
|
65
52
|
if (!canPreload(routePath)) {
|
|
66
53
|
return false;
|
|
67
54
|
}
|
|
68
|
-
loaded
|
|
69
|
-
preloadHelper(
|
|
70
|
-
return true;
|
|
55
|
+
loaded.add(routePath);
|
|
56
|
+
return preloadHelper(routePath);
|
|
71
57
|
},
|
|
72
58
|
};
|
|
73
|
-
|
|
59
|
+
// This object is directly mounted onto window, better freeze it
|
|
60
|
+
export default Object.freeze(docusaurus);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React, { type ReactNode } from 'react';
|
|
8
|
+
import type { DocusaurusContext } from '@docusaurus/types';
|
|
9
|
+
export declare const Context: React.Context<DocusaurusContext>;
|
|
10
|
+
export declare function DocusaurusContextProvider({ children, }: {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import siteConfig from '@generated/docusaurus.config';
|
|
9
|
+
import globalData from '@generated/globalData';
|
|
10
|
+
import i18n from '@generated/i18n';
|
|
11
|
+
import codeTranslations from '@generated/codeTranslations';
|
|
12
|
+
import siteMetadata from '@generated/site-metadata';
|
|
13
|
+
// Static value on purpose: don't make it dynamic!
|
|
14
|
+
// Using context is still useful for testability reasons.
|
|
15
|
+
const contextValue = {
|
|
16
|
+
siteConfig,
|
|
17
|
+
siteMetadata,
|
|
18
|
+
globalData,
|
|
19
|
+
i18n,
|
|
20
|
+
codeTranslations,
|
|
21
|
+
};
|
|
22
|
+
export const Context = React.createContext(contextValue);
|
|
23
|
+
export function DocusaurusContextProvider({ children, }) {
|
|
24
|
+
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
|
|
25
|
+
}
|
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
/// <reference types="@docusaurus/module-type-aliases" />
|
|
7
8
|
/// <reference types="react" />
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
fallback?: JSX.Element;
|
|
11
|
-
}): JSX.Element | null;
|
|
12
|
-
export default BrowserOnly;
|
|
9
|
+
import type { Props } from '@docusaurus/BrowserOnly';
|
|
10
|
+
export default function BrowserOnly({ children, fallback, }: Props): JSX.Element | null;
|
|
@@ -4,13 +4,19 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import React from 'react';
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
import React, { isValidElement } from 'react';
|
|
8
|
+
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
9
|
+
// Similar comp to the one described here:
|
|
10
|
+
// https://www.joshwcomeau.com/react/the-perils-of-rehydration/#abstractions
|
|
11
|
+
export default function BrowserOnly({ children, fallback, }) {
|
|
12
|
+
const isBrowser = useIsBrowser();
|
|
13
|
+
if (isBrowser) {
|
|
14
|
+
if (typeof children !== 'function' &&
|
|
15
|
+
process.env.NODE_ENV === 'development') {
|
|
16
|
+
throw new Error(`Docusaurus error: The children of <BrowserOnly> must be a "render function", e.g. <BrowserOnly>{() => <span>{window.location.href}</span>}</BrowserOnly>.
|
|
17
|
+
Current type: ${isValidElement(children) ? 'React element' : typeof children}`);
|
|
18
|
+
}
|
|
19
|
+
return <>{children?.()}</>;
|
|
13
20
|
}
|
|
14
|
-
return fallback
|
|
21
|
+
return fallback ?? null;
|
|
15
22
|
}
|
|
16
|
-
export default BrowserOnly;
|
|
@@ -5,5 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import Loadable from 'react-loadable';
|
|
8
|
-
declare
|
|
9
|
-
|
|
8
|
+
declare global {
|
|
9
|
+
interface NodeRequire {
|
|
10
|
+
resolveWeak: (name: string) => number;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export default function ComponentCreator(path: string, hash: string): ReturnType<typeof Loadable>;
|