Skip to content

SWF(refactor): テーマ切り替えの light/dark 分岐を THEMES でまとめる - #821

Open
suree33 wants to merge 1 commit into
mainfrom
devin/1795146116-theme-toggle-consolidate
Open

suree33 wants to merge 1 commit into
mainfrom
devin/1795146116-theme-toggle-consolidate

Conversation

@suree33

@suree33 suree33 commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

テーマ切り替えのクライアント側スクリプトで、light と dark を別々に書いていた分岐を THEMES を使う形にまとめました。動作は変えていません。

Summary

src/components/ThemeToggle.astro の applyTheme() と getCurrentTheme() は、'dark' と 'light' のそれぞれに同じ処理を書いていました。src/types/Theme.ts の THEMES を使い、1つの流れにまとめています。

// before: dark / light / null の3つの分岐がほぼ同じ処理を持つ
// after
html.classList.remove(...THEMES);
if (theme !== null) html.classList.add(theme);
html.style.colorScheme = theme ?? 'light dark';
storeTheme(theme);

const getCurrentTheme = () =>
  THEMES.find((theme) => html.classList.contains(theme)) ?? null;
  • isTheme() も THEMES.some(...) で判定するようにし、テーマの一覧を THEMES だけに置きました。
  • classList.remove() に渡していた 'theme-system' を外しました。このクラスを付けるコードは feat: テーマ切り替え追加 #447 からリポジトリのどこにもありません(git grep theme-system が0件)。
  • FOUC 対策の BaseLayout.astro のインラインスクリプトは変えていません。
  • tests/unit/theme.test.ts を足し、isTheme() が light と dark だけを受け付けることを確かめます。変更前の Theme.ts でも変更後でも 7 件すべて通ります。

動作の確認

テーマ切り替えの E2E(6 プロジェクトすべて)

pnpm exec playwright test tests/e2e/specs/theme.spec.ts

  ✓  30 [Mobile Safari (Small screen)] › theme.spec.ts:242:3 › light OS で無効な保存テーマはシステム設定にフォールバックする (942ms)
  ✓  27 [Mobile Safari (Small screen)] › theme.spec.ts:89:3 › テーマトグル › ダーク → ライト → システムを循環し、リロード後も永続化する (2.8s)
  ✓  28 [Mobile Safari (Small screen)] › theme.spec.ts:184:3 › ダーク OS のテーマトグル › ライト → ダーク → システムを循環し、リロード後も永続化する (2.8s)

  30 passed (21.0s)

chromium、firefox、webkit、Mobile Chrome、Mobile Safari、Mobile Safari (Small screen) で、ライト OS とダーク OS の循環、リロード後の復元、localStorage が使えない場合、無効な保存値のフォールバックを確かめています。

chromium の E2E 全体

pnpm exec playwright test --project=chromium → 70 passed, 2 skipped(コンポーネントの見た目のスナップショットを含む)

ビルド結果の比較

main とこのブランチをそれぞれ pnpm run build:e2e でビルドし、dist/ の HTML 48 ファイルを比べました。差分が出たのはヘッダーを持つ 46 ファイルで、どれもテーマ切り替えの <script type="module"> 1 行だけでした。それ以外の行はすべて同じです。

-a=e=>{t.classList.remove(`dark`,`light`,`theme-system`),e===`dark`?(t.classList.add(`dark`),t.style.colorScheme=`dark`,r(`dark`)):e===`light`?(t.classList.add(`light`),t.style.colorScheme=`light`,r(`light`)):(t.style.colorScheme=`light dark`,r(null))},o=()=>t.classList.contains(`dark`)?`dark`:t.classList.contains(`light`)?`light`:null;
+o=t=>{n.classList.remove(...e),t!==null&&n.classList.add(t),n.style.colorScheme=t??`light dark`,i(t)},s=()=>e.find(e=>n.classList.contains(e))??null;

pnpm run lint と pnpm run test:unit も通ります。

試し方

pnpm run build:e2e && pnpm exec playwright test tests/e2e/specs/theme.spec.ts

確かめていないこと

  • 実機のブラウザでの手動操作はしていません(Playwright の 6 プロジェクトで確認)。

Software Factory opened this PR for Daiki
Implemented in session Consolidate theme toggle light/dark branches
Review with Devin · Open in Devin Desktop


@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 57 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e343c640-8598-4c97-a90a-c0f6aac61de7
Commits

Reviewing files that changed from the base of the PR and between e693614 and 5745b25.

Files selected for processing: 3

  • src/components/ThemeToggle.astro
  • src/types/Theme.ts
  • tests/unit/theme.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
blog 5745b25 Commit Preview URL

Branch Preview URL
Nov 20 2026, 03:52 AM

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant