Skip to content

fix: panic caused by "state() called before manage()"#806

Merged
medcl merged 1 commit intomainfrom
fix/tauri_panic
Jul 23, 2025
Merged

fix: panic caused by "state() called before manage()"#806
medcl merged 1 commit intomainfrom
fix/tauri_panic

Conversation

@SteveLauC
Copy link
Copy Markdown
Member

@SteveLauC SteveLauC commented Jul 23, 2025

This commit fixes the following panic:

Time: [2025-07-23-17-03-23]
Location: [/Users/steve/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tauri-2.5.1/src/lib.rs:742:7]
Message: [state() called before manage() for tauri_plugin_global_shortcut::GlobalShortcut<tauri_runtime_wry::Wry<tauri::EventLoopMessage>>]

The root cause is that, in a Tauri application, before you can access a piece of managed state with the .state() method, you must first register it with Tauri using .manage(). When a user reigsters hotkey for an extension, initializing extensions will invoke the .state() method, at that point, .manage() hasn't been called.

The fix is simple, we simply call .manage() earlies (invoked by our shortcut::enable_shortcut(app) function).

What does this PR do

Rationale for this change

Standards checklist

  • The PR title is descriptive
  • The commit messages are semantic
  • Necessary tests are added
  • Updated the release notes
  • Necessary documents have been added if this is a new feature
  • Performance tests checked, no obvious performance degradation

This commit fixes the following panic:

```
Time: [2025-07-23-17-03-23]
Location: [/Users/steve/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tauri-2.5.1/src/lib.rs:742:7]
Message: [state() called before manage() for tauri_plugin_global_shortcut::GlobalShortcut<tauri_runtime_wry::Wry<tauri::EventLoopMessage>>]
```

The root cause is that, in a Tauri application, before you can access a piece of
managed state with the .state() method, you must first register it with Tauri
using .manage(). When a user reigsters hotkey for an extension,
initializing extensions will invoke the .state() method, at that point,
.manage() hasn't been called.

The fix is simple, we simply call .manage() earlies (invoked by our
`shortcut::enable_shortcut(app)` function).
@medcl medcl merged commit ca3b514 into main Jul 23, 2025
4 checks passed
@medcl medcl deleted the fix/tauri_panic branch July 23, 2025 10:56
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