Skip to content

fix: call the latest onReset when double-clicking a sash - #904

Merged
johnwalley merged 1 commit into
johnwalley:mainfrom
SahinurDEV:fix/sash-reset-latest-onreset
Oct 11, 2026
Merged

johnwalley merged 1 commit into
johnwalley:mainfrom
SahinurDEV:fix/sash-reset-latest-onreset

Conversation

@SahinurDEV

Copy link
Copy Markdown
Contributor

Problem

If the onReset prop changes after mount (for example because it depends on state), double-clicking a sash still calls the onReset from the first render. ref.current.reset() is not affected because useImperativeHandle re-runs with the latest props.

Cause

The sashreset listener is registered once in the mount effect and closes over the initial onReset.

Fix

Keep onReset in a ref and update it in a useEffect when the prop changes (the same way onChange, onDragStart and onDragEnd are kept in sync on the SplitView). The listener reads the ref, so it always calls the current callback.

Tests

  • Added src/allotment.test.tsx: renders an Allotment with one onReset, 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, eslint and prettier pass.

Fixes #901

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
@netlify

netlify Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for allotment-storybook ready!

Name Link
🔨 Latest commit 7c323a2
🔍 Latest deploy log https://app.netlify.com/projects/allotment-storybook/deploys/6ac7856105635e0007aa20fd
😎 Deploy Preview https://deploy-preview-904--allotment-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for allotment-website canceled.

Name Link
🔨 Latest commit 7c323a2
🔍 Latest deploy log https://app.netlify.com/projects/allotment-website/deploys/6ac7856116c09a000811836a

@johnwalley
johnwalley merged commit b4d9fca into johnwalley:main Oct 11, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

onReset changes after mount are ignored when double-clicking a sash

2 participants