Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): prevent escaping textContent for scripts #36174

Merged
merged 6 commits into from
Jul 20, 2022

Conversation

marvinjude
Copy link
Contributor

@marvinjude marvinjude commented Jul 19, 2022

Description

Prevent auto escaping of textContent for <script> tags.

See Discussion

Documentation

https://www.gatsbyjs.com/docs/how-to/adding-common-features/adding-seo-component/#rich-snippets

[sc-53448]

@marvinjude marvinjude added the type: bug An issue or pull request relating to a bug in Gatsby label Jul 19, 2022
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jul 19, 2022
@marvinjude marvinjude removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jul 19, 2022
@LekoArts LekoArts added topic: DX Developer Experience (e.g. Fast Refresh, i18n, SSR, page creation, starters) and removed type: bug An issue or pull request relating to a bug in Gatsby labels Jul 20, 2022
@marvinjude marvinjude changed the title fix(gatsby): prevent escaping textContent for <script> data blocks fix(gatsby): prevent escaping textContent for head elements Jul 20, 2022
)
let element
const attributes = { ...node.attributes, "data-gatsby-head": true }
if (rawTagName === `script`) {
Copy link
Contributor Author

@marvinjude marvinjude Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React isn't happy with doing dangerouslySetInnerHTML on <title> so it makes sense to keep this for scripts alone

@marvinjude marvinjude changed the title fix(gatsby): prevent escaping textContent for head elements fix(gatsby): prevent escaping textContent scripts Jul 20, 2022
@marvinjude marvinjude changed the title fix(gatsby): prevent escaping textContent scripts fix(gatsby): prevent escaping textContent for scripts Jul 20, 2022
@LekoArts LekoArts merged commit d42243c into master Jul 20, 2022
@LekoArts LekoArts deleted the prev-escaping-text-for-data-block branch July 20, 2022 10:45
LekoArts pushed a commit that referenced this pull request Jul 20, 2022
* 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)
LekoArts pushed a commit that referenced this pull request Jul 20, 2022
@LekoArts
Copy link
Contributor

Fixed in [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: DX Developer Experience (e.g. Fast Refresh, i18n, SSR, page creation, starters)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants