fix: Correct data handling logic in Paragraphs Model for non-array data #7559
+22
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug Fix: Handle empty array validation in Paragraphs component
Reason for change
Problem: The
setRemoteValue
method in theParagraphs
component doesn't properly handle empty arrays. When an empty array[]
is received as input, the code attempts to access properties ofval[0]
which results in a JavaScript runtime error (trying to access properties ofundefined
).Solution: Added a check to handle empty arrays in the validation logic. The fix validates if the array is empty and adds an appropriate error message rather than attempting to access the first element of an empty array.
Screenshots
N/A - This is a bug fix that prevents runtime errors without visible UI changes.
Rollout strategy
Direct merge to main branch. No feature flag needed as this is a bug fix for existing functionality.
Testing
Risks
Low risk. The change only adds an additional validation check without modifying existing logic.
Reviewer notes
The issue occurs in the
setRemoteValue
method where we directly accessval[0]
without first checking if the array contains any elements. This fix prevents the runtime error by explicitly handling the empty array case.