# perf: debounce Zustand store persistence and deduplicate legacy cleanup · gitcafe/t3code

[View on GitCafe](https://git.cafe/gitcafe/t3code/commit/7a377fc5e4d607a475a7d36957689562d5dcccb9)

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

Visibility: public

Requested revision: 7a377fc5e4d607a475a7d36957689562d5dcccb9

Requested commit: 7a377fc5e4d607a475a7d36957689562d5dcccb9

Commit: 7a377fc5e4d607a475a7d36957689562d5dcccb9

Tree: 8aa6767ba647bed6003162e2e8d4299df49ab80c

Author: Chukwudi Nwobodo

Committer: Julius Marminge

## Message

```
perf: debounce Zustand store persistence and deduplicate legacy cleanup

The useStore subscriber called persistState on every state mutation,
triggering JSON.stringify + localStorage.setItem synchronously. It also
ran 8 localStorage.removeItem calls for legacy keys on every fire.

Wrap the subscriber with a 500ms debounce so rapid state changes batch
into a single write. Move legacy key cleanup behind a one-time flag so
it runs only once per page load. Add a beforeunload handler to flush
the final state.

```

## Parents

- [90e0c2ab15e7034d8e6e0688b3996fd905c03017](https://git.cafe/gitcafe/t3code/commit/90e0c2ab15e7034d8e6e0688b3996fd905c03017?format=markdown)

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