fix(ui): keep Sheet close handlers current before passive effects flush
User description
Summary
SheetupdatedonCloseRef/requestCloseRefin a passiveuseEffect. A Close/swipe/back that landed after a commit but before the passive flush called the previous render'sonClose(stale closure).- Seen in CI on #3625 (
tests/admin-renewed-sheet.dom.test.tsxβΊ "clears the form once a save has actually completed", line 138): Close ranAdminRenewedSheet's pre-savehandleClose, so the saved state was not reset. - Fix: update the refs in
useLayoutEffect. Regression test intests/sheet.dom.test.tsxclicks Close from a MutationObserver right after the commit.
Areas touched: Design system
Verification
- Checks run: new freshness test fails without the fix (
expected [ +0 ] to deeply equal [ 1 ]) and passes with it;vitest run tests/sheet*.test.tsx tests/admin-*.dom.test.tsxβTest Files 28 passed (28), Tests 352 passed (352); eslint clean; push guard typecheck passed.
Risk and rollout
- Risk: low; ref assignment moves from passive to layout timing, no behaviour change otherwise.
- Rollback: revert this commit.
- Provider or production effects: None
Notes
- No checks, thresholds or tests loosened.
Summary by cubic
Fixes a stale-closure bug where Sheet's Close button, swipe, and back handlers could call the previous render's onClose when a click landed right after a commit but before passive effects flushed.
Now updates the close handler refs in an isomorphic layout effect (useLayoutEffect on the client, useEffect on the server), and adds a regression test that reproduces the race by clicking Close from a MutationObserver immediately after a commit.
CodeAnt-AI Description
Keep sheet close actions in sync with the latest state
What Changed
- Close, swipe, and back actions now use the latest close behavior immediately after a sheet updates
- Prevents closing a sheet after saving from running outdated behavior and skipping a reset
Impact
β
Saved sheet state resets on close
β
Close actions honor the latest state
π‘ Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
@codeant-ai ask: Your question here
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
@codeant-ai ask: Can you suggest a safer alternative to storing this secret?
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
@codeant-ai: Your feedback here
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
@codeant-ai: Do not flag unused imports.
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
@codeant-ai: review
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.
Summary by CodeRabbit
- Bug Fixes
- The Sheetβs Close action now uses the most recently updated close behavior, including when clicked immediately after an update. This prevents the action from relying on an outdated close handler during the transition between an update and the next effect.