# gpui: Defer appearance change callback to avoid reentrant borrow \(\#61789\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/a11083f9a79495e9c7ddee0c5782f22d07695c31)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: a11083f9a79495e9c7ddee0c5782f22d07695c31

Requested commit: a11083f9a79495e9c7ddee0c5782f22d07695c31

Commit: a11083f9a79495e9c7ddee0c5782f22d07695c31

Tree: 3ff1df67ab60d270654beac87eda29433fbf4e2d

Author: Mayank Verma

Committer: GitHub

## Message

```
gpui: Defer appearance change callback to avoid reentrant borrow (#61789)

### Objective

PR #58902 made native macOS window chrome follow the selected theme, but
AppKit can synchronously invoke `viewDidChangeEffectiveAppearance` while
the settings observer holds an `App` borrow. `handle.update` then fails
with `RefCell already borrowed`, leaving `Window::appearance()` and its
observers stale.

### Steps to reproduce

1. Set Zed's theme mode to Dark.
2. Set macOS Appearance to Light.
3. Change Zed's theme mode to System.
4. Notice that the window chrome switches to light, but Zed's UI remains
dark.


https://github.com/user-attachments/assets/f91962cc-76ba-4d8e-b587-2a2343f365ba

### Expectation

Zed should switch to its configured light theme when returning to System
mode.

### Solution

Defer `Window::appearance_changed` to the foreground executor so the
current `App` borrow finishes before refreshing the cached appearance
and notifying observers.

### Testing

- Added a regression test.

### Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- N/A
```

## Parents

- [dc1e815e47835095748cbb036541992abd9ac826](https://git.cafe/gitcafe/zed/commit/dc1e815e47835095748cbb036541992abd9ac826?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/a11083f9a79495e9c7ddee0c5782f22d07695c31?format=markdown)
