Skip to content

fix(theme-provider): callback deps, inline script, and onThemeChange#760

Draft
paanSinghCoder wants to merge 1 commit intomainfrom
fix/theme-provider-callbacks-and-script
Draft

fix(theme-provider): callback deps, inline script, and onThemeChange#760
paanSinghCoder wants to merge 1 commit intomainfrom
fix/theme-provider-callbacks-and-script

Conversation

@paanSinghCoder
Copy link
Copy Markdown
Contributor

@paanSinghCoder paanSinghCoder commented Apr 29, 2026

Description

Addresses items 2, 3, and 5 from #646.

  • Callback depssetTheme now tracks storageKey (was forcedTheme, unused). handleMediaQuery now includes enableSystem and applyTheme. Both fix latent stale-closure bugs that surface only when those props change at runtime.
  • Inline-script fixupdateDOM no longer emits c.add(x[e]|| ''). The literal path is gated with if(${val}) so a missing value-map entry doesn't reach classList.add('') (throws) or setAttribute(n, '') (junk attr).
  • onThemeChange callback — fires on actual theme/resolvedTheme changes, skips initial mount. Held via ref so consumer render churn doesn't over-fire and the callback never goes stale.

Type of Change

  • Bug fix
  • New feature
  • Improvement

How Has This Been Tested?

Manual repro on main vs branch for each fix. Tests TODO — leaving as draft until theme-provider.test.tsx is extended.

Related Issues

Refs #646 (items 2, 3, 5).

🤖 Generated with Claude Code

…646)

- Correct setTheme deps to track storageKey instead of unused forcedTheme.
- Add missing enableSystem and applyTheme to handleMediaQuery deps.
- Fix inline-script generation in updateDOM: drop the `name + "|| ''"` concat
  that produced classList.add('') (throws) or setAttribute(n, '') (junk
  attribute) when a value-map lookup missed; guard the literal path with
  if(${val}) so the DOM call only runs when the lookup is truthy.
- Add onThemeChange prop. Fires on actual theme/resolvedTheme changes,
  skipping the initial mount. Uses a ref so the callback identity is read
  at fire time, decoupling effect cadence from consumer render churn.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 29, 2026

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

Project Deployment Actions Updated (UTC)
apsara Ready Ready Preview, Comment Apr 29, 2026 3:54am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 01d7b0ae-9e3e-4f8e-997b-a6d4cd9b748d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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 and usage tips.

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