networknt / networknt/react-schema-form

Array delete is not working (UI became out-of-sync of model)

Open
#22 17 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted
Dominant language
JavaScript
Stars
356
Forks
94
Avg merge
19h 36m
Merged PRs (30d)
4

Description

In the following GIF image you can see that:

  1. I'm adding three elements to the array (A, B and C)
  2. I'm removing the second element (B)
  3. The model is fine (with values A and C)
  4. But in the UI we see that B remains visible (the last element is the one being removed - not rendered)

react-schema-form issue with array delete

This happens because you are using array's index as the key for each li component rendered in the Array react component.

React uses key prop to improve performance. From the documentation you can read the following:

Keys should be stable, predictable, and unique. Unstable keys (like those produced by Math.random()) will cause many nodes to be unnecessarily re-created, which can cause performance degradation and lost state in child components.

I don't know a solution for this. But the solution should be around defining a stable KEY for the array elements internally tracked by react-schema-form.


  • You can try this yourself in the online playground
  • react-schema-form version used: 0.2.8

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/Array.js around line 129 and reproduce the deletion sequence in the linked online playground using react-schema-form 0.2.8. Investigate the array element keys and verify that deleting the middle element removes the corresponding UI item while preserving the model values A and C.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.