-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgatsby-ssr.js
61 lines (55 loc) · 1.81 KB
/
gatsby-ssr.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
50
51
52
53
54
55
56
57
58
59
60
61
/**
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/ssr-apis/
*/
// You can delete this file if you're not using it
import React from "react"
import Intercom from "decentraland-gatsby/dist/components/Development/Intercom"
import Segment from "decentraland-gatsby/dist/components/Development/Segment"
import Sentry from "decentraland-gatsby/dist/components/Development/Sentry"
export { wrapPageElement, wrapRootElement } from "./gatsby-browser"
/**
* @see https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/#onPreRenderHTML
*/
export function onPreRenderHTML(
{
pathname,
getHeadComponents,
replaceHeadComponents,
getPreBodyComponents,
replacePreBodyComponents,
getPostBodyComponents,
replacePostBodyComponents,
},
pluginOptions
) {
const headComponents = getHeadComponents()
.concat([
<script
dangerouslySetInnerHTML={{
__html:
"if (typeof window !== 'undefined' && 'serviceWorker' in navigator) {window.navigator.serviceWorker.getRegistrations().then(registrations => {registrations.forEach(r => r.unregister())})}",
}}
></script>,
])
.map((component, i) => {
if (component.type !== "style" || !component.props["data-href"]) {
return component
}
return (
<link
key={i}
rel="stylesheet"
id={component.props.id}
href={component.props["data-href"]}
/>
)
})
const postBodyComponents = [...getPostBodyComponents()]
postBodyComponents.push(<Segment key="segment" trackPage={false} />)
postBodyComponents.push(<Intercom key="intercom" />)
postBodyComponents.push(<Sentry key="sentry" />)
replaceHeadComponents(headComponents)
replacePostBodyComponents(postBodyComponents)
}