Skip to content

fix(elements): Trigger additional change detection when method is invoked in elements - #17580

Open
mddragnev wants to merge 4 commits into
masterfrom
mdragnev/elements-method-cd
Open

fix(elements): Trigger additional change detection when method is invoked in elements#17580
mddragnev wants to merge 4 commits into
masterfrom
mdragnev/elements-method-cd

Conversation

@mddragnev

@mddragnev mddragnev commented Sep 8, 2026

Copy link
Copy Markdown
Member

Closes #17581

Description

Needed because of zone.js removal

Motivation / Context

Without zone.js, native browser event listeners do not automatically trigger Angular change detection when component methods are invoked from event callbacks. Because UI state changes may occur across various public methods, change detection is defensively scheduled after every method call to ensure consistent state updates.

Type of Change (check all that apply):

  • Bug fix
  • New functionality
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring (no functional changes)
  • Documentation
  • Demos
  • CI/CD
  • Tests
  • Changelog
  • Skills/Agents

Component(s) / Area(s) Affected:

How Has This Been Tested?

  • Unit tests
  • Manual testing
  • Automated e2e tests

Test Configuration:

  • Angular version:
  • Browser(s):
  • OS:

Screenshots / Recordings

Checklist:

  • All relevant tags have been applied to this PR
  • This PR includes unit tests covering all the new code (test guidelines)
  • This PR includes API docs for newly added methods/properties (api docs guidelines)
  • This PR includes feature/README.MD updates for the feature docs
  • This PR includes general feature table updates in the root README.MD
  • This PR includes CHANGELOG.MD updates for newly added functionality
  • This PR contains breaking changes
  • This PR includes ng update migrations for the breaking changes (migrations guidelines)
  • This PR includes behavioral changes and the feature specification has been updated with them
  • Accessibility (ARIA, keyboard navigation, focus management) has been verified

@mddragnev
mddragnev marked this pull request as ready for review September 8, 2026 09:48
Copilot AI lite review requested due to automatic review settings September 8, 2026 09:48

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.

🟡 Changes recommended

The current implementation schedules change detection unconditionally after method calls, which can cause redundant global ticks in zone-enabled builds and should be gated to the zoneless case.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR addresses missing change detection in Angular Elements when running without zone.js by explicitly scheduling Angular change detection after invoking configured component instance methods from the custom element wrapper (motivated by #17581 affecting grid search clear behavior).

Changes:

  • Add notifyChanges() to the custom elements strategy to manually notify Angular’s change detection scheduler.
  • Wrap generated element method proxies to schedule change detection after invoking the underlying component method.
  • Add a unit test covering grid search clear behavior to prevent the “mirrored cell value” stale rendering state.
File summaries
File Description
projects/igniteui-angular-elements/src/app/custom-strategy.ts Adds notifyChanges() hook for manually scheduling change detection; minor local refactor (letconst).
projects/igniteui-angular-elements/src/app/create-custom-element.ts Updates method proxy generation to invoke notifyChanges() after calling the component method.
projects/igniteui-angular-elements/src/app/custom-strategy.spec.ts Adds a regression test ensuring UI updates after invoking search-related methods (findNext, clearSearch).
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Lite

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

Comment thread projects/igniteui-angular-elements/src/app/create-custom-element.ts Outdated
Comment thread projects/igniteui-angular-elements/src/app/custom-strategy.ts

@damyanpetev damyanpetev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor note on the comment, otherwise LGTM

// Angular normally wraps listeners and schedules change detection to preserve Zone.js behavior.
// Like Angular Elements' setInputValue, we notify the scheduler explicitly because custom-element methods bypass that listener path.
// This behavior may change in a future Angular version.
// https://github.com/angular/angular/blob/9a58353b1b680f162a55969965ae6a90ae20316d/packages/core/src/change_detection/scheduling/zoneless_scheduling_impl.ts#L140

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Elements] Searching in data grid does not trigger a changeDetection after clearing the search

4 participants