Repository navigation
fix: call the latest onReset when double-clicking a sash - #904
Merged
johnwalley merged 1 commit intoOct 11, 2026
Merged
Conversation
The sashreset listener is registered once in the mount effect and closed over the onReset prop from the first render. Keep onReset in a ref that is updated when the prop changes, like onChange/onDragStart/onDragEnd. Fixes #901
✅ Deploy Preview for allotment-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for allotment-website canceled.
|
johnwalley
self-requested a review
October 11, 2026 19:29
johnwalley
approved these changes
Oct 11, 2026
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.
Problem
If the
onResetprop changes after mount (for example because it depends on state), double-clicking a sash still calls theonResetfrom the first render.ref.current.reset()is not affected becauseuseImperativeHandlere-runs with the latest props.Cause
The
sashresetlistener is registered once in the mount effect and closes over the initialonReset.Fix
Keep
onResetin a ref and update it in auseEffectwhen the prop changes (the same wayonChange,onDragStartandonDragEndare kept in sync on theSplitView). The listener reads the ref, so it always calls the current callback.Tests
src/allotment.test.tsx: renders anAllotmentwith oneonReset, re-renders it with another, double-clicks the sash and checks that only the new callback is called. It fails without the fix (the stale callback is called) and passes with it.npm test(2 suites, 3 tests),npm run build,eslintandprettierpass.Fixes #901