Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Glitch theme applies on launch #4168

Merged
merged 2 commits into from
Dec 2, 2024
Merged

Conversation

louis-jan
Copy link
Contributor

@louis-jan louis-jan commented Nov 30, 2024

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:
CleanShot 2024-11-30 at 18 58 26

After:
CleanShot 2024-11-30 at 19 02 36

Notes:
Ordered list offscreen issue is filed in another issue

Changes made

This diff introduces several changes to the Setting.atom.ts and useLoadTheme.ts files, as follows:

Setting.atom.ts Changes:

  1. Atoms and Constants Updates:
    • New constants THEME_DATA, THEME_OPTIONS, and THEME_PATH are defined.
    • The themesOptionsAtom, janThemesPathAtom, and themeDataAtom are updated to use atomWithStorage, allowing them to persist in storage.
    • These atoms now have storage keys and enable the getOnInit option for initialization.

useLoadTheme.ts Changes:

  1. Atom Imports:

    • The import for useSetAtom from jotai is removed because it is no longer used.
  2. useLoadTheme Logic:

    • The hook useLoadTheme has been refactored to use useAtom for themeOptions and themePath instead of useSetAtom.
    • A new useCallback hook, applyTheme, is introduced to handle theme application logic. It first checks if themeData, themeOptions, or themePath is missing - if so, it calls getThemes. Otherwise, it applies CSS variables through a style tag in the document's head.
    • The useEffect now relies on applyTheme instead of directly calling getThemes.

These changes primarily focus on improving theme persistence and application by leveraging atomWithStorage in Recoil Jotai and optimizing the effect hooks.

@louis-jan louis-jan requested a review from a team November 30, 2024 12:07
@github-actions github-actions bot added the type: bug Something isn't working label Nov 30, 2024
Copy link
Contributor

Barecheck - Code coverage report

Total: 69.7%

Your code coverage diff: 0.16% ▴

Uncovered files and lines
FileLines
web/hooks/useLoadTheme.ts32-34, 91-95

@louis-jan louis-jan changed the title fix: Glitch theme applies on launch. fix: Glitch theme applies on launch Dec 1, 2024
@louis-jan louis-jan merged commit b335add into dev Dec 2, 2024
9 checks passed
@louis-jan louis-jan deleted the fix/glitch-theme-on-launch branch December 2, 2024 02:34
@github-actions github-actions bot added this to the v0.5.10 milestone Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants