Skip to content

Commit

Permalink
fix(antdsite): don't trigger ngprocess when links don't change.
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyi7099 committed Aug 12, 2019
1 parent 664ce99 commit 137ff27
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 17 additions & 11 deletions packages/antdsite/src/default-theme/components/MyLink/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import React from 'react';
import { Link } from 'gatsby';
import { Link as RouterLink } from '@reach/router';
import { PageContext } from 'antdsite/src/templates/PageContext';
import { resolvePathWithBase } from '../utils';
import { resolvePathWithBase, normalize } from '../utils';
import NProgress from 'nprogress';

function handleLinkClick() {
function handleLinkClick(from: string, to: string) {
to = normalize(to);
if (from == to) return;

NProgress.start();
NProgress.set(0.6);
}
Expand All @@ -22,17 +25,20 @@ const MyLink: React.SFC<any> = ({
prefetch: boolean;
onClick: (e: any) => void;
}) => {
let clickMerged = handleLinkClick;

if (onClick) {
clickMerged = (...args) => {
onClick.apply(null, args);
handleLinkClick();
};
}
return (
<PageContext.Consumer>
{({ webConfig: { base, prefetch: globalPrefetch } }) => {
{({ webConfig: { base, prefetch: globalPrefetch }, slug }) => {
let clickMerged = () => {
handleLinkClick(slug, to);
};

if (onClick) {
clickMerged = (...args) => {
onClick.apply(null, args);
handleLinkClick(slug, to);
};
}

if (!prefetch || !globalPrefetch) {
return (
<RouterLink onClick={clickMerged} to={resolvePathWithBase(to, base)} {...rest}>
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"clean": "gatsby clean"
},
"dependencies": {
"antdsite": "^0.6.1",
"antdsite": "^0.6.2",
"gatsby": "^2.13.39",
"gatsby-plugin-netlify": "^2.0.0",
"react": "^16.8.0",
Expand Down

0 comments on commit 137ff27

Please sign in to comment.