Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Error when rebuilding Date with patches #676

Closed
jgrenon opened this issue Sep 23, 2020 · 6 comments
Closed

Error when rebuilding Date with patches #676

jgrenon opened this issue Sep 23, 2020 · 6 comments
Labels

Comments

@jgrenon
Copy link

jgrenon commented Sep 23, 2020

Report

When using new Date as a field value in a draft, the resulting patch doesn't produce a valid date when replayed.

Link to repro

https://codesandbox.io/s/immer-sandbox-forked-wzvm6?file=/src/index.js

To Reproduce

Run the code above and look in the console.

Observed behavior

After patch is applied, date is null.

Expected behavior

After patch, date should be a valid primitive date

Environment

Node.JS 14.8.0
Immer 7.0.9

@ebataille
Copy link

ebataille commented Sep 26, 2020

I got a bug too here, but don't have the same problem,

Wehn I applyPatches with date, and then do a date.getDate, I Have
this is not a date object

I found where the issue happen in Patches.ts in the function deepClonePatchValue

const cloned = Object.create(Object.getPrototypeOf(obj))

should be

const cloned = obj instanceof Date ? new Date(obj) : Object.create(Object.getPrototypeOf(obj))

It solved the issue for me

@mweststrate
Copy link
Collaborator

Looks like the deepClonePatchValue misses a pre-condition if (!isDraftable(obj)) return obj

@ebataille
Copy link

Any idea of a workaround while this bug is fix ?

@mweststrate
Copy link
Collaborator

mweststrate commented Oct 7, 2020 via email

@mweststrate
Copy link
Collaborator

Should be fixed in 7.12

@aleclarson
Copy link
Member

🎉 This issue has been resolved in version 7.0.12 🎉

The release is available on:

Your semantic-release bot 📦🚀

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants