-
-
Notifications
You must be signed in to change notification settings - Fork 264
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
Bug with history (again?) #323
Comments
Thanks for reporting. Would you like to create a minimal test to catch the bug? (Note that I'm not even sure if this is fixable at this point.) |
Hello, @dai-shi I found in the code that the lengths of the "ops" array are different I think the problem is that proxyObject.saveHistory() function is called In the case of the example provided above, it seems to work well using the code below. // https://github.com/pmndrs/valtio/blob/b4604b591f33b7be4cc10f81e18a14f848af0b8d/src/utils/proxyWithHistory.ts#L62
subscribe: () =>
subscribe(proxyObject, (ops) => {
if (
ops.some(
(op) =>
op[1][0] === 'value' &&
op[1].length === 2 && // added
(op[0] !== 'set' || op[2] !== proxyObject.history.wip)
)
) {
proxyObject.saveHistory()
}
}), |
Thanks for digging into it.
My gut feeling is this is not correct. It can be more than two if we have nested objects. But, I may need to take time to look into it to have better understanding. Also, if you can create a minimal test case, that would be helpful. |
Right, It have to be change from
I forked the code sandbox you'll be able to check it. |
thanks! looking into it. |
@dai-shi Sure, I think firing click event twice is make just 1 snapshot in history. |
thanks for your help! |
Great! |
Released: https://github.com/pmndrs/valtio/releases/tag/v1.2.12 Thanks for reporting and investigating. |
Hello again, I think I found something.
sandbox link
I'm trying to implement transition (jump) between different states in my project and found one issue.
If I try to undo or redo a state in a loop it doesn't work as expected.
PS: Loop is just an example for this issue, I know I can get the value directly from the snapshots array.
Expected:
Case 1:
initial value 0
UpdateValue (x3) -> undo by step (x3) -> redo by step (x3) -> 3
Case 2:
initial value 0
UpdateValue (x3) -> undo all -> redo all -> 3
Actual:
Case 1:
initial value 0
UpdateValue (x3) -> undo by step (x3) -> redo by step (x3) -> 3 <- fine
Case 2:
initial value 0
UpdateValue (x3) -> undo all -> redo all -> 0 <- bad
The text was updated successfully, but these errors were encountered: