Invalid HTML inside `dangerouslySetInnerHTML` breaks the page.
See original GitHub issueBug report
Describe the bug
If invalid HTML is added to dangerouslySetInnerHTML
, Next.js will output a blank page without providing any feedback. This can be hard to track when working with a CMS provider or markdown files.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Clone https://github.com/lfades/nextjs-inner-html-bug
- Run
yarn && yarn dev
ornpm i && npm run dev
- See that
pages/index.js
is a blank page with no errors
Expected behavior
Invalid HTML inside dangerouslySetInnerHTML
should throw and/or let the user know that there’s something wrong.
The demo also has an index.html
and index.js
in the root directory that shows how the same code works in React alone, it doesn’t produce an error either, but it shows the content.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Does dangerouslySetInnerHTML prevent invalid HTML from ...
I am trying to figure out whether a user might break their website by providing invalid HTML input, but have been unsuccessful so...
Read more >Using dangerouslySetInnerHTML in a React application
Learn why you should use the dangerouslySetInnerHTML property in your React application and how to apply it safely within your code.
Read more >Using dangerouslySetInnerHTML - Getting Started with DOM
Here is the conclusion: using the React dangerouslySetInnerHTML is great for rendering HTML markups on-page, especially dynamic ones that can be ...
Read more >Dangerously Set innerHTML | React
The prop name dangerouslySetInnerHTML is intentionally chosen to be ... a new object containing only the key __html and your sanitized data as...
Read more >warning: prop `dangerouslysetinnerhtml` did not match. - You.com ...
If it does not, then try to fix other invalid html markups. ... Link component it works fine almost every time but if...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ll take this one on.
I don’t have time to continue on this issue, so if anyone else wants to continue - feel free to do so!
My idea is to validate the HTML with perhaps html-validator package and logging the error to the console. I think adding something similiar to this in Main component could work: