Skip to content

fix(edit-content): guard against non-array category values when translating#35248

Merged
oidacra merged 3 commits intomainfrom
issue-33932-categories-translate-error
Apr 10, 2026
Merged

fix(edit-content): guard against non-array category values when translating#35248
oidacra merged 3 commits intomainfrom
issue-33932-categories-translate-error

Conversation

@oidacra
Copy link
Copy Markdown
Member

@oidacra oidacra commented Apr 7, 2026

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

  • Translation no longer crashes when Categories field is empty
  • Existing category selection behavior unchanged
  • Empty/null/non-array values return empty array

Test Plan

  • 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

Note

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, and DotEditContentFormComponent.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

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Apr 7, 2026

Claude finished @oidacra's task in 3m 20s —— View job


Claude finished @oidacra's task in 1m 15s —— View job


Rollback Safety Analysis — Complete

  • Gather context from PR data
  • Read rollback-unsafe categories reference
  • Get full PR diff (commits bf6b6d53...8739ff5e, 3 new commits)
  • Analyze diff against unsafe categories
  • Applied label: AI: Safe To Rollback

Result: ✅ Safe To Rollback

All changes in this PR are pure frontend TypeScript/Angular — no unsafe categories apply:

Category Applies? Reason
C-1 Structural Data Model Change ✅ No No DB schema changes
C-2 Elasticsearch Mapping Change ✅ No No ES mapping touched
C-3 Content JSON Model Version Bump ✅ No No CURRENT_MODEL_VERSION change
C-4 DROP TABLE/Column ✅ No No SQL DDL
H-1 One-Way Data Migration ✅ No No data transformation tasks
H-2 RENAME TABLE/Column ✅ No No renames
H-3 PK Restructuring ✅ No No constraint changes
H-4 New Field Type ✅ No No new field types registered
H-5 Storage Provider Change ✅ No No storage config changes
H-6 DROP PROCEDURE/FUNCTION ✅ No No stored procedure changes
M-1 Column Type Change ✅ No No type alterations
M-2 Bundle Format Change ✅ No No push-publishing bundlers touched
M-3 REST/GraphQL API Contract ✅ No Frontend-only changes
M-4 OSGi Interface Breakage ✅ No No Java/OSGi changes

Changed files (all frontend TypeScript):

  • category-field.utils.ts — Added Array.isArray() guard before .map() call
  • dot-edit-content-form.component.ts — Added early return for CATEGORY fields to preserve array values without calling processFieldValue
  • 3 spec files — Unit test additions covering the new guards

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@oidacra oidacra marked this pull request as ready for review April 8, 2026 14:48
@oidacra oidacra self-assigned this Apr 8, 2026
@oidacra oidacra enabled auto-merge April 8, 2026 21:12
@oidacra oidacra added this pull request to the merge queue Apr 8, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 8, 2026
@oidacra oidacra added this pull request to the merge queue Apr 9, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 9, 2026
@oidacra oidacra added this pull request to the merge queue Apr 9, 2026
github-merge-queue bot pushed a commit that referenced this pull request Apr 9, 2026
…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 |
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 9, 2026
@oidacra oidacra added this pull request to the merge queue Apr 10, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 10, 2026
oidacra added 2 commits April 10, 2026 11:06
…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.
@oidacra oidacra force-pushed the issue-33932-categories-translate-error branch from ba0a23f to 60f2f72 Compare April 10, 2026 15:06
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Apr 10, 2026

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.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

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.

Comment thread core-web/libs/edit-content/src/lib/utils/functions.util.spec.ts
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.
@cursor
Copy link
Copy Markdown

cursor bot commented Apr 10, 2026

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.

@oidacra oidacra enabled auto-merge April 10, 2026 15:27
@oidacra oidacra added this pull request to the merge queue Apr 10, 2026
Merged via the queue into main with commit 9f03cf9 Apr 10, 2026
36 checks passed
@oidacra oidacra deleted the issue-33932-categories-translate-error branch April 10, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI: Safe To Rollback Area : Frontend PR changes Angular/TypeScript frontend code

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[DEFECT] Error when translating content without Categories in New Edit Contentlet Mode

4 participants