XIVY-19301 Persist useOnFocus value on unmount#1594
Conversation
ivy-lli
left a comment
There was a problem hiding this comment.
No idea either... Has AI proposed this?
A test for it would definitely be cool :)
But I think this is the same bug as: https://axon-ivy.atlassian.net/browse/XIVY-19187?
There was a problem hiding this comment.
Pull request overview
This PR addresses a UX/data-loss issue where rapid tab switching can unmount a focused SingleLineCodeEditor before blur fires, causing the latest edits to be dropped. It adds an unmount-time persistence mechanism to useOnFocus so the last focused value is committed even when blur is skipped.
Changes:
- Add an unmount cleanup in
useOnFocusintended to persist the latest focused value viaonChange. - Track latest value/callback via refs so the cleanup uses up-to-date data.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Yes AI proposed it and I quickly check and it seems to work with no side effect ✌️ |
When switching tabs quickly when inside a
SingleLineCodeEditor, theblurevent is not fired before the component unmounts. As a result, the most recently typed value is being lost.This change adds an unmount cleanup to
useOnFocusthat callsonChangewith the latest focused value. This ensures edits are persisted even whenbluris skipped.I am not sure if this is the best approach, as now the onChange is also always triggered on mount of the component too, which is not nessacary. Maybe i can add a check that ensures the onChange only runs if the value actually changed. There may also be a cleaner solution that avoids this behavior altogether.
If this approach looks reasonable, I can also add a test covering this scenario.