UNPKG

1.39 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4exports.__esModule = true;
5exports.onRenderBody = void 0;
6var _react = _interopRequireDefault(require("react"));
7var _gatsbyScript = require("gatsby-script");
8var _getForwards = require("./utils/get-forwards");
9var _integration = require("@builder.io/partytown/integration");
10const onRenderBody = ({
11 pathname,
12 setHeadComponents
13}) => {
14 const collectedScripts = _gatsbyScript.collectedScriptsByPage.get(pathname);
15 if (!(collectedScripts !== null && collectedScripts !== void 0 && collectedScripts.length)) {
16 return;
17 }
18 const forwards = (0, _getForwards.getForwards)(collectedScripts);
19
20 // Adapted from https://github.com/BuilderIO/partytown/blob/main/src/react/snippet.tsx to only include SSR logic
21 setHeadComponents([/*#__PURE__*/_react.default.createElement("script", {
22 key: "partytown",
23 "data-partytown": "",
24 suppressHydrationWarning: true,
25 dangerouslySetInnerHTML: {
26 __html: `
27 ${(0, _integration.partytownSnippet)({
28 forward: forwards
29 })}
30 document.currentScript.dataset.partytown=""
31 `
32 }
33 })]);
34
35 // Clear scripts after we've used them to avoid leaky behavior
36 _gatsbyScript.collectedScriptsByPage.delete(pathname);
37};
38exports.onRenderBody = onRenderBody;
39//# sourceMappingURL=gatsby-ssr.js.map
\No newline at end of file