UNPKG

gatsby-plugin-styled-components

Version:
27 lines (25 loc) 1.06 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _react = _interopRequireDefault(require("react")); var _styledComponents = require("styled-components"); var sheetByPathname = new Map(); // eslint-disable-next-line react/prop-types,react/display-name exports.wrapRootElement = function (_ref, pluginOptions) { var element = _ref.element, pathname = _ref.pathname; var sheet = new _styledComponents.ServerStyleSheet(); sheetByPathname.set(pathname, sheet); return /*#__PURE__*/_react.default.createElement(_styledComponents.StyleSheetManager, { sheet: sheet.instance, disableVendorPrefixes: pluginOptions === null || pluginOptions === void 0 ? void 0 : pluginOptions.disableVendorPrefixes }, element); }; exports.onRenderBody = function (_ref2) { var setHeadComponents = _ref2.setHeadComponents, pathname = _ref2.pathname; var sheet = sheetByPathname.get(pathname); if (sheet) { setHeadComponents([sheet.getStyleElement()]); sheetByPathname.delete(pathname); } };