fix: prevent theme switcher from overwriting saved theme on mount#50
Conversation
|
@voqthekid is attempting to deploy a commit to the 0xBuns Team on Vercel. A member of the Team first needs to authorize it. |
Wait for component to mount before attempting to write the current theme state to localStorage. This prevents the initial 'dracula' state from clobbering the user's saved preference before the initial read effect can update the state.
a615bba to
8ebfbab
Compare
|
Maintainer triage: keeping this open as one of the highest-value bugfixes in the queue. The change is narrowly scoped, addresses a real mount-time theme persistence bug, and does not overlap with the feature backlog. Once the branch is current with main, this is a strong candidate for merge ahead of most component-addition PRs. |
|
Maintainer note: repo-owned Actions are now enabled and branch protection is live, but this PR still needs a fresh branch update from current |
BunsDev
left a comment
There was a problem hiding this comment.
Reviewed after branch refresh. The fix is narrowly scoped, the repo-owned checks now pass, and this remains a strong early merge candidate.
What does this PR do?
Fixes a bug where
ThemeSwitcheroverwrites the user's savedlocalStoragetheme with the default'dracula'theme on the initial render.Problem
Previously, the second
useEffectinThemeSwitcherran immediately on mount, writing the initial component state ('dracula') tolocalStoragebefore the firstuseEffecthad a chance to apply the saved theme. This caused a flash of unstyled content and overwrote user preferences if the state didn't update fast enough or if multiple storage events fired.Solution
mountedstate to defer thelocalStoragewrite until the component is fully mounted.Type of Change
Checklist