fix: compare pass-through props in day-cell memo comparators - #19
Merged
Conversation
dayCellInstancePropsAreEqual / dayButtonInnerPropsAreEqual compared only date/render/columnIndex and the derived state, ignoring the arbitrary spread props (className, style, event handlers, data-*) the components forward onto their element. Those were frozen at first render — a consumer's changed className/handler wouldn't apply unless a compared field happened to change too. Add a shared passThroughPropsEqual shallow comparison (skipping the explicitly-handled keys and children, which is a fresh element each render) and AND it into both comparators. The comparators are now exported and unit-tested. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
|
🎉 This PR is included in version 2.0.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Audit medium M1.
Problem
DayCellInstanceandDayButtonInnerarememo'd with custom comparators (dayCellInstancePropsAreEqual,dayButtonInnerPropsAreEqual). Both compared onlydate/render/columnIndexand the_derivedStatefields — but both components accept arbitrary spread props ([key: string]: unknown) and forward them onto the rendered element (mergeProps(defaultProps, otherProps)). Those pass-through props (className,style,onPointerDown,data-*, …) were never compared, so they froze at first render: a consumer changingclassNameonDayCellTemplate/DayButtonsaw no update unless a compared field also changed.Fix
A shared
passThroughPropsEqual(prev, next, handledKeys)does a shallow compare of the remaining props, skipping the explicitly-handled keys andchildren(a fresh React element every render — never usefully comparable, matching the existing intent). It's AND-ed into both comparators, so genuine pass-through changes now re-render while stable props stay memoized.Tests
The comparators are now exported and unit-tested (
day-cell.test.tsx): changing aclassName/ handler /data-*returnsfalse(RED before the fix — they returnedtrue); unchanged props returntrue;childrendifferences are still ignored; derived-state changes still returnfalse.vp run ready: lint+typecheck 0/0, all suites green — including thegrid.perfmemoization tests (stable pass-through props, so no extra re-renders).🤖 Generated with Claude Code