guardian / guardian/dotcom-rendering
Fix Island json serialisation
- Dominant language
- TypeScript
- Stars
- 274
- Forks
- 34
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 121
Description
Island can only JSON-serialise primitive types (e.g. string, number, boolean). If a field has a more complex type, such as Date, it gets automatically converted to a string during serialisation.
This becomes an issue on the client side, where components expect a Date, leading to hydration failures. See this PR for an example: https://github.com/guardian/dotcom-rendering/pull/15622
We need a way to ensure Island can correctly serialise complex types to JSON and reliably deserialise them back into their original types on the client.
**Potential solutions:**
- Use schema validation libraries (e.g. valibot or Zod) to explicitly handle parsing and type restoration
- Use more advanced serialization libraries (e.g. devalue: https://github.com/sveltejs/devalue)
Contributor guide
Assessment
This issue has not been assessed yet.