Why is React hydration data within a script tag, commented out?
See original GitHub issueI’m working on an issue to optimize open source library for server rendering: github.com/shakacode/react_on_rails/pull/660.
We’re considering breaking away from placing react hydration data in a meta tag and moving into maybe a script tag.
Why does Airbnb puts react hydration data inside of an <script type=“application/json” data-key=“foobar”><!--{json}--></script>
per the screen shots below? Is this related to XSS or performance reasons?
CC: @goatslacker
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:15
Top Results From Across the Web
Why Efficient Hydration in JavaScript Frameworks is so ...
Most JavaScript frameworks need to hydrate top-down. This is as true for React as it is for Svelte. So if your app contains...
Read more >Hydrating text content from Server-Side Rendering | Tan Li Hau
Partial hydration in React is a mechanism to partially hydrate a server-rendered result while other parts of the pages are still loading the ......
Read more >Warning: Text content did not match. Server: "I'm out" Client
The hydration issue occurs because the HTML rendered on the browser doesn't match the one generated on the server. In your case this...
Read more >Keeping Server-Side Rendering Cool With React Hydration
hydrates a site from HTML to React. In order to avoid issues with the hydration reconciliation process, you can wrap any side effects...
Read more >React on Twitter: "Suspense also enables selective hydration ...
Suspense also enables selective hydration. React 18 can start hydrating the HTML before all JavaScript code loads. Specifically, content wrapped in <Suspense> ...
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 Free
Top 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
Some older browsers will execute any script block, even if it’s type is “application/json”.
Best practice is to always comment it out to ensure nothing can ever execute.
Interesting - that does sound like something we want to handle, then.