Repository navigation
Fix: prevent unnecessary property change notifications for NaN - #21171
Karthikeya1500 wants to merge 1 commit into
Conversation
When setting a property to NaN, if its current value is already NaN, `currentValue !== value` evaluates to `true` (since `NaN !== NaN` in JS). This triggers false positive property change notifications and unnecessary reactivity recalculations. Using `!Object.is(currentValue, value)` correctly checks for value equivalence.
|
Do you have a test that recreates this NaN !== NaN situation? |
|
|
|
Thank you for the context, @kategengler! I wasn't aware of the upcoming deprecation in RFC #1129. I completely understand the reasoning behind freezing the internal code for @NullVoxPopuli Given the feedback above and the decision not to merge fixes in this area, I'll hold off on writing a test for this edge case unless you feel it would still be useful to have for posterity. I'll go ahead and close this PR. Thanks both for your time reviewing it! |
Fix: Correct equality check for NaN in property change detection
Problem
Currently, both
_setProp(property_set.ts) and the computed property caching logic (computed.ts) use strict equality (===/!==) to determine whether a property value has changed.However, in JavaScript
NaN !== NaNalways evaluates totrue. Because of this, updating a property fromNaNtoNaNis incorrectly treated as a change. This bypasses Ember’s early-return optimizations and triggersnotifyPropertyChange, even though the value has not actually changed.In larger applications, this can lead to unnecessary observer executions, reactive updates, and avoidable DOM re-renders.
Solution
Replace strict equality checks with
Object.is()when comparing the new value with the cached value.Object.is()correctly handles edge cases such asNaNand distinguishes between+0and-0.With this change, setting a property from
NaNtoNaNwill be correctly recognized as an unchanged value, preventing unnecessary reactive updates.Impact
This improves the correctness of Ember’s change detection and avoids false-positive property change notifications in the core reactivity loop. Although small, this fix helps eliminate potential performance overhead caused by redundant updates.