๐บ๏ธ Enhance and Dedupe Loaders #7768
Replies: 8 comments 22 replies
-
If I understand this correctly, you mean if two loaders return the same value (e.g. both return |
Beta Was this translation helpful? Give feedback.
-
Will this allow to send promises that are not in the root of the response? So instead of always doing |
Beta Was this translation helpful? Give feedback.
-
Is this something that will remain this way? While I have enough with all the things |
Beta Was this translation helpful? Give feedback.
-
About sending Error instances, will this work with custom errors? E.g. |
Beta Was this translation helpful? Give feedback.
-
As you've written, the serialization of date objects are one of the more significant issues. However most people don't use the built in types for dates and use luxon / date-fns. It would be good if we could configure this to use one of those library's data types (in my case luxon) |
Beta Was this translation helpful? Give feedback.
-
I think one of the biggest pain points for dates being sent is figuring out a way to serialise them for the client to all regions. There have been multiple times where a date created on the server results in a date on the client being a few hours off of the clients local time due to servers being hosted in different locales and or the load balancers themselves. Would this proposition be able to tackle some of these issues? |
Beta Was this translation helpful? Give feedback.
-
For everyone focused on dates, this get's you a real Date object that matches between SSR and CSR allowing you to avoid toString()ing it, and format it properly in the browser based on your users client hints. I don't see a way for this to handle dates much better than that, as how to format / display is a "you" decision, not one I can make at this layer. If I'm missing something, let's try to consolidate thoughts / explanations focused on Date concerns in this thread. @moishinetzer @StevenBendell |
Beta Was this translation helpful? Give feedback.
-
this RFC reminds me of this issue for React with RSC -> facebook/react#25687 |
Beta Was this translation helpful? Give feedback.
-
Proposal Overview:
defer()
utility.Contextual Background:
Presently in Remix, the loader and action return values are bound to only those that are JSON serializable. This constraint has inadvertent repercussions, notably the conversion of Date objects to Strings when transmitted across network boundaries. Additionally, this results in data redundancy within the initial remix context serialized for HTML document hydration.
Beyond the JSON serializable restriction, the
defer()
utility was introduced to accommodate Promises as root object key-value pairs. While this provides the convenience of showcasing a loading state and transmitting data that might be slower to load at a later interval, it doesn't cater to subsequent promises on the resolved value or scenarios like arrays of promises.Detailed Proposal:
The current approach employs a HTML-safe
JSON.stringify()
for the remix context and for ferrying loader data to the browser. The proposed methodology adopts a variant of Rich Harris's devalue, specifically the turbo-stream library to efficiently "flatten" values. This process not only ensures deduplication but also seamlessly incorporates data types like Map, Set, Promise, and others.A key distinction between "devalue" and "turbo-stream" is the latter's capability to handle Promises by rendering directly to a WebStream.
Moreover, "turbo-stream" is not designed to be extensible.(I was very quickly talked out of this by my own use-case outside of Remix and others below).Leveraging "turbo-stream" for encoding the remix context would yield automatic deduplication across route loaders and within the internal remix context. This also presents an opportunity to replace the defer() function, eliminating the need for distinct response formats for client-side loader invocations.
Steps
text/remix-deferred
withturbo-stream
for a client initiated navigation to a deferred route.turbo-stream
as format inlined in HTML responsedefer()
Beta Was this translation helpful? Give feedback.
All reactions