Skip to content

fix(#1502): add theme prop to sonner#1694

Open
vachanmn123 wants to merge 3 commits intounovue:devfrom
vachanmn123:dev
Open

fix(#1502): add theme prop to sonner#1694
vachanmn123 wants to merge 3 commits intounovue:devfrom
vachanmn123:dev

Conversation

@vachanmn123
Copy link

@vachanmn123 vachanmn123 commented Feb 19, 2026

🔗 Linked issue

Fixes #1502

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

I have added a theme prop to the Sonner component to allow it to work better with dark themes. Resolves #1502

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly. (N/A)

Summary by CodeRabbit

  • New Features
    • Sonner toaster now follows the app's color mode (uses system when set to auto), improving theme consistency across the UI.

@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Adds automatic color-mode detection to the Sonner toaster by using the useColorMode() hook, computing a theme value (maps auto to system), and passing that theme into the Sonner/Toaster component; also reformats icon imports.

Changes

Cohort / File(s) Summary
Sonner Color Mode Support
apps/v4/registry/new-york-v4/ui/sonner/Sonner.vue
Introduces useColorMode() and a computed theme (maps autosystem); binds :theme="theme" to the Sonner/Toaster component. Adjusts lucide-vue-next and computed import formatting. No public API changes.

Sequence Diagram(s)

sequenceDiagram
    participant Component as Sonner.vue
    participant Hook as useColorMode()
    participant Toaster as Sonner/Toaster

    Component->>Hook: call useColorMode()
    Hook-->>Component: returns colorMode (e.g., "auto", "dark", "light")
    Component->>Component: compute theme = colorMode === "auto" ? "system" : colorMode
    Component->>Toaster: render with prop theme=<computed theme>
    Toaster-->>Component: display toasts with selected theme
Loading

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 A rabbit's ode to adaptive hues:
Soft hops through light and shadow play,
Sonner learns whether night or day.
Themes now follow system tone,
No more toggles to set alone—
Hooray for colors that just flow! 🎨✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: adding theme prop support to the Sonner component to resolve issue #1502.
Linked Issues check ✅ Passed The PR implements automatic theme detection via useColorMode() hook, allowing Sonner to adapt to the app's theme without manual configuration, directly addressing issue #1502's requirement.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing theme support for Sonner; only import formatting adjustment is present, which is necessary for code organization.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@vachanmn123 vachanmn123 changed the title fix(#1502): add prop to sonner fix(#1502): add theme prop to sonner Feb 19, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/v4/registry/new-york-v4/ui/sonner/Sonner.vue`:
- Around line 30-31: The current template spreads v-bind="props" then
unconditionally sets :theme="theme", which in Vue 3 causes the computed theme to
always override any consumer-supplied props.theme; update the binding so the
component uses the consumer-provided theme when present by changing the
computed/prop usage to use props.theme ?? <computed fallback> (or adjust the
computedTheme getter) and then bind :theme to that result (or replace
:theme="theme" with :theme="props.theme ?? themeFallback"); target the
v-bind="props" usage and the computed/theme variable in Sonner.vue and ensure
ToasterProps.theme is respected.
- Around line 3-11: The file calls useColorMode but doesn't import it; add
useColorMode to the import list from its source (e.g., import { useColorMode }
from "@vueuse/core" or from your project's composables) so the reference inside
Sonner.vue (where useColorMode() is invoked) resolves at runtime; update the
existing import block that currently imports computed to include the correct
useColorMode import instead of leaving it undefined.

Comment on lines +3 to +11
import {
CircleCheckIcon,
InfoIcon,
Loader2Icon,
OctagonXIcon,
TriangleAlertIcon,
XIcon,
} from "lucide-vue-next"
import { computed } from "vue"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

useColorMode is missing from the imports.

useColorMode is called on line 17 but is not imported anywhere in this file. This will throw a ReferenceError at runtime in any project that doesn't have @vueuse/core composables auto-imported.

🔧 Proposed fix
 import { computed } from "vue"
+import { useColorMode } from "@vueuse/core"
 import { Toaster as Sonner } from "vue-sonner"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/v4/registry/new-york-v4/ui/sonner/Sonner.vue` around lines 3 - 11, The
file calls useColorMode but doesn't import it; add useColorMode to the import
list from its source (e.g., import { useColorMode } from "@vueuse/core" or from
your project's composables) so the reference inside Sonner.vue (where
useColorMode() is invoked) resolves at runtime; update the existing import block
that currently imports computed to include the correct useColorMode import
instead of leaving it undefined.

@vachanmn123
Copy link
Author

This is my first OSS contribution, sorry if this might sound stupid but are we supposed to import from @vueuse/core? Since I checked the Button implementation and it does in fact use the same function but without an import.

@benkroeger
Copy link
Contributor

I don't think this should be part of the shadcn library.
In our codebase we manage the user's theme preference in a different store (actually persisted to server via api) and pass that to useColorMode as custom store ref.
If this PR got merged, it would always fallback to vueuse's default store for overrides (i.e., LocalStorage) and thus make the Sonner styling be out-of-sync with the rest of our application.

I think it is best to resolve / manage the color mode outside of this component and simply pass it as theme prop.

@benkroeger
Copy link
Contributor

Since I checked the Button implementation and it does in fact use the same function but without an import.

where did you find that? I searched the code base and found useColorMode only in apps/v4 - which is the docs page (not the actual components code)

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.

[Feature]: Support for theme and Sonner's richColors

3 participants