-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Date changes datatype in SSR und CSR #5865
Comments
IMO your endpoint should be responsible for returning something that can be serialized (as-is) to JSON. If you're returning something that can't be losslessly serialized and deserialized, that's not something SK should be worried about I don't think. Resolving this would mean running all SSR responses from these functions through |
An endpoint can be called from the server and from the client. I would expect the same result in both cases. While I agree that it seems like a waste it would at least follow the same flow in both cases. I'm under the impression that the result is cached and the stringifying and parsing would only be done once. If #647 would be implemented and expanded to endpoints as well the Date type could be also restored again on the client. Another option would be to test and throw an error if not serializable datatypes are encountered. There was someone on discord who was returning mongodb client handles via the endpoint, which was also working because of how SSR works it seems, but |
I'd be in favor of testing for serializability in dev mode only, and just passing along the object as-is in prod mode for SSR. |
Providing some way to hook into the deserialization on the client would make it easier to convert ISO date strings back to JS Objects (i.e. as a I hit this all the time (pretty much ever chunk of data always has a date in it) and it's a new-user foot-gun because the error you end up with isn't obvious as to the cause. |
Describe the bug
When returning a JSDate from an endpoint. The datatype is preserved during SSR, but then on clientside load the type is the expected string.
Reproduction
The reproduction repo can be found here: https://github.com/tylkomat/sveltekit-date-ssr
The setup is very simple:
index.svelte
index.ts
Logs
System Info
Severity
annoyance
Additional Information
No response
The text was updated successfully, but these errors were encountered: