Skip to content

fix: normalize the landing-draft theme-toggle's persisted localStorage value - #511

Merged
jackgranatowski merged 1 commit into
mainfrom
claude/landing-theme-toggle-localstorage-guard
Jul 3, 2026
Merged

fix: normalize the landing-draft theme-toggle's persisted localStorage value#511
jackgranatowski merged 1 commit into
mainfrom
claude/landing-theme-toggle-localstorage-guard

Conversation

@jackgranatowski

Copy link
Copy Markdown
Contributor

Summary

Replaces #504, which described a full landing-page redesign but whose actual diff against main was just this one fix — every other feature it described (hero animation, CDN load, token demos, dark install band, Jekyll exclusion) was already merged into main via earlier commits shared by both branches, so closing or merging #504 wouldn't have changed anything else in copy-wip/github-pages-index.html. Opening this standalone PR with just the actual remaining change, and closing #504.

Fix

current = localStorage.getItem('slashed-home-theme') || 'auto'; accepted any truthy stored string unconditionally. If the value ever isn't one of the three known states (auto/dark/light) — e.g. a stale value from a future rename of the states array, or manual tampering via devtools — apply(current) would set an unmatched data-theme attribute (silently falls back to OS-preference styling) and stamp the toggle button's label with that raw string.

Now only accepts the stored value if it's one of the known states, otherwise keeps the 'auto' default.

-      try { current = localStorage.getItem('slashed-home-theme') || 'auto'; } catch (e) {}
+      try {
+        var stored = localStorage.getItem('slashed-home-theme');
+        if (states.indexOf(stored) !== -1) current = stored;
+      } catch (e) {}

🤖 Generated with Claude Code


Generated by Claude Code

Only accept a stored slashed-home-theme value if it's one of the known
states (auto/dark/light). Guards against a stale or tampered value
driving an invalid data-theme attribute and a garbage toggle-button
label.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016rBJXkhpA2ZvDxsoRWFZGG
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@jackgranatowski, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 32 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4e235d46-fade-46f1-a482-159bd47f2b20

📥 Commits

Reviewing files that changed from the base of the PR and between a3f0bb9 and 1f7d849.

📒 Files selected for processing (1)
  • copy-wip/github-pages-index.html
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/landing-theme-toggle-localstorage-guard

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

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Fix theme toggle: validate persisted localStorage value before applying

🐞 Bug fix 🕐 Less than 5 minutes

Grey Divider

AI Description

• Validate the persisted theme value before using it to set the page theme.
• Default to "auto" when localStorage contains an unknown/tampered value.
• Prevent invalid data-theme attributes and incorrect toggle labeling.
Diagram

graph TD
  A["Landing page script"] --> B[("localStorage")] --> C{"Stored value valid?"}
  C -->|"yes"| D["Use stored state"] --> F["apply(current)"] --> G["<html> data-theme"]
  C -->|"no"| E["Keep default: auto"] --> F
  subgraph Legend
    direction LR
    _proc["Process"] ~~~ _db[("Storage")] ~~~ _dec{"Decision"}
  end
Loading
High-Level Assessment

This is the right fix for the failure mode: explicitly whitelist known theme states before applying. Alternatives like storing a versioned schema, JSON encoding, or using a mapping object add complexity without materially improving robustness for a three-state toggle.

Files changed (1) +4 / -1

Bug fix (1) +4 / -1
github-pages-index.htmlWhitelist persisted theme value before applying it +4/-1

Whitelist persisted theme value before applying it

• Updates theme initialization to read the stored theme into a temporary variable and only accept it if it matches one of the known states (auto/dark/light). Prevents invalid/tampered localStorage values from producing an unmatched data-theme attribute and incorrect toggle label text.

copy-wip/github-pages-index.html

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Qodo Logo

@jackgranatowski
jackgranatowski merged commit 297538d into main Jul 3, 2026
13 checks passed
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.

2 participants