-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-browser.js
49 lines (43 loc) · 1.35 KB
/
gatsby-browser.js
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
const React = require('react')
const {
PrismicPreviewProvider,
componentResolverFromMap,
} = require('gatsby-plugin-prismic-previews')
const PrismicProvider = require('@prismicio/react').PrismicProvider
const GatsbyLink = require('gatsby').Link
const linkResolver = require('./src/utils/linkResolver').linkResolver
const PageTemplate = require('./src/pages/page')
/**
* An adapter to support Gatsby's `<Link>` component when using `<PrismicLink>`.
*/
const GatsbyLinkShim = React.forwardRef(({ href, ...props }, ref) => {
return <GatsbyLink to={href} ref={ref} {...props} />
})
GatsbyLinkShim.displayName = 'GatsbyLinkShim'
exports.wrapRootElement = ({ element }) => (
<PrismicProvider
linkResolver={linkResolver}
internalLinkComponent={GatsbyLinkShim}
>
<PrismicPreviewProvider
repositoryConfigs={[
{
repositoryName: process.env.GATSBY_PRISMIC_REPO_NAME,
linkResolver,
componentResolver: componentResolverFromMap({
page: PageTemplate,
}),
},
]}
>
{element}
</PrismicPreviewProvider>
</PrismicProvider>
)
exports.onClientEntry = () => {
// IntersectionObserver polyfill for gatsby-background-image (Safari, IE)
if (!(`IntersectionObserver` in window)) {
import(`intersection-observer`)
console.log(`# IntersectionObserver is polyfilled!`)
}
}