Skip to content

Editors: get rid of the ctor overrides - #34925

Merged
EugeniyKiyashko merged 6 commits into
DevExpress:mainfrom
EugeniyKiyashko:typescript/ui/editor_drop_ctor_26_2
Aug 26, 2026
Merged

EugeniyKiyashko merged 6 commits into
DevExpress:mainfrom
EugeniyKiyashko:typescript/ui/editor_drop_ctor_26_2

Conversation

@EugeniyKiyashko

Copy link
Copy Markdown
Contributor

No description provided.

@EugeniyKiyashko EugeniyKiyashko self-assigned this Aug 26, 2026
Copilot AI lite review requested due to automatic review settings August 26, 2026 08:53
@EugeniyKiyashko
EugeniyKiyashko requested a review from a team as a code owner August 26, 2026 08:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the internal Editor initialization to rely on the framework’s _createElement lifecycle hook instead of overriding ctor, aligning Editor with the DOMComponent construction flow where _createElement is invoked before options initialization. It also adds Jest coverage to ensure validation-related fields are initialized at the correct time and behave as expected.

Changes:

  • Removed Editor.ctor(...) override and moved validationRequest / showValidationMessageTimeout initialization into _createElement(...).
  • Ensured the element is still marked as a validation target during element creation.
  • Added Jest tests to validate initialization order and validationRequest firing behavior on value changes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/devextreme/js/__internal/ui/editor/editor.ts Moves per-instance initialization from ctor to _createElement so it runs during DOMComponent element creation (before options init).
packages/devextreme/js/__internal/ui/editor/tests/editor.test.ts Adds Jest tests covering initialization ordering, validation target marking, and validationRequest behavior on value updates.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

TextEditorBase.ctor validated the buttons option, built the button
collection and reset the button/label containers before delegating to
DOMComponent.ctor. All of it moves into a new _init() override: _init()
still runs inside the same construction call and before _initMarkup(), so
_renderButtonContainers() finds the collection, and every descendant
override (text_editor.mask, drop_down_editor, select_box) calls
super._init() first, so the base keeps running earlier than subclass init.

The buttons option is now read through this.option() destructuring instead
of the raw options bag, which makes the `if (options)` guard unnecessary -
the option store is initialized by the time _init() runs.

Adds jest coverage for the button collection being ready before the markup
is rendered, for the declared button surviving a repaint and for the E1053
check, so moving the setup to render time cannot slip through unnoticed.

Refactoring card: DevExpress/devextreme-private#3836
TextBox.ctor cached the user-provided showClearButton before delegating to
DOMComponent.ctor. Search mode force-enables the clear button, and that cache
is what tells "the user asked for it" from "search mode turned it on", so the
value has to be captured before the defaults are merged in - reading the
merged option later cannot reproduce it.

_initOptions() receives the same raw option bag inside the same construction
call, so the capture moves there as is. The `if (options)` guard is dropped:
by that point the bag is always an object, Component.ctor defaults it.

Adds jest coverage for both sides of the distinction - search mode enables the
clear button when the option is omitted and leaves it alone when it is passed
explicitly (T218573) - so switching to the merged value cannot pass unnoticed.

Refactoring card: DevExpress/devextreme-private#3836
Both ctors existed only to raise a deprecation warning after delegating to
DOMComponent.ctor, and both need the raw option bag: they ask whether the user
mentioned the option at all ('preventScrollEvents' in options, 'provider' in
options), which the merged value cannot answer.

_initOptions() receives that same raw bag inside the same construction call, so
the checks move there unchanged. The `if (options)` guards are dropped - the bag
is always an object by then. The warning is now raised while options are being
processed instead of after the first render; for a log line that is immaterial,
and the existing coverage pins it: the overlay preventScrollEvents module
(including the _ignorePreventScrollEventsDeprecation cases) and the dxMap
"provider is set to bing on init/runtime" tests.

With this, js/__internal/ui no longer declares ctor anywhere.

Refactoring card: DevExpress/devextreme-private#3836
Copilot AI review requested due to automatic review settings August 26, 2026 09:41
@EugeniyKiyashko EugeniyKiyashko changed the title Editor: replace the ctor override with _createElement Editors: get rid of the ctor overrides Aug 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

Comment thread packages/devextreme/js/__internal/ui/editor/editor.ts
Review follow-up: creating the validationRequest callbacks while the element is
being created reads as a side effect. _init() is the canonical place and it is
still early enough - DOMComponent.endUpdate() calls super.endUpdate() (which
reaches _initializeComponent -> _init) before _updateDOMComponent() renders.

Nothing observes the two fields in the window this opens up: the only place that
fires validationRequest is _optionChanged, which _notifyOptionChanged gates
behind _initialized - set after _init() returns; initValidationOptions() is a
pure options transform; and the external subscriber is added by DefaultAdapter
once the editor exists. _init() also cannot run twice, _initialized is only ever
set to true, so the callbacks object cannot be replaced under a subscriber.

The jest case is repinned from "before the options are initialized" - that was
the status quo, not a requirement - to "before the markup is rendered".
Copilot AI review requested due to automatic review settings August 26, 2026 10:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread packages/devextreme/js/__internal/ui/text_box/text_editor.base.ts
Reverts the move to _init() from the previous commit - it broke the
DxValidator "should work with dx-validator" angular tests.

devextreme-angular passes an onInitializing handler that calls beginUpdate() on
the widget itself (packages/devextreme-angular/src/core/component.ts), so the
editor's _init() is deferred until the wrapper calls endUpdate() in its own
ngAfterViewInit. A nested <dx-validator> is a child component and Angular runs
child ngAfterViewInit first, so the validator binds to the editor while its
_init() still has not run: DefaultAdapter then calls .add on an undefined
validationRequest. _createElement() is inside the constructor proper and is not
affected by the update lock, which is why the callbacks belong there - next to
the registration that makes the element a validation target in the first place.

The ordering probe is replaced with a test that reproduces the same flow without
Angular: the editor is created with an onInitializing that calls beginUpdate(),
a Validator is attached while initialization is still deferred, and the editor
is released with endUpdate(). It fails with the same TypeError if the setup is
moved to _init().
Copilot AI review requested due to automatic review settings August 26, 2026 11:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@EugeniyKiyashko
EugeniyKiyashko merged commit 01c44b1 into DevExpress:main Aug 26, 2026
106 of 107 checks passed
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.

3 participants