[PR #25644] fix: allow empty values in Variable Inspector #31144

Closed
opened 2026-02-21 20:48:54 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/25644

State: closed
Merged: Yes


Summary

Fixed a bug in the Variable Inspector where empty arrays [] and empty objects {} were incorrectly treated as invalid JSON values. The issue occurred due to a truthiness check that converted empty arrays/objects to empty strings, causing validation failures.

Changes Made:

  • Changed truthiness check to null check in JSON editor initialization (line 74 of value-content.tsx)
  • Empty arrays [] and empty objects {} now properly serialize as '[]' and '{}'
  • Fixes issue where empty values were treated as invalid JSON

Technical Details:

The bug was in /web/app/components/workflow/variable-inspect/value-content.tsx where:

// Before (buggy):
setJson(currentVar.value ? JSON.stringify(currentVar.value, null, 2) : '')

// After (fixed):  
setJson(currentVar.value != null ? JSON.stringify(currentVar.value, null, 2) : '')

JavaScript's truthiness check incorrectly treated empty arrays/objects as falsy, converting them to empty strings instead of valid JSON representations.

Fixes #25612

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Screenshots

Before After
Empty values show validation errors Empty values are accepted as valid JSON

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/25644 **State:** closed **Merged:** Yes --- ## Summary Fixed a bug in the Variable Inspector where empty arrays `[]` and empty objects `{}` were incorrectly treated as invalid JSON values. The issue occurred due to a truthiness check that converted empty arrays/objects to empty strings, causing validation failures. ### Changes Made: - Changed truthiness check to null check in JSON editor initialization (line 74 of `value-content.tsx`) - Empty arrays `[]` and empty objects `{}` now properly serialize as `'[]'` and `'{}'` - Fixes issue where empty values were treated as invalid JSON ### Technical Details: The bug was in `/web/app/components/workflow/variable-inspect/value-content.tsx` where: ```tsx // Before (buggy): setJson(currentVar.value ? JSON.stringify(currentVar.value, null, 2) : '') // After (fixed): setJson(currentVar.value != null ? JSON.stringify(currentVar.value, null, 2) : '') ``` JavaScript's truthiness check incorrectly treated empty arrays/objects as falsy, converting them to empty strings instead of valid JSON representations. Fixes #25612 > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Screenshots | Before | After | |--------|-------| | Empty values show validation errors | Empty values are accepted as valid JSON | ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:48:54 -05:00
yindo closed this issue 2026-02-21 20:48:54 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#31144