---
title: "Comment by Tarun Sharma on \"Dark Mode Without the Flash: One localStorage Key, One Inline Script, and a Custom DOM Event\" | Hashnode"
description: "One gap in the setup: the theme is only applied at load and on your own toggle, so with two tabs open a change in tab A leaves tab B on the old theme. A window"
url: "https://hashnode.com/posts/dark-mode-without-the-flash-one-localstorage-key-one-inline-script-and-a-custom-dom-event/6afbf38c1f0840881b5ab487/comment/6afdf0ab38cef92418f64067"
---

[Discussion](https://hashnode.com/posts/dark-mode-without-the-flash-one-localstorage-key-one-inline-script-and-a-custom-dom-event/6afbf38c1f0840881b5ab487)

Comment [Dark Mode Without the Flash: One localStorage Key, One Inline Script, and a Custom DOM Event](https://hashnode.com/posts/dark-mode-without-the-flash-one-localstorage-key-one-inline-script-and-a-custom-dom-event/6afbf38c1f0840881b5ab487)

[Tarun Sharma](https://hashnode.com/@101beardo)

[4d ago](https://hashnode.com/posts/dark-mode-without-the-flash-one-localstorage-key-one-inline-script-and-a-custom-dom-event/6afbf38c1f0840881b5ab487/comment/6afdf0ab38cef92418f64067)

One gap in the setup: the theme is only applied at load and on your own toggle, so with two tabs open a change in tab A leaves tab B on the old theme. A window "storage" listener that calls initTheme when the key changes fixes that for free, since the event only fires in the other tabs. Also useIsDark could use useSyncExternalStore with that same event, which removes the useEffect.
