faceyspacey / redux-first-router-boilerplate

MIT License
23 stars 15 forks source link

Warning about JSON and unicode #3

Open dalebaldwin opened 7 years ago

dalebaldwin commented 7 years ago

Hey discovered this one over the last couple of days. I'm pulling a rather large set of JSON feeds from an API I control which contains a large amount of data I don't control. Some of that data contains unicode characters in particular \2028.

When reloading and taking the server rendered version I would often get a red screen of death but making a change and letting the page hot reload would let the page load fine. Also navigating to that page without triggering off a browser reload would also let that content load.

From what I can tell this is an issue with the state object loaded into the script tag on page and React having trouble re-hydrating from that object if it contains certain unicode characters.

It might be worth putting in a warning somewhere here and on other universal modules that might have issues with JSON that isn't as clean or controllable as we would like.

faceyspacey commented 7 years ago

this should do it instead of a JSON.stringify (it's a common alternative):

https://www.npmjs.com/package/serialize-javascript

let me know.

dalebaldwin commented 7 years ago

Did something similar on our API end, thinking I might try and write something like that in the server rendering as a backup as well. But also think it's worth putting in a warning I just submitted via PR in the readme.md as well.