perf(module:select): do not run change detection if the triggerWidth
has not been changed
#6858
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Checklist
PR Type
What is the current behavior?
Currently, the
nz-select
callsupdateCdkConnectedOverlayStatus
every time the select is opened or closed. TheupdateCdkConnectedOverlayStatus
schedules a frame callback which is triggering the whole layout update (due togetBoundingClientRect()
) and it callsmarkForCheck()
which forces Angular to run the change detection from the root component down tonz-select
.It causes frame drops since the main thread is busy with:
tick()
We don't need to run the
markForCheck()
since we don't need the "global" change detection. ThetriggerWidth
is bound tocdkConnectedOverlayMinWidth
, thetriggerWidth
is a number, number bindings are not updated each change detection cycle, since Angular usesObject.is
comparison to determine if the binding has been changed or not:This means that if the
triggerWidth
hasn't been updated, thecdkConnectedOverlayMinWidth
binding will not be re-evaluated. This means we have a "dead" change detection (thetick()
has been run, but there's nothing to update).What is the new behavior?
The change detection is not running anymore from the root component when the frame callback fires since it'll check if the
triggerWidth
has been changed or not.Does this PR introduce a breaking change?