[Feature]: Use Blitz.js superjson instead of native JSON.serialize/parse
See original GitHub issueWhat is the new or updated feature that you are suggesting?
Use superjson to serialize and parse data returned from loaders/actions.
Why should this feature be included?
Right now Remix uses JSON.stringify and JSON.parse, this means types like Date (see #634) are going to be converted to strings when serializing it but not converted back to Date on the revive step, and other types like BigInt are not even compatible with JSON.stringify, so if an ORM returns one the user needs to manually convert them to a string before returning the data/response inside the loader.
This superjson library created by the Blitz.js team have differents stringify and parse method that it’s capable of serializing more types of data and reviving them back to the original class (see the table here https://github.com/blitz-js/superjson#parse), this way if a loader does this:
return json({ date: new Date() })
Then the useLoaderData will get this
let { date } = useLoaderData<{ date: Date }>()
let fullYear = date.getFullYear() // this will work
And other native objects like BigInt, RegExp, Set, Map and Error will also work as valid return values.
Additionally, superjson can be extended to serialize and revive other objects, it may be cool if Remix let you customize that somehow, but I think just the default config would be better than the native JSON methods.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:21
- Comments:18 (7 by maintainers)

Top Related StackOverflow Question
Ahhh that could be the reason, I think the team should set the default branch as dev so people open PRs automatically against that branch instead of main
It’s
8.7kBgzipped. I don’t think it’s worth including. It goes against the “web fundamentals” approach of Remix. Better to rally TC39 to update the JSON spec instead.