Skip to content

fix(edit-content): clear stale field state on manual locale translation#35596

Merged
adrianjm-dotCMS merged 9 commits into
mainfrom
issue-35521-stale-field-state-content-editor
May 11, 2026
Merged

fix(edit-content): clear stale field state on manual locale translation#35596
adrianjm-dotCMS merged 9 commits into
mainfrom
issue-35521-stale-field-state-content-editor

Conversation

@adrianjm-dotCMS
Copy link
Copy Markdown
Member

@adrianjm-dotCMS adrianjm-dotCMS commented May 6, 2026

Summary

Fixes the two scenarios from issue #35521 where stale form field state was not properly cleared:

  • Scenario 1 (fix(angular-form-bridge)): When switching between content items of the same type, stale values from the previous item were shown. Fixed by resetting the AngularFormBridge instance when called with a different FormGroup.
  • Scenario 2 (fix(edit-content)): When changing locale via Translate Manually, not all fields were cleared — fields with internal state (binary/image, date picker, relationship, custom fields) retained values from the original locale.
Screen.Recording.2026-05-06.at.3.55.27.PM.mov

Root Cause (Scenario 2)

Two layers of state weren't being cleared on manual translation:

  1. FormControls — resolution functions fell back to field.defaultValue when contentlet was null, so fields with a configured default showed that default instead of empty.
  2. Component internal state — field components like binary, date, relationship, and custom fields manage their own visual state independently of the FormControl. Simply rebuilding the FormGroup with null values wasn't enough to clear what these components rendered.

Changes

edit-content.store.ts — Adds isManualTranslation: boolean to the store state.

locales.feature.ts — Sets isManualTranslation: true in patchState when the user selects "Translate Manually".

dot-edit-content-form-resolutions.ts — Adds isManualTranslation as an optional 4th parameter to FnResolutionValue and updates all resolution functions that fell back to field.defaultValue when contentlet was null. When isManualTranslation is true, they return null/[] instead, ensuring FormControls start truly empty.

dot-edit-content-form.component.ts / .html — Adds $shouldRenderFields signal. When isManualTranslation is true, the copy-locale effect sets the signal to false (destroying all field components) then restores it to true via setTimeout (recreating them fresh). Components recreated with contentlet = null initialize to their empty/default visual state without any prior data.

Checklist

  • Tests
  • Translations
  • Security Implications Contemplated (add notes if applicable)

Additional Info

The $shouldRenderFields toggle causes a one-frame flash while field components are destroyed and recreated. This is intentional and expected — it happens only on the "Translate Manually" path after the user confirms the dialog.

This PR fixes: #35521

This PR fixes: #35521

…oup changes

- Refactored `getInstance` method to reset and create a new instance of `AngularFormBridge` when called with a different `FormGroup` or `NgZone`.
- Removed console warning for instance retrieval with different parameters, ensuring a new instance is returned instead.
- Updated unit tests to reflect the new behavior, ensuring instances are correctly managed based on form changes.

This change enhances the reliability of instance management in dynamic form scenarios.
@claude

This comment was marked as resolved.

…t form

- Added `isManualTranslation` parameter to resolution functions to handle manual translation scenarios.
- Updated resolution functions to return `null` for manual translations when contentlet is not available.
- Introduced `$shouldRenderFields` signal to manage field rendering based on manual translation state.
- Modified HTML template to conditionally render fields based on the new signal.

This change improves the handling of manual translations, ensuring that the form behaves correctly when translating content.
@adrianjm-dotCMS adrianjm-dotCMS changed the title fix(angular-form-bridge): update instance management logic for FormGr… fix(edit-content): clear stale field state on manual locale translation May 6, 2026
…m rendering

- Removed unnecessary `isManualTranslation` parameter from `hostFolderResolutionFn`, simplifying the resolution logic.
- Updated `DotEditContentFormComponent` to utilize `untracked` for managing reactivity during locale copying, ensuring that only relevant state changes trigger re-execution.
- Introduced `#flushFieldsForRerender` method to reset field components, enhancing the form's responsiveness to manual translation scenarios.
- Adjusted `locales.feature.ts` to correctly set `isManualTranslation` based on the copy type.

These changes enhance the edit content form's behavior during manual translations, ensuring a smoother user experience.
@adrianjm-dotCMS adrianjm-dotCMS marked this pull request as ready for review May 6, 2026 20:00
…nctions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ge behavior

- Reset isManualTranslation to false when switching to a translated locale
- Guard AngularFormBridge.destroy() against orphan instances decrementing live refCount
- Make $shouldRenderFields protected readonly in dot-edit-content-form component
- Add isManualTranslation assertions and reset test to locales.feature.spec
- Add fakeAsync tests for $shouldRenderFields toggle on manual translation
- Document categoryResolutionFn array-branch asymmetry with isManualTranslation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…1-stale-field-state-content-editor

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	core-web/libs/edit-content/src/lib/components/dot-edit-content-form/dot-edit-content-form.component.ts
Copy link
Copy Markdown
Member

@zJaaal zJaaal left a comment

Choose a reason for hiding this comment

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

Approving since all comments are related to readability

- Replace nested ternaries with early returns in defaultResolutionFn, textFieldResolutionFn, and blockEditorResolutionFn
- Flatten isCopyingLocale effect with early return
- Refactor getInitialFieldValue to use an object parameter
- Fix accumulating onDestroy callbacks in #flushFieldsForRerender

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@adrianjm-dotCMS adrianjm-dotCMS added this pull request to the merge queue May 11, 2026
Merged via the queue into main with commit ffcc213 May 11, 2026
30 checks passed
@adrianjm-dotCMS adrianjm-dotCMS deleted the issue-35521-stale-field-state-content-editor branch May 11, 2026 19:23
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.

[BUG] Form fields retain stale values when switching between content items

4 participants