-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
__staticRouterHydrationData html tag escape #10068
Conversation
Hi @zheng-chuang, Welcome, and thank you for contributing to React Router! Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once. You may review the CLA and sign it by adding your name to contributors.yml. Once the CLA is signed, the If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at [email protected]. Thanks! - The Remix team |
🦋 Changeset detectedLatest commit: 54f3fcd The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
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 |
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳 |
8006041
to
07ac5a0
Compare
I'm not sure what this is actually fixing. Can you explain why this change is needed? |
@brophdawg11 Any thoughts on this? This can probably be simplified to |
I'm not sure we want to try to handle every potential edge case when it comes to serializing the |
Thanks, I'll close this PR. But I really hope you can make it easier with this library "serialize-javascript" which I just found. |
I agree this, but I still think this PR is necessary. React-router stringify the JSON string on server, parse JSON string in <script> tag on browser. When </script> within JSON string in a <script> tag, error will occur. Because HTML parser will treat everything between <script> and </script> as part of the script. In this case, the react router will fail to run! This is a bug! This PR will not change the semantics of JSON string, but can effectively avoid the syntax conflict with HTML! Some references for this problem in stackoverflow: |
@zheng-chuang Please reopen the PR. |
f8f7609
to
03aa55b
Compare
I don't think this is worth adding a 2kb gzipped dependency to I could be convinced that at the very least we should auto-escape HTML in the JSON string ( Personally, if I needed to dynamically render HTML elements within my components, I would send up the data, not the markup: function loader() {
return json({
scripts: [{ src: '/script.js' }],
});
}
function component() {
let data = useLoaderData();
return data.scripts.map(s => <script src={s.src}></script>);
} Or if I was loading pre-generated markup from something like a CMS, I'd just escape that in my loader if I knew it would contain HTML. |
Also would you mind repointing this to |
But this runs on the server side and will not be packaged and sent to the browser. |
It's not just for size reasons -
|
@zheng-chuang I think you may need to rebase this onto |
01d19e5
to
1d00b40
Compare
@brophdawg11 |
// This code is copy form https://github.com/vercel/next.js | ||
// License: https://github.com/vercel/next.js/blob/b2e9431bb46563264d450b1707dc0d9cdaf70d26/license.md |
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 code is copy form https://github.com/vercel/next.js | |
// License: https://github.com/vercel/next.js/blob/b2e9431bb46563264d450b1707dc0d9cdaf70d26/license.md | |
// This utility is based on https://github.com/zertosh/htmlescape | |
// License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE |
Since this file is already copied by Next.js, let's reference the original code as well.
a599480
to
3932911
Compare
Thanks @zheng-chuang! |
fix bug when __staticRouterHydrationData contains </script>