Skip to content

Refactor Home theme initialization and persistence flow#8

Merged
TomChicken-on-github merged 1 commit into
mainfrom
codex/refactor-theme-initialization-in-home.vue
Feb 24, 2026
Merged

Refactor Home theme initialization and persistence flow#8
TomChicken-on-github merged 1 commit into
mainfrom
codex/refactor-theme-initialization-in-home.vue

Conversation

@TomChicken-on-github

Copy link
Copy Markdown
Collaborator

Motivation

  • Prevent the initial theme application from immediately overwriting a stored user preference and ensure the initial theme is applied synchronously for correct first-paint.
  • Keep requestIdleCallback only for non-critical writes to localStorage while avoiding it for the first read/application of theme to eliminate race conditions.
  • Make theme persistence explicit and guarded so toggling still persists and refresh restores the chosen theme.

Description

  • Added isThemeInitialized (ref) and a new synchronous initTheme() that reads localStorage.getItem('theme') first, falls back to matchMedia('(prefers-color-scheme: dark)'), sets theme.value, and toggles document.documentElement.classList in one place.
  • Reworked the watch(theme, ...) handler to remove immediate: true, normalize resolvedTheme, update the dark class immediately, and only persist to localStorage asynchronously when isThemeInitialized is true using requestIdleCallback (with a setTimeout fallback).
  • Call initTheme() from onMounted() and removed the previous requestIdleCallback-based initial read path so initial read/apply is synchronous while writes remain deferred.

Testing

  • Ran npm run build successfully and the build completed without blocking errors (warnings from tooling reported but did not affect the build outcome).

Codex Task

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Feb 24, 2026

Copy link
Copy Markdown

Deploying wsmcs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 12a74db
Status: ✅  Deploy successful!
Preview URL: https://238c546b.wsmcs.pages.dev
Branch Preview URL: https://codex-refactor-theme-initial.wsmcs.pages.dev

View logs

@vercel

vercel Bot commented Feb 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
wsmcs Ready Ready Preview, Comment Feb 24, 2026 0:13am

@netlify

netlify Bot commented Feb 24, 2026

Copy link
Copy Markdown

Deploy Preview for wsmcs ready!

Name Link
🔨 Latest commit 12a74db
🔍 Latest deploy log https://app.netlify.com/projects/wsmcs/deploys/699d95d51d7f290008c261ff
😎 Deploy Preview https://deploy-preview-8--wsmcs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@TomChicken-on-github TomChicken-on-github merged commit f752142 into main Feb 24, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant