-
Notifications
You must be signed in to change notification settings - Fork 41
/
gatsby-browser.tsx
51 lines (40 loc) · 1.45 KB
/
gatsby-browser.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import type { GatsbyBrowser } from 'gatsby';
import './src/styles/global.css';
import { reducerFlashes } from '@ably/ui/core/Flash';
import {
attachStoreToWindow,
createRemoteDataStore,
reducerBlogPosts,
reducerSessionData,
} from '@ably/ui/core/scripts';
import { reducerApiKeyData } from './src/redux/api-key/api-key-reducer';
const onClientEntry: GatsbyBrowser['onClientEntry'] = () => {
const store = createRemoteDataStore({
...reducerBlogPosts,
...reducerSessionData,
...reducerApiKeyData,
...reducerFlashes,
});
attachStoreToWindow(store);
};
/**
* The 'shouldUpdateScroll' function will fire when navigating to new pages within Gatsby
*/
const shouldUpdateScroll: GatsbyBrowser['shouldUpdateScroll'] = ({ prevRouterProps, routerProps: { location } }) => {
if (!prevRouterProps || !location) {
return false;
}
const curr = location.pathname;
const prev = prevRouterProps.location.pathname;
return (
curr !== prev && // If the current location is a variant of the previous location, do not update scroll
!(curr.indexOf('#') > -1) &&
!(prev.indexOf('#') > -1) // If we're going to or from any hash link on page B from page A, do not update scroll; we want to visit the specific section
);
};
/**
* Load our user state
*/
import UserContextWrapper from './src/contexts/user-context/wrap-with-provider';
const wrapRootElement = UserContextWrapper;
export { onClientEntry, shouldUpdateScroll, wrapRootElement };