fix: Glitch theme applies on launch #4168
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe Your Changes
There’s an issue with an app where when the user launches the app with the first thread is a large one, it glitches the app’s theme a bit before the conversation is loaded. This results in a very ugly display, with only a border and a translucent background.
This fix intends to store the previously set settings in the localStorage., ensuring that themes are applied effectively without the need to load JSON files from the disk.
Before:
After:
Notes:
Ordered list offscreen issue is filed in another issue
Changes made
This diff introduces several changes to the
Setting.atom.ts
anduseLoadTheme.ts
files, as follows:Setting.atom.ts
Changes:THEME_DATA
,THEME_OPTIONS
, andTHEME_PATH
are defined.themesOptionsAtom
,janThemesPathAtom
, andthemeDataAtom
are updated to useatomWithStorage
, allowing them to persist in storage.getOnInit
option for initialization.useLoadTheme.ts
Changes:Atom Imports:
useSetAtom
fromjotai
is removed because it is no longer used.useLoadTheme Logic:
useLoadTheme
has been refactored to useuseAtom
forthemeOptions
andthemePath
instead ofuseSetAtom
.useCallback
hook,applyTheme
, is introduced to handle theme application logic. It first checks ifthemeData
,themeOptions
, orthemePath
is missing - if so, it callsgetThemes
. Otherwise, it applies CSS variables through a style tag in the document's head.useEffect
now relies onapplyTheme
instead of directly callinggetThemes
.These changes primarily focus on improving theme persistence and application by leveraging
atomWithStorage
in Recoil Jotai and optimizing the effect hooks.