deepmodeling / deepmodeling/dpgui
[Code scan] Avoid data loss when loading repeated list and dict inputs
- Dominant language
- Vue
- Stars
- 9
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
This issue was found during a Codex global code scan of the repository.
Baseline commit: e3c5b38a99eb7ab778b5d8c68a5ed4ddf6cf91b3
Problem
The repeated list and dict loaders mutate `repeat_jdata` and then immediately read `$refs` before Vue has rendered the new repeated children. The repeated dict path also treats a dictionary as if it had `obj.length`.
Code references:
https://github.com/deepmodeling/dpgui/blob/e3c5b38a99eb7ab778b5d8c68a5ed4ddf6cf91b3/src/components/dargs/DargsItem.vue#L448-L470
https://github.com/deepmodeling/dpgui/blob/e3c5b38a99eb7ab778b5d8c68a5ed4ddf6cf91b3/src/components/dargs/DargsItem.vue#L500-L522
Relevant snippet:
```js
this.keys = Object.keys(obj);
[...Array(obj.length).keys()].forEach((ii) => {
this.repeat_jdata.push(this.jdata);
});
```
Impact
Loading an existing JSON file with repeated entries can skip rows or fail to populate nested fields. Saving after that can drop data from the imported configuration.
Suggested fix
For repeated dicts, iterate over `Object.keys(obj)` instead of `obj.length`. After resizing `repeat_jdata`, wait for Vue to render the new children, for example with `nextTick`, before walking `$refs` and loading nested values.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.