-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
unshift and insert mutator is broken in v3.0.2 #44
Comments
Further debugging shows that |
I'm seeing the same issue, except in my case, downgrading to 3.0.1 doesn't help. https://codesandbox.io/s/react-final-forms-re-rendering-wup5c (you can ignore the "Selected", it's for testing state, which appears to be correct) |
Actually, your sandbox has a flaw in that it uses
The slight difference in reproduction is that after first appending and then prepending a row, the culprit becomes the second row (which was moved from index 0 to 1), while the first row is mapped correctly. Btw this bug seems to have existed since 3.0.1, while 3.0.0 results in updating the first row when you try to change the second :) Whoever solves this logic should get a medal. |
It looks to me like the call to "moveFieldState" in the insert mutator might be the issue. This is used to move the state to the shifted fields, but it actually also deletes the field by moving. I think it should copy the state and then assign a "fresh" state to the field just added. Or maybe first shift the states and then add the new value to the desired index? But to be fair, I don't quite understand what the moveFieldState function actually does. btw. remove function is broken, too |
Agreed, the notion of cloning the array [...array] might be incorrect because the array contains functions. I tried to fork the final-form-arrays and used lodash deep clone. It still doesn't fix the problem. I had very little time and hence, ended up making a new unshift(insert to the start of the array) that uses push logic but reverses the array before and after pushing a new element into the array. Here's a copy of the code (Just for Unshift). I will look and try to fix the actual issue. https://github.com/Vishwas-93/final-form-arrays/blob/master/src/unshift2.js Thanks |
Hello 👋 Any update? Thanks :) |
The issue still exists. The following sandbox works in [email protected], and breaks for any version above this: Or if I'm doing something wrong, please let me know |
Also I see that there's a forked fix that works. Any specific reason this fix is not merged? (We cannot use forked packages because of company security policies unfortunately) |
Any update on the fix? |
I have an update about this issue and submitted the PR |
Are you submitting a bug report or a feature request?
Bug Report!
What is the current behavior?
The
unshift
mutator doesn't work. When a field is unshifted onto an array, it's value is inited as null and any changes to field (eg, via<input>
s) aren't reflected.Sandbox Link
This is actually visible via a slight tweak to the standard RFF Arrays example. Rather than just an "Add customer" button, there's now Append and Prepend variants. I've also bumped versions on all FF libs to latest.
To reproduce:
<input>
!What is the expected behavior?
The behaviour that you see if you go into the sandbox and change the FFA library version to 3.0.1
What's your environment?
FF 4.18.6
FFA 3.0.2
RFF 6.3.3
RFFA 3.1.1
The text was updated successfully, but these errors were encountered: