Skip to content

fix: preserve empty array default value on JSONForm reset - #42226

Open
rasadregmi wants to merge 1 commit into
appsmithorg:releasefrom
rasadregmi:fix/jsonform-reset-empty-array
Open

rasadregmi wants to merge 1 commit into
appsmithorg:releasefrom
rasadregmi:fix/jsonform-reset-empty-array

Conversation

@rasadregmi

@rasadregmi rasadregmi commented Sep 12, 2026

Copy link
Copy Markdown

Summary

Fixes #41653. Resetting a JSON Form whose Array field defaults to [] created one empty array item, making the form invalid and unsubmittable. Reset now restores the empty default.

Root cause

schemaItemDefaultValue() in app/client/src/widgets/JSONFormWidget/helper.ts computes the array default as lodash.merge(processArray(...), sanitizedDefaultValue). processArray() always returns a single-item array because the __array_item__ schema entry always exists, and lodash.merge([item], []) keeps [item], so an empty default [] becomes [{}]. Form.onReset() (component/Form.tsx) feeds that value into reset(values, { keepErrors: true }), producing the phantom array item that fails required/regex validation.

Changes

  • app/client/src/widgets/JSONFormWidget/helper.ts: return [] when the array schema item's defaultValue is an empty array
  • app/client/src/widgets/JSONFormWidget/helper.test.ts: regression tests for both identifier and accessor key paths

Testing

  • jest src/widgets/JSONFormWidget/helper.test.ts — 17/17 pass
  • jest src/widgets/JSONFormWidget/fields/ArrayField.test.tsx — 2/2 pass
  • tsc --noEmit — clean
  • prettier --check and eslint on touched files — clean
  • Verified the new tests fail without the fix

Closes #41653

Summary by CodeRabbit

  • Bug Fixes

    • Empty array defaults in JSON forms are now preserved as empty arrays instead of being populated with unintended values.
  • Tests

    • Added coverage for empty array defaults using both identifier- and accessor-based field configurations.

@rasadregmi
rasadregmi requested a review from a team as a code owner September 12, 2026 12:29
@github-actions github-actions Bot added awaiting-maintainer The next action on this pull request belongs to an Appsmith maintainer external-contribution Pull request submitted from outside the Appsmith repository labels Sep 12, 2026
@github-actions

Copy link
Copy Markdown

Thanks for contributing to Appsmith!

Credential-free formatting, lint, type, and unit checks will run after GitHub's workflow approval. An Appsmith maintainer will start privileged integration tests or a deploy preview when needed.

No action is required from you while this PR has the awaiting-maintainer label.

@coderabbitai

coderabbitai Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 65b38ac4-4e6f-4b1a-9be0-1714d49d6a66

📥 Commits

Reviewing files that changed from the base of the PR and between 172b7c1 and e7cf591.

📒 Files selected for processing (2)
  • app/client/src/widgets/JSONFormWidget/helper.test.ts
  • app/client/src/widgets/JSONFormWidget/helper.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

The JSON Form helper now preserves empty array defaults instead of creating an empty array item. Tests cover both identifier and accessor key types.

Changes

JSON Form array default handling

Layer / File(s) Summary
Preserve empty array defaults
app/client/src/widgets/JSONFormWidget/helper.ts, app/client/src/widgets/JSONFormWidget/helper.test.ts
schemaItemDefaultValue returns [] immediately for empty array defaults. Tests cover identifier and accessor key types.

Priority: ⬆️ High

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: High

Suggested reviewers: amelia-c0n

Merge Risk: ⚪ Minimal · up to e7cf5

The change correctly preserves empty array defaults during form resets, with coverage for both key paths. No merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: preserving an empty array default when resetting a JSON Form.
Description check ✅ Passed The description explains the issue, root cause, implementation, regression tests, validation results, and linked issue. It does not explicitly state dependencies or complete the Communication section,…
Linked Issues check ✅ Passed Issue #41653 requires reset to preserve an Array field default of [] without creating an invalid item. In helper.ts, the ARRAY branch returns [] when schemaItem.defaultValue is an empty array,…
Out of Scope Changes check ✅ Passed The changed files contain only the ARRAY default-value fix and regression tests for issue #41653. The changes support the linked issue and introduce no unrelated implementation or test scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Empty arrays stay still
Reset follows the default
No phantom rows bloom
Identifier and accessor agree
Validation rests calm

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-maintainer The next action on this pull request belongs to an Appsmith maintainer external-contribution Pull request submitted from outside the Appsmith repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Resetting JSON Form creates an empty Array item for Array fields defaulted to [], causing validation failure

1 participant