gatsby
Version:
Blazing fast modern site generator for React
28 lines (27 loc) • 1.05 kB
JavaScript
exports.__esModule = true;
exports.injectPartytownSnippet = injectPartytownSnippet;
var _integration = require("@builder.io/partytown/integration");
var _getForwards = require("./get-forwards");
// Adapted from https://github.com/BuilderIO/partytown/blob/main/src/react/snippet.tsx to only include CSR logic
function injectPartytownSnippet(collectedScripts) {
if (!collectedScripts.length) {
return;
}
const existingSnippet = document.querySelector(`script[data-partytown]`);
const existingSandbox = document.querySelector(`iframe[src*="~partytown/partytown-sandbox-sw"]`);
if (existingSnippet) {
existingSnippet.remove();
}
if (existingSandbox) {
existingSandbox.remove();
}
const forwards = (0, _getForwards.getForwards)(collectedScripts);
const snippet = document.createElement(`script`);
snippet.dataset.partytown = ``;
snippet.innerHTML = (0, _integration.partytownSnippet)({
forward: forwards
});
document.head.appendChild(snippet);
}
//# sourceMappingURL=inject-partytown-snippet.js.map
;