[utils] Fix usePreviousValue equality comparison#5264
Open
lyzno1 wants to merge 1 commit into
Open
Conversation
lyzno1
marked this pull request as ready for review
July 18, 2026 12:49
commit: |
Bundle size
PerformanceTotal duration: 1,039.53 ms -71.67 ms(-6.5%) | Renders: 78 (+0) | Paint: 1,648.10 ms -118.36 ms(-6.7%)
14 tests within noise — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Changes
usePreviousValuewithObject.isNaN, transitions toNaN, and signed zero transitionsWhy
usePreviousValueupdates state during render when its input changes. Strict inequality treatsNaNas different from itself, so rendering the hook withNaNrepeatedly schedules another render and eventually throws a "Too many re-renders" error.Using
Object.ismakes the hook follow React's state equality semantics: repeatedNaNvalues are stable, while positive and negative zero remain distinguishable.Impact
Consumers of the public utility can safely pass
NaNwithout triggering an infinite render loop. Existing internal call sites use non-numeric values and retain their current behavior.Tests
pnpm test:jsdom usePreviousValue --no-watchpnpm typescriptpnpm eslintpnpm prettierI have followed (at least) the PR section of the contributing guide.