fix(content-types): reset field editor form state when creating a new field#35435
fix(content-types): reset field editor form state when creating a new field#35435
Conversation
… field The field properties dialog leaked values (notably the Value textarea) from a previously saved field into the next new field. Two fixes: - DotTextareaContentComponent.writeValue skipped empty/null/undefined via a truthy guard, so the Monaco editor kept stale content when the form control was reset. - DynamicFieldPropertyDirective compared previous/current field by id, but new fields share a null id, so the inner property component was reused across different field dialogs. Compare by field reference instead so the component is recreated when the field changes. Closes #35434
|
Claude finished @oidacra's task in 2m 32s —— View job PR Review
The fix is correct and the root cause analysis is accurate. Two issues worth flagging: 1.
writeValue(value: string): void {
this.value = value ?? '';
}The implementation now handles 2. The
The outer In practice this edge case is rare because field switches produce a different Everything else is clean. |
…sed recreation Add three unit tests for the new shouldRecreate logic: - Two new fields with id=null but different references recreate the inner component. - The same field reference passed again does not recreate. - Switching from a saved field to a new null-id field recreates. Addresses review feedback on #35435.
|
Added three unit tests in 13adbe9 covering the new reference-based
All 2109 tests pass. |
Summary
Fixes a bug in the content type editor where the field properties dialog leaked state (most visibly the Value textarea) from a previously saved field into a newly opened field dialog. Users would see the prior field's values prepopulated, the textarea would behave as uneditable, and Save would stay disabled until toggling an unrelated checkbox.
Closes #35434
Root cause
Two independent defects compounded to produce the visible behavior:
DotTextareaContentComponent.writeValuehad a truthy guard (if (value)) that skipped empty/null/undefined values. When Reactive Forms calledwriteValue('')to reset the control, the Monaco editor's internal model kept the stale content from the previous field.DynamicFieldPropertyDirectivedecided whether to recreate the dynamic inner component by comparingpreviousFieldId !== currentFieldId. Since every new field hasid === null, switching between two new fields (e.g. Radio → Select) resulted innull !== null === false→ theValuesPropertyComponent(and its child Monaco editor) was reused rather than recreated, preserving its stale DOM.Changes
dot-textarea-content.component.ts—writeValuenow writes the value directly (using?? ''), so empty/null/undefined correctly reset the control.dynamic-field-property.directive.ts— compare the previous vs. current field reference instead of ids, so the inner component is recreated whenever the field instance changes.dot-textarea-content.component.spec.ts— newwriteValuetests asserting the control resets for'',null, andundefined.Acceptance criteria
writeValuecorrectly resets for empty/null/undefined.Test plan
value|1/value.2|2, save.