You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to revive custom objects that have as properties other custom objects, if the reviver functions are asynchronous, the outer object's reviver doesn't receive the nested revived value as an argument immediately, but it does after a timeout.
Interestingly, when rewriting CustomObjectWithNestedObject's reviver using a setTimeout, the property appears, making the problem look like a race condition:
// ...// This works!
reviveAsync: (v)=>newTypeson.Promise((resolve,reject)=>{setTimeout(()=>{// By the time this is executed, v.custom appears on the object!resolve(newCustomObjectWithNestedObject(v.custom))},0);})
Thanks for your encouragement of the project. I'd like to help, but I'm afraid I have too much on my plate at this time, but I should be able to find time to review a PR if you might be able to take a closer look. Note that the typeson proper codebase is fairly small, so though it can be a little dizzying to track (and the reason why I haven't gotten to #11 as well--which incidentally sounds like it could be similar if not a dupe), it should be doable with some focused time (and probably more importantly, enough forethought on how such nesting needs to work).
When trying to revive custom objects that have as properties other custom objects, if the reviver functions are asynchronous, the outer object's reviver doesn't receive the nested revived value as an argument immediately, but it does after a timeout.
Simplified example:
Interestingly, when rewriting
CustomObjectWithNestedObject
's reviver using asetTimeout
, the property appears, making the problem look like a race condition:I have created a CodeSandbox with a reproduction here, with tests extracted from my code: https://codesandbox.io/s/typeson-async-bug-reproduction-prpp9
I hope this can be fixed soon, as this is an otherwise great library :)
The text was updated successfully, but these errors were encountered: