Skip to content

fix(useColorModes): clean up the matchMedia listener#510

Merged
mrholek merged 1 commit into
mainfrom
fix/color-modes-matchmedia-leak
Jul 17, 2026
Merged

fix(useColorModes): clean up the matchMedia listener#510
mrholek merged 1 commit into
mainfrom
fix/color-modes-matchmedia-leak

Conversation

@mrholek

@mrholek mrholek commented Jul 17, 2026

Copy link
Copy Markdown
Member

Fixes a listener leak from the July 2026 security/quality audit (P2).

The prefers-color-scheme matchMedia change listener was added inside a useEffect with no dependency array and no cleanup — so a new listener was registered on every render and none were ever removed. Extract the handler, return a cleanup that removes it, and scope the effect to [colorMode, localStorageItemName]. Regression tests: the listener is removed on unmount, and re-renders don't stack new listeners.

Local validation (GitHub CI unavailable — billing): lint 0 errors, lib:build clean, lib:test green (ran via the pre-push gate).

The prefers-color-scheme change listener was added inside a useEffect with
no dependency array and no cleanup, so a new listener was registered on
every render and none were ever removed (a leak). Extract the handler,
return a cleanup that removes it, and scope the effect to
[colorMode, localStorageItemName].
@mrholek
mrholek merged commit ac83980 into main Jul 17, 2026
3 checks passed
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.

1 participant