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: invalid structured data ld+json #685

Merged
merged 2 commits into from
Jan 27, 2024
Merged

Conversation

lucymtc
Copy link
Contributor

@lucymtc lucymtc commented Jan 27, 2024

Description of the Change

Because react treats the contents as text and automatically escapes any content, using createElement on ld+json it escapes the JSON string. Special characters like quotes (") are being converted to their HTML entity (") causing an invalid json.
Solution: Return script with "dangerouslySetInnerHTML" bypassing react escaping to make sure the JSON is inserted in the DOM without alterations and remain valid.

Steps to replicate the error:

  • Run the nextjs project.
  • View source code.
  • See the json being transformed into html entities.
  • Copy the code into https://validator.schema.org
  • See Error: Missing '}' or object member name.

Closes #

How to test the Change

  • Run the nextjs project.
  • View source code.
  • See the json being transformed into html entities.
  • Copy the code into https://validator.schema.org
  • Validator test passes,

Changelog Entry

Added - New feature
Changed - Existing functionality
Deprecated - Soon-to-be removed feature
Removed - Feature
Fixed - Bug fix
Security - Vulnerability

Credits

Props @username, @username2, ...

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

Copy link

changeset-bot bot commented Jan 27, 2024

🦋 Changeset detected

Latest commit: c5c3df8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@headstartwp/next Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jan 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
headstarwp ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 27, 2024 6:48pm

Copy link
Contributor

📦 Next.js Bundle Analysis for @10up/headless_framework%0A%0AThis analysis was generated by the Next.js Bundle Analysis action. 🤖%0A%0AThis PR introduced no changes to the JavaScript bundle! 🙌

Copy link
Contributor

📦 Next.js Bundle Analysis for @10up/headless_framework

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@nicholasio nicholasio merged commit 6a35eaa into develop Jan 27, 2024
11 checks passed
@nicholasio nicholasio deleted the fix/invalid-structured-data branch January 27, 2024 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants