flightcontrolhq / superjson

Safely serialize JavaScript expressions to a superset of JSON, which includes Dates, BigInts, and more.
https://www.flightcontrol.dev?ref=superjson
MIT License
4.13k stars 91 forks source link

Add test for issue #196 #197

Open dgrcode opened 2 years ago

dgrcode commented 2 years ago

@Skn0tt I've added the test hardcoding the data that is creating the issue. However, the test is passing 🤷

I'm opening this PR so you can have a quick look and check if you see any red flag in the test I've written. I'm just hardcoding the value that's giving me trouble, stringifying, parsing, and checking that the parsed value and the hardcoded value are equal.

Let me know if you see something weird.

Thanks!

dgrcode commented 2 years ago

I've been testing locally with different payloads which fail on the app, but all of them make the test pass.

The two possible scenarios that I think we might be in:

wdyt?

Skn0tt commented 2 years ago

The test looks very fine to me. One think I could imagine is happening is that the javascript object representation you've pasted in fails to capture some of the fine details of the objects created by dehydrating. Maybe you could try using the breaking code from https://github.com/blitz-js/superjson/issues/196 in the test?

Skn0tt commented 2 years ago

I'll be off on vacation for the coming weeks, so I won't be able to assist with this any further for now. If you find the issue, that means the fastest way to resolution is probably fixing it yourself and then opening a PR. Maybe @beerose and team can help with reviewing + publishing during that time.

dgrcode commented 2 years ago

Yes, that makes sense. I'll use the actual dehydrate function and see if that reproduces the issue.

I'll try to fix it myself, no worries. Enjoy your time off!

dgrcode commented 2 years ago

I've updated the tests to use the actual QueryClient and dehydrate from @tanstack/react-query.

EDIT: ~A quick note on the dependencies added. I had to add react because react-query was complaining about it. I've opened https://github.com/TanStack/query/issues/4080 because I don't see why the code I'm using would require react, but I also might be missing something about that library.~ Updated the dependencies to avoid using react on https://github.com/blitz-js/superjson/pull/197/commits/c02c0c7c618f7125dfb585848c7485ad627672f8

To my surprise, the tests continue passing. I've checked the object produced by dehydrate and it's pretty much the same as the object I originally described on #196, so I really don't know what else I can do to imitate the actual behaviour.

The hypothesis that the issue might be on the babel plugin babel-plugin-superjson-next instead of this library is getting more points.

What do you think should be the next steps?

Skn0tt commented 2 years ago

back from PTO!

I'm not sure what's causing this. Maybe you could build a minimum reproduction repository? Then I could take a look and check if I can reproduce and have an idea what's causing it