refactor(core): type improvements for `PendingNavigation` (#5580)

* Fix type

* Completely fix

* Fix type
This commit is contained in:
Joshua Chen 2021-09-21 15:05:42 +08:00 committed by GitHub
parent 7f770ae621
commit e0aa87fe7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 8 deletions

View File

@ -23,7 +23,7 @@ function App(): JSX.Element {
<BrowserContextProvider>
<Root>
<BaseUrlIssueBanner />
<PendingNavigation routes={routes}>
<PendingNavigation routes={routes} delay={1000}>
{renderRoutes(routes)}
</PendingNavigation>
</Root>

View File

@ -6,29 +6,30 @@
*/
import React from 'react';
import {Route, withRouter} from 'react-router-dom';
import {Route, withRouter, RouteComponentProps} from 'react-router-dom';
import {RouteConfig} from 'react-router-config';
import nprogress from 'nprogress';
import clientLifecyclesDispatcher from './client-lifecycles-dispatcher';
import preload from './preload';
import normalizeLocation from './normalizeLocation';
import type {Location} from '@docusaurus/history';
import './nprogress.css';
nprogress.configure({showSpinner: false});
interface Props {
interface Props extends RouteComponentProps {
routes: RouteConfig[];
delay: number;
location: any;
location: Location;
}
interface State {
nextRouteHasLoaded: boolean;
}
class PendingNavigation extends React.Component<Props, State> {
previousLocation: any;
previousLocation: Location | null;
progressBarTimeout: NodeJS.Timeout | null;
constructor(props: Props) {
@ -46,7 +47,7 @@ class PendingNavigation extends React.Component<Props, State> {
// is done loading.
shouldComponentUpdate(nextProps: Props, nextState: State) {
const routeDidChange = nextProps.location !== this.props.location;
const {routes, delay = 1000} = this.props;
const {routes, delay} = this.props;
// If `routeDidChange` is true, means the router is trying to navigate to a new
// route. We will preload the new route.
@ -128,4 +129,4 @@ class PendingNavigation extends React.Component<Props, State> {
}
}
export default withRouter(PendingNavigation as any) as any;
export default withRouter(PendingNavigation);

View File

@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
type Location = {pathname: string};
import type {Location} from '@docusaurus/history';
// Memoize previously normalized pathnames.
const pathnames: Record<string, string> = {};