fix: preserve empty array default value on JSONForm reset - #42226
rasadregmi wants to merge 1 commit into
Conversation
|
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 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. WalkthroughThe JSON Form helper now preserves empty array defaults instead of creating an empty array item. Tests cover both ChangesJSON Form array default handling
Priority: ⬆️ High Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: High Suggested reviewers: Merge Risk: ⚪ Minimal · up to 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)
✨ Finishing Touches🧪 Generate unit tests (beta)
Empty arrays stay still Comment |
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()inapp/client/src/widgets/JSONFormWidget/helper.tscomputes the array default aslodash.merge(processArray(...), sanitizedDefaultValue).processArray()always returns a single-item array because the__array_item__schema entry always exists, andlodash.merge([item], [])keeps[item], so an empty default[]becomes[{}].Form.onReset()(component/Form.tsx) feeds that value intoreset(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'sdefaultValueis an empty arrayapp/client/src/widgets/JSONFormWidget/helper.test.ts: regression tests for bothidentifierandaccessorkey pathsTesting
jest src/widgets/JSONFormWidget/helper.test.ts— 17/17 passjest src/widgets/JSONFormWidget/fields/ArrayField.test.tsx— 2/2 passtsc --noEmit— cleanprettier --checkandeslinton touched files — cleanCloses #41653
Summary by CodeRabbit
Bug Fixes
Tests