-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Description
When using context menus with checkbox (checked) items on macOS, calling setMenuItemChecked() does not update the visual state in time — the checkmark appears stale when the menu opens.
Root cause: The Objective-C implementation of setMenuItemChecked() wraps the NSMenuItem.state assignment inside dispatch_async(dispatch_get_main_queue(), ...). This means the state change is enqueued and executes after the menu has already been rendered and shown to the user.
As a result, if you update checked state in response to an action and then the user right-clicks to reopen the context menu, the menu displays the previous checked state rather than the current one.
To Reproduce
- Create an application context menu with checkbox-style items (e.g., Bold, Italic formatting toggles)
- Use the context menu to toggle an item (e.g., Bold on)
- Immediately right-click again to reopen the context menu
- Observe that the checked state shown is stale (reflects the state before the toggle)
The issue occurs because:
- The action callback fires and calls
setMenuItemChecked(true) dispatch_asyncenqueues theNSMenuItem.state = NSControlStateValueOncall- The user opens the menu again before the async block executes
- Menu renders with the old state
Expected behaviour
setMenuItemChecked() should update NSMenuItem.state synchronously (or at least before the menu is displayed). If the call originates from the main thread, dispatch_async is unnecessary. If it comes from a background thread, dispatch_sync or checking NSThread.isMainThread would ensure the state is applied before the menu renders.
Workaround
On the application side, we work around this by manually re-reading the current state after each action triggered from the context menu and pushing it to Go via an explicit IPC call, ensuring the Go-side state is up to date before the next menu open. Deduplication prevents unnecessary IPC when the state hasn't actually changed.
Related issues
- [v3] Dynamic Context Menu #4012 — Dynamic Context Menu (macOS)
- [v3] Updating a systray menu while it's open breaks click handlers #4719 — Updating a systray menu while it's open breaks click handlers
- PR Fix macOS system tray menu real-time updates using NSMenuDelegate #4828 — Fix macOS system tray menu real-time updates using NSMenuDelegate
These are related but focus on systray menus. This issue affects application context menus with checked items.
System Details
Wails v3 alpha
Platform: macOS (darwin/arm64)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status