fix(edit-content): guard against non-array category values when translating#35248
fix(edit-content): guard against non-array category values when translating#35248
Conversation
|
Claude finished @oidacra's task in 3m 20s —— View job Claude finished @oidacra's task in 1m 15s —— View job Rollback Safety Analysis — Complete
Result: ✅ Safe To RollbackAll changes in this PR are pure frontend TypeScript/Angular — no unsafe categories apply:
Changed files (all frontend TypeScript):
|
There was a problem hiding this comment.
Pull request overview
Guards category field translation logic against non-array values to avoid runtime crashes when translating contentlets with empty or unexpected Categories values.
Changes:
- Updated
getSelectedFromContentlet()to return an empty array when the underlying contentlet value isn’t an array (preventing.map()crashes).
…lating (#35248) ## Summary - Add `Array.isArray()` guard in `getSelectedFromContentlet()` to prevent `.map()` crash when the category field value is not an array (e.g., during content translation when the field is empty or has unexpected type) Closes #33932 ## Acceptance Criteria - [x] Translation no longer crashes when Categories field is empty - [x] Existing category selection behavior unchanged - [x] Empty/null/non-array values return empty array ## Test Plan - [x] `yarn nx test edit-content --testPathPattern=category-field.utils` — all tests pass - [ ] Manual: Create content with empty categories, translate to new language ## Changed Files | File | Change | |------|--------| | `libs/edit-content/.../category-field.utils.ts:30-34` | Added `Array.isArray()` guard |
…lating Add Array.isArray() check in getSelectedFromContentlet() to prevent .map() crash when category field value is not an array (e.g., empty content during translation). Closes #33932
… string when translating When translating a contentlet to a new language, the backend returns categories as an empty string. The processFormValue fallback (?? '') did not catch this because ?? only handles null/undefined. Now Category fields use Array.isArray() to guarantee the payload always contains an array.
ba0a23f to
60f2f72
Compare
|
Rollback safety analysis complete. The label AI: Safe To Rollback has been applied. All changes are pure frontend TypeScript/Angular - no DB, ES, or API contract changes. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is kicking off a free cloud agent to fix these issues. This run is complimentary, but you can enable autofix for all future PRs in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 60f2f72. Configure here.
The category guard in processFormValue was checking Array.isArray on the already-processed value (a comma-joined string), causing it to always return an empty array. Move the guard before processFieldValue and check the original fieldValue instead.
|
You have used all of your free Bugbot PR reviews. To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial. |

Summary
Array.isArray()guard ingetSelectedFromContentlet()to prevent.map()crash when the category field value is not an array (e.g., during content translation when the field is empty or has unexpected type)Closes #33932
Acceptance Criteria
Test Plan
yarn nx test edit-content --testPathPattern=category-field.utils— all tests passChanged Files
libs/edit-content/.../category-field.utils.ts:30-34Array.isArray()guardNote
Low Risk
Low risk: adds defensive type checks and normalization for category field values to prevent crashes when translation returns unexpected types.
Overview
Prevents edit-content translation flows from crashing when Category fields come back as non-arrays (e.g., empty string).
getSelectedFromContentlet()now returns[]unless the contentlet value is an array, andDotEditContentFormComponent.processFormValue()normalizes processed Category values to an array (non-arrays become[]). Tests were extended to cover these translation/edge cases and ensure array values are preserved.Reviewed by Cursor Bugbot for commit 60f2f72. Bugbot is set up for automated code reviews on this repo. Configure here.
This PR fixes: #33932