Is this a bug with removeValue on nested array elements?
Hey all, I thought I should ask here before posting the issue in the repo just in case. I have a made a minimal example which is attached but I'm not sure if its a bug or if I'm doing something wrong.
I am trying to remove an object from a nested array. This is the schema
This is the code I use to do that (the console.logs are for debugging):
The result in the console is in the image but basically:
- the obj is removed but then it appears again without the id value
- I'm so confused 😦
15 Replies
equal-aqua•7mo ago
Can you please reproduce it by forking a stackblitz example?
https://tanstack.com/form/latest/docs/framework/react/examples/simple
React TanStack Form Simple Example | TanStack Form Docs
An example showing how to implement Simple in React using TanStack Form.
xenophobic-harlequinOP•7mo ago
StackBlitz
Form Simple Example (forked) - StackBlitz
Run official live example code for Form Simple, created by Tanstack on StackBlitz
xenophobic-harlequinOP•7mo ago
I also have a start repo with it
equal-aqua•7mo ago
I think it's on L131, there's something wrong with the data and
item.id
probably being undefined sometimes, if you put itemIndex
there the error goes awayxenophobic-harlequinOP•7mo ago
Yes react reports a bug. But I am increasing sure that this is a tan stack form bug. item.id should never be undefined
Based on the code
xenophobic-harlequinOP•7mo ago

xenophobic-harlequinOP•7mo ago
This is the same code I just use form.setFieldValue(
consignments[${index}].goodsItems
,
newValues
);
instead of removeValuexenophobic-harlequinOP•7mo ago
You can look at the link now I updated it so its a little easier to see what is happening:
https://stackblitz.com/edit/tanstack-form-dbycl9vt?file=src%2Findex.tsx
StackBlitz
Form Simple Example (forked) - StackBlitz
Run official live example code for Form Simple, created by Tanstack on StackBlitz
xenophobic-harlequinOP•7mo ago
@Leonardo
equal-aqua•7mo ago
Ok so if you remove from the last one it works fine
If you remove from the middle, the first removal operation looks weird, then it works fine
right?
xenophobic-harlequinOP•7mo ago
Its not only that it looks weird. Its that it inserts an object for some reason. Like before removal we have 4, we filter one out we have 3 then we have 4 after update again
But yes if we remove the last element it works fine
equal-aqua•7mo ago
Got it, thanks! Could you please cleanup the example a little bit more to make it really the minimal set of instructions to replicate it and open an issue? There's probably something that has to be fixed on Form 🙂
xenophobic-harlequinOP•7mo ago
Sure, It will have to be monday though
equal-aqua•7mo ago
That's fine! Thank you 😄
xenophobic-harlequinOP•7mo ago
I made the issue now. Will clean up the stackbliz monday though
God dammit this drove me crazy yesterday 🤣