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

Hydration issue when props have strings with newlines #35

Open
mraerino opened this issue Jan 21, 2022 · 1 comment
Open

Hydration issue when props have strings with newlines #35

mraerino opened this issue Jan 21, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@mraerino
Copy link

When hydrating a component that gets passed props with values that are strings with newlines, i get this error in the browser:

main.4cbde32973bc4eb1fe2d.js:1 Could not hydrate interactive components. Error: Unexpected token 
 in JSON at position 799

The JSON that was rendered into the page as a comment:

{"id":"0","loc":"start","componentName":"BlogPost","props":"{\"functions\":{},\"pkg\":{\"name\":\"kalkspace-relaunch\",\"version\":\"1.0.0\",\"description\":\"\",\"main\":\"index.js\",\"scripts\":{\"develop\":\"ELEVENTY_EXPERIMENTAL=true eleventy --serve\"},\"keywords\":[],\"author\":\"\",\"license\":\"ISC\",\"devDependencies\":{\"@11ty/eleventy\":\"^0.12.1\"},\"dependencies\":{\"@babel/core\":\"^7.16.10\",\"@babel/preset-env\":\"^7.16.11\",\"@babel/preset-react\":\"^7.16.7\",\"babel-loader\":\"^8.2.3\",\"core-js\":\"^3.20.3\",\"eleventy-plugin-react\":\"^1.1.0\",\"react\":\"^17.0.2\",\"react-dom\":\"^17.0.2\",\"regenerator-runtime\":\"^0.13.9\"}},\"layout\":\"blogpost.jsx\",\"title\":\"Hello\",\"tags\":[\"cat\",\"dog\"],\"page\":{\"date\":\"2022-01-21T13:16:05.133Z\",\"inputPath\":\"./src/posts/hello.md\",\"fileSlug\":\"hello\",\"filePathStem\":\"/posts/hello\",\"url\":\"/posts/hello/\",\"outputPath\":\"_site/posts/hello/index.html\"},\"content\":\"<p>Cats, dogs.</p>\n\",\"layoutContent\":\"<p>Cats, dogs.</p>\n\",\"_layoutContent\":\"<p>Cats, dogs.</p>\n\",\"children\":null}"}

This is likely related to brokenness when calling JSON.stringify twice on strings with newlines. the places inside of props where you see \n should likely be \\n.

@kaicataldo kaicataldo added the bug Something isn't working label Jan 24, 2022
@kaicataldo
Copy link
Owner

Hmmm yeah, this is definitely not a case I considered! We should definitely make the serialization logic handle stringified JSON correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants