solid-primitives icon indicating copy to clipboard operation
solid-primitives copied to clipboard

`makePersisted` with cookieStorage does not deserialize umlauts on the server correctly

Open madaxen86 opened this issue 1 year ago • 4 comments

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.

  1. ON the index page click on "set umlauts" to set the text.
  2. reload the page to trigger SSR deserialization.

Minimal Reproduction Link

https://github.com/madaxen86/make-persisted-umlauts

madaxen86 avatar Aug 09 '24 19:08 madaxen86

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.

atk avatar Aug 12 '24 10:08 atk

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="öäüÖÄÜ"

atk avatar Aug 12 '24 19:08 atk

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.

atk avatar Aug 12 '24 20:08 atk

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.

madaxen86 avatar Aug 12 '24 20:08 madaxen86

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.

atk avatar Aug 19 '24 07:08 atk

No problem. I figured it would not be easy. I'll test it when merged and published 🙏

madaxen86 avatar Aug 19 '24 12:08 madaxen86