`makePersisted` with cookieStorage does not deserialize umlauts on the server correctly
Describe the bug
When persisting a data with umlauts (probably also other special characters) like "öäü" makePersisted does not deserialize those chars correctly but returns instead: "öäüÃÃÃ" Happens only during SSR. On client side navigation the values are returned correctly.
``
See GitHub repo for reproduction.
- ON the index page click on "set umlauts" to set the text.
- reload the page to trigger SSR deserialization.
Minimal Reproduction Link
https://github.com/madaxen86/make-persisted-umlauts
Thank you for the reproduction repo. I'm just back from my vacation, will investigate and fix it this evening (I'm pretty sure we're just missing the encoding in the server part of cookieStorage.
Interestingly, the cookie is internally utf-8, but the header that the browser sends seems to already have the wrongful encoding. From the localhost:3000 request header:
cookie:
umlauts="öäüÖÄÜ"
Interestingly, this is actual browser behavior. A few RFCs tried to rectify the situation, but still aren't supported by most major browsers. I guess I have to encode the cookie both ways. Give me a bit more time, please.
No problem, it's not urgent. As a workaround I am setting/updating the cookie myself and JSON.stringify the value. Works perfectly. But still would be great if it worked out of the box. I also tried to use the serialize/deserialize props and add do the same JSON.stringify and .parse but without any success.
Sorry for the delay, my attempts to make \u... escapes failed and the solution became too complex, so I had to pivot to use encodeURIComponent - but then, cookies are a limited resource and I only wanted to escape those characters not supported; long story short, I'm just opening a new PR that fixes the issue.
No problem. I figured it would not be easy. I'll test it when merged and published 🙏