Skip to content

XIVY-19301 Persist useOnFocus value on unmount#1594

Merged
ivy-edp merged 1 commit into
masterfrom
fix-useOnFocus
Jul 16, 2026
Merged

XIVY-19301 Persist useOnFocus value on unmount#1594
ivy-edp merged 1 commit into
masterfrom
fix-useOnFocus

Conversation

@ivy-edp

@ivy-edp ivy-edp commented Jul 15, 2026

Copy link
Copy Markdown
Member

When switching tabs quickly when inside a SingleLineCodeEditor, the blur event 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 useOnFocus that calls onChange with the latest focused value. This ensures edits are persisted even when blur is 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.

@ivy-lli ivy-lli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 useOnFocus intended to persist the latest focused value via onChange.
  • 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.

Comment thread packages/inscription-view/src/components/browser/useOnFocus.ts
Comment thread packages/inscription-view/src/components/browser/useOnFocus.ts
@ivy-edp

ivy-edp commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

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?

Yes AI proposed it and I quickly check and it seems to work with no side effect ✌️
I will add a test 👍
Yes this probably will also fix the bug you mentions or at least the process-editor part. I would need to check the form-editor separatly

Comment thread packages/inscription-view/src/components/browser/useOnFocus.ts
@ivy-edp
ivy-edp merged commit cc7b0ce into master Jul 16, 2026
12 checks passed
@ivy-edp
ivy-edp deleted the fix-useOnFocus branch July 16, 2026 06:19
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.

3 participants