Skip to content

Commit

Permalink
fix(gatsby): prevent escaping textContent for scripts (#36174)
Browse files Browse the repository at this point in the history
* prevent escaping textContent for <script> data blocks

* fix typo

* touch up

* spread attributes

* add gatsby-head attribute

* unescape for all script tags

(cherry picked from commit d42243c)
  • Loading branch information
marvinjude authored and LekoArts committed Jul 20, 2022
1 parent 53bedf1 commit 5e58db0
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions packages/gatsby/cache-dir/head/head-export-handler-for-ssr.js
Expand Up @@ -56,20 +56,31 @@ export function headHandlerForSSR({

const seenIds = new Map()
for (const node of headNodes) {
const { rawTagName, attributes } = node
const id = attributes.id
const { rawTagName } = node
const id = node.attributes.id

if (!VALID_NODE_NAMES.includes(rawTagName)) {
warnForInvalidTags(rawTagName)
} else {
const element = createElement(
rawTagName,
{
...attributes,
"data-gatsby-head": true,
},
node.childNodes[0]?.textContent
)
let element
const attributes = { ...node.attributes, "data-gatsby-head": true }
if (rawTagName === `script`) {
element = (
<script
{...attributes}
dangerouslySetInnerHTML={{
__html: node.text,
}}
/>
)
} else {
element = (
<node.rawTagName {...attributes}>
{node.childNodes[0]?.textContent}
</node.rawTagName>
)
}

if (id) {
if (!seenIds.has(id)) {
validHeadNodes.push(element)
Expand Down

0 comments on commit 5e58db0

Please sign in to comment.