Skip to content

feat: callback version of conflictBehavior#54

Open
skyboyer wants to merge 3 commits intoTanStack:mainfrom
skyboyer:feat-callback-for-conflictbehavior
Open

feat: callback version of conflictBehavior#54
skyboyer wants to merge 3 commits intoTanStack:mainfrom
skyboyer:feat-callback-for-conflictbehavior

Conversation

@skyboyer
Copy link

@skyboyer skyboyer commented Mar 7, 2026

🎯 Changes

As discussed in #47 we may want to do unregister conflicting hot key conditionally(e.g. after showing the confirmation popup) instead of doing it always. Or we may want to log conflict to a remote endpoint, not just show error locally.
Here is how it will be reflected in DevTools:
2026-03-07 09_24_38

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

<div class={styles().optionRow}>
<span class={styles().optionLabel}>conflictBehavior</span>
<span class={styles().optionValue}>{conflictBehavior()}</span>
<span class={styles().optionValue}>{serializeConflictBehavior(conflictBehavior())}</span>
Copy link
Author

Choose a reason for hiding this comment

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

conflictBehavior() cannot be directly rendered in JSX any more. I considered String(conflictBehavior()) but it just dumps callback version as plain JS code which does not look good 😅

}

if (typeof conflictBehavior === 'function') {
conflictBehavior(keyDisplay, () => unregister(conflictingId))
Copy link
Author

@skyboyer skyboyer Mar 7, 2026

Choose a reason for hiding this comment

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

I don't think it makes sense to expose conflictingId and unregister separately in this case with a callback

'Mod+S',
expect.any(Function),
)
handleConflictCallback.mock.calls[0]?.[1]()
Copy link
Author

Choose a reason for hiding this comment

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

mimics custom async logic inside the callback, e.g. call unregisterConflicting after displaying a popup and user clicked "Confirm"

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 7, 2026

Open in StackBlitz

@tanstack/hotkeys

npm i https://pkg.pr.new/@tanstack/hotkeys@54

@tanstack/hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/hotkeys-devtools@54

@tanstack/preact-hotkeys

npm i https://pkg.pr.new/@tanstack/preact-hotkeys@54

@tanstack/preact-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/preact-hotkeys-devtools@54

@tanstack/react-hotkeys

npm i https://pkg.pr.new/@tanstack/react-hotkeys@54

@tanstack/react-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/react-hotkeys-devtools@54

@tanstack/solid-hotkeys

npm i https://pkg.pr.new/@tanstack/solid-hotkeys@54

@tanstack/solid-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/solid-hotkeys-devtools@54

commit: 0da4d23

- `'warn'` - Log a warning to the console but allow both registrations (default)
- `'error'` - Throw an error and prevent the new registration
- `'replace'` - Unregister the existing registration and register the new one
- `'allow'` - Allow multiple registrations without warning
Copy link
Author

Choose a reason for hiding this comment

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

I added a new entry here but autofix removed it.

  • custom callback - You can log the issue with configuration or unregister conflicting registration conditionally e.g. with showing confirmation popup

How could I keep it?

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.

2 participants