freeCodeCamp/client/gatsby-browser.js
Valeriy 3a2db4744d fix(client): disable core prefetching due to scrolling performance in the map (#35512)
- [x] I have read [freeCodeCamp's contribution guidelines](https://github.com/freeCodeCamp/freeCodeCamp/blob/master/CONTRIBUTING.md).
- [x] My pull request has a descriptive title (not a vague title like `Update index.md`)
- [x] My pull request targets the `master` branch of freeCodeCamp.
- [x] None of my changes are plagiarized from another source without proper attribution.

Closes #35418

It disables only prefetching on link become visible, other prefetching strategies like prefetching on link hover still work.
2019-03-06 12:30:19 +05:30

62 lines
1.5 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import { Provider } from 'react-redux';
import { createStore } from './src/redux/createStore';
import AppMountNotifier from './src/components/AppMountNotifier';
import {
CertificationLayout,
DefaultLayout,
GuideLayout
} from './src/components/layouts';
const store = createStore();
export const wrapRootElement = ({ element }) => {
return (
<Provider store={store}>
<AppMountNotifier render={() => element} />
</Provider>
);
};
wrapRootElement.propTypes = {
element: PropTypes.any
};
export const wrapPageElement = ({ element, props }) => {
const {
location: { pathname }
} = props;
if (pathname === '/') {
return (
<DefaultLayout disableSettings={true} landingPage={true}>
{element}
</DefaultLayout>
);
}
if (/^\/certification(\/.*)*/.test(pathname)) {
return <CertificationLayout>{element}</CertificationLayout>;
}
if (/^\/guide(\/.*)*/.test(pathname)) {
return (
<DefaultLayout onGuide={true}>
<GuideLayout>{element}</GuideLayout>
</DefaultLayout>
);
}
if (/^\/learn(\/.*)*/.test(pathname)) {
return <DefaultLayout showFooter={false}>{element}</DefaultLayout>;
}
return <DefaultLayout>{element}</DefaultLayout>;
};
wrapPageElement.propTypes = {
element: PropTypes.any,
location: PropTypes.objectOf({ pathname: PropTypes.string }),
props: PropTypes.any
};
export const disableCorePrefetching = () => true;