-
Notifications
You must be signed in to change notification settings - Fork 30
Fix content loss by transforming legacy div and h1 tags #15235
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
base: main
Are you sure you want to change the base?
Conversation
|
Hello 👋! When you're ready to run Chromatic, please apply the You will need to reapply the label each time you want to run Chromatic. |
| }; | ||
| }, | ||
| div: 'p', | ||
| h1: 'h2', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, what error did you find in the logs that could be fixed by this change? And what is the reason for making div to be p and h1 to become h2? Why couldn't we keep them as div and h1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- This generates around 2000 warns a day see logs . Because we return null on unknown tags, we discard all nested children. In old sports blogs, DIV wrappers cause entire team lineups to be deleted from the page.
- We transform H1 to H2 so that we maintain the best practice of only one H1 per page.
- Transforming DIV to P allows us to inherit standard styling. This is much cleaner than adding redundant switch cases and CSS to handle legacy elements.
What does this change?
TextBlockComponentcurrently returnsnullwhen it encounters unknown tags like<div>(common in 2013/14 legacy content) or<h1>. This causes content loss because recursion stops and all child elements are discarded. This PR updatessanitiserOptionsto transformdivtopandh1toh2before they reach the renderer.Why?
Part of guardian/frontend#28496