Skip to content

fix: Correct data handling logic in Paragraphs Model for non-array data #7559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

anilpixel
Copy link

Bug Fix: Handle empty array validation in Paragraphs component

Reason for change

Problem: The setRemoteValue method in the Paragraphs component doesn't properly handle empty arrays. When an empty array [] is received as input, the code attempts to access properties of val[0] which results in a JavaScript runtime error (trying to access properties of undefined).

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

  • Manual test by providing an empty array as data source for the Paragraphs component
  • Add unit test for empty array condition

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 access val[0] without first checking if the array contains any elements. This fix prevents the runtime error by explicitly handling the empty array case.

Copy link

netlify bot commented May 19, 2025

👷 Deploy request for heartex-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit c791f9f

Copy link

netlify bot commented May 19, 2025

👷 Deploy request for label-studio-docs-new-theme pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit c791f9f

@github-actions github-actions bot added the fix label May 19, 2025
Copy link

netlify bot commented May 19, 2025

Deploy Preview for label-studio-storybook ready!

Name Link
🔨 Latest commit c791f9f
🔍 Latest deploy log https://app.netlify.com/projects/label-studio-storybook/deploys/682aa5fe525181000833d9fb
😎 Deploy Preview https://deploy-preview-7559--label-studio-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant