Description
I'm using React Router as a...
library
Reproduction
export async function loader() { return { invalidDateField: new Date('invalid-date-string') }; }
https://stackblitz.com/edit/github-rxhk6sn1-zaw2xuan?file=app%2Froutes%2Fhome.tsx
System Info
System:
OS: Linux 5.0 undefined
CPU: (2) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 18.20.3 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.2.3 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
@react-router/dev: * => 7.4.0
@react-router/node: * => 7.4.0
@react-router/serve: * => 7.4.0
react-router: * => 7.4.0
vite: ^6.0.11 => 6.2.2
Used Package Manager
npm
Expected Behavior
{"siteTitle":"React Router","bug":null}
The loader function should handle Invalid Date objects in the same way as standard JSON.stringify, i.e., convert them to null and not cause a syntax error.
Actual Behavior
Oops! Unable to decode turbo-stream response
Additional Information
The issue seems to arise from how React Router handles the serialization of data returned from the loader. When performing JSON.stringify on an object containing an Invalid Date, the expected result is that the Invalid Date would be converted to null, but this bug causes a syntax error on the client side.
Possible Solution
React Router should ensure that handling invalid date objects matches the standard behavior of JSON.stringify or provide an alternative solution that prevents the application from crashing in such cases.