Replies: 25 comments 17 replies
-
It's |
Beta Was this translation helpful? Give feedback.
-
@mikestopcontinues it's tree-shakeable, so that's not the final size, since the browser only needs one method it should be smaller, but would need to be measured correctly |
Beta Was this translation helpful? Give feedback.
-
Could this be supported by having serialize/parse hooks in the client/server entries? |
Beta Was this translation helpful? Give feedback.
-
I don't think so, you can't change how Remix parse the data from the first request and for requests it does when navigating. This is something that Remix needs to do internally, or somehow expose hooks to do that which is not possible right now. |
Beta Was this translation helpful? Give feedback.
-
It would be similar to how tRPC does it: https://trpc.io/docs/data-transformers |
Beta Was this translation helpful? Give feedback.
-
Does somebody need to give the final word on this before someone can make a PR? |
Beta Was this translation helpful? Give feedback.
-
@zachtylr21 I already made a PR #662 |
Beta Was this translation helpful? Give feedback.
-
@sergiodxa in the future, is there a way to know which issues are already being worked on? I wonder if we should use the "assignees" section so people don't accidentally start working on the same thing. Or is it just assumed that if you create the issue, you create the PR as well? |
Beta Was this translation helpful? Give feedback.
-
@zachtylr21 honestly, I don't know, I also don't know why GitHub didn't related the issue with the PR (I'm sure |
Beta Was this translation helpful? Give feedback.
-
@sergiodxa Cool, maybe I'll just assume that if someone else created the issue, they're working on it, or I'll just ask them. Btw, I just looked at your PR, I think it's supposed to be "fixes" not "fix". |
Beta Was this translation helpful? Give feedback.
-
@zachtylr21 just tried with fixes, it doesn't link them, I'm not sure what's happening with GitHub |
Beta Was this translation helpful? Give feedback.
-
@sergiodxa weird 🤷 |
Beta Was this translation helpful? Give feedback.
-
@sergiodxa I think that's because you're not creating a PR against the default branch (which is |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
What is the proposed way to deal with this issue? Right now, this is what I'm doing, but I'm sure there are better ways (I'm new to TypeScript) : export type TransactionJson = Omit<Transaction, 'createdAt'> & {
createdAt: string
}
export type LoaderResponse = {
transactions: TransactionJson[]
}
export const loader: LoaderFunction = async ({ params }) => {
invariant(params.accountId, 'expected params.accountId')
const transactions = await getTransactions(params.accountId)
return json({ transactions })
}
export default function Transactions() {
const { transactions } = useLoaderData<LoaderResponse>()
[...]
} Good thing I need an string representation of that Date inside |
Beta Was this translation helpful? Give feedback.
-
@arthurgeek Separate from the |
Beta Was this translation helpful? Give feedback.
-
As someone who uses Maps and Sets in their (backend) code, I would appreciate support for serializing them. |
Beta Was this translation helpful? Give feedback.
-
Would love this, currently all my prisma date types are incorrect and it's incredibly frustrating. |
Beta Was this translation helpful? Give feedback.
-
+1 |
Beta Was this translation helpful? Give feedback.
-
Constantly parsing dates is really annoying, this feature would be amazing! Please consider it! |
Beta Was this translation helpful? Give feedback.
-
I don't think I can use Remix since I need to serialize BigInt 😔 |
Beta Was this translation helpful? Give feedback.
-
Is this still being considered for a future release? Consider this another vote in favor of this working out of the box 👍 |
Beta Was this translation helpful? Give feedback.
-
I know some time has passed on this issue, but as someone new to Remix I arrived here from a search after I hit this same issue. Is there any current recommendation for this date handling in late 2023? I ask because I checked out remix-typedjson, remix-superjson, superjson-remix, remix-supertyped and the like, and those repos do not seem all that active, with not many recent commits, or what look like on the face of it significant open issues with the current version of Remix. Situations like this are why it would be very helpful to have a solution for this in Remix core rather than depending on a 3rd-party repo that falls by the wayside as time goes on. |
Beta Was this translation helpful? Give feedback.
-
I have no preference for or against any existing solution, but would be awesome to have a transparent and automatic way when using |
Beta Was this translation helpful? Give feedback.
-
With Single Fetch using turbo-stream, this is not needed anymore since now Remix can send more advanced objects like Date, Map, etc. |
Beta Was this translation helpful? Give feedback.
-
Note
This is not needed anymore now that Remix uses turbo-stream when Single Fetch feature is enabled, since that allows sending more values than plain JSON, like Date, BigInt, Map, etc.
What 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:
Then the useLoaderData will get this
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.
Beta Was this translation helpful? Give feedback.
All reactions