From 3a15b920a7fa0ce739bc6c88e035fb6a7279510e Mon Sep 17 00:00:00 2001 From: Jonghyeon Ko Date: Mon, 23 Nov 2026 00:14:13 +0900 Subject: [PATCH 1/2] Replace Sonner with Base UI Toast --- package.json | 1 - pnpm-lock.yaml | 14 ---- src/components/ToastProvider.module.css | 89 +++++++++++++++++++++++++ src/components/ToastProvider.tsx | 74 +++++++++++--------- 4 files changed, 130 insertions(+), 48 deletions(-) create mode 100644 src/components/ToastProvider.module.css diff --git a/package.json b/package.json index 9252a7fbb..f1c7f6262 100644 --- a/package.json +++ b/package.json @@ -175,7 +175,6 @@ "react-instantsearch": "^7.29.0", "remove-markdown": "^0.6.3", "resend": "^6.10.0", - "sonner": "^2.0.7", "tailwind-merge": "^3.5.0", "takumi-js": "^2.5.4", "tar-stream": "^3.1.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 40d153600..7140d62b9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -363,9 +363,6 @@ importers: resend: specifier: ^6.10.0 version: 6.10.0 - sonner: - specifier: ^2.0.7 - version: 2.0.7(react-dom@19.2.3(react@19.2.3))(react@19.2.3) tailwind-merge: specifier: ^3.5.0 version: 3.5.0 @@ -7734,12 +7731,6 @@ packages: solid-js@1.9.12: resolution: {integrity: sha512-QzKaSJq2/iDrWR1As6MHZQ8fQkdOBf8GReYb7L5iKwMGceg7HxDcaOHk0at66tNgn9U2U7dXo8ZZpLIAmGMzgw==} - sonner@2.0.7: - resolution: {integrity: sha512-W6ZN4p58k8aDKA4XPcx2hpIQXBRAgyiWVkYhT7CvK6D3iAu7xjvVyhQHg2/iaKJZ1XVJ4r7XuwGL+WGEK37i9w==} - peerDependencies: - react: ^18.0.0 || ^19.0.0 || ^19.0.0-rc - react-dom: ^18.0.0 || ^19.0.0 || ^19.0.0-rc - sorted-btree@1.8.1: resolution: {integrity: sha512-395+XIP+wqNn3USkFSrNz7G3Ss/MXlZEqesxvzCRFwL14h6e8LukDHdLBePn5pwbm5OQ9vGu8mDyz2lLDIqamQ==} @@ -15976,11 +15967,6 @@ snapshots: seroval: 1.5.4 seroval-plugins: 1.5.4(seroval@1.5.4) - sonner@2.0.7(react-dom@19.2.3(react@19.2.3))(react@19.2.3): - dependencies: - react: 19.2.3 - react-dom: 19.2.3(react@19.2.3) - sorted-btree@1.8.1: {} source-map-explorer@2.5.3: diff --git a/src/components/ToastProvider.module.css b/src/components/ToastProvider.module.css new file mode 100644 index 000000000..283c54cd5 --- /dev/null +++ b/src/components/ToastProvider.module.css @@ -0,0 +1,89 @@ +.viewport { + --toast-gap: 8px; + position: fixed; + right: 1rem; + bottom: 1rem; + z-index: 10000; + width: 24rem; + height: var(--toast-frontmost-height, 0px); + pointer-events: none; + outline: none; +} + +.toast { + --toast-y: calc(-1 * var(--toast-index) * var(--toast-gap)); + --toast-scale: calc(1 - 0.05 * var(--toast-index)); + position: absolute; + bottom: 0; + z-index: calc(3 - var(--toast-index)); + width: 100%; + height: var(--toast-frontmost-height, auto); + overflow-wrap: anywhere; + pointer-events: auto; + touch-action: pan-y; + transform: translateY(var(--toast-y)) scale(var(--toast-scale)); + transform-origin: bottom center; + transition: + transform 250ms, + opacity 250ms, + height 250ms; +} + +.toast[data-expanded] { + --toast-y: calc( + -1 * (var(--toast-offset-y) + var(--toast-index) * var(--toast-gap)) + ); + --toast-scale: 1; + height: var(--toast-height, auto); +} + +/* Keep hover active as the pointer crosses the gap between expanded toasts. */ +.toast[data-expanded]::after { + position: absolute; + right: 0; + bottom: calc(-1 * var(--toast-gap) - 1px); + left: 0; + height: calc(var(--toast-gap) + 1px); + content: ''; +} + +.toast[data-swiping] { + transition: none; +} + +.toast[data-starting-style], +.toast[data-ending-style] { + opacity: 0; + transform: translateY(calc(var(--toast-y) + 100%)) scale(var(--toast-scale)); +} + +.toast[data-ending-style][data-swipe-direction='right'] { + transform: translate( + calc(var(--toast-swipe-movement-x) + 100%), + var(--toast-y) + ); +} + +.toast[data-limited] { + visibility: hidden; +} + +.toast[data-ending-style] { + pointer-events: none; +} + +.content[data-behind]:not([data-expanded]) { + opacity: 0; +} + +@media (max-width: 600px) { + .viewport { + width: calc(100% - 2rem); + } +} + +@media (prefers-reduced-motion: reduce) { + .toast { + transition: none; + } +} diff --git a/src/components/ToastProvider.tsx b/src/components/ToastProvider.tsx index 927627c28..9c40c206f 100644 --- a/src/components/ToastProvider.tsx +++ b/src/components/ToastProvider.tsx @@ -1,6 +1,6 @@ +import { Toast } from '@base-ui/react/toast' import * as React from 'react' -import { Toaster, toast } from 'sonner' -import { useTheme } from '~/components/ThemeProvider' +import styles from './ToastProvider.module.css' type ToastOptions = { durationMs?: number @@ -11,6 +11,10 @@ type ToastContextValue = { notify: (content: React.ReactNode, options?: ToastOptions) => string } +type ToastProviderProps = { + children: React.ReactNode +} + const ToastContext = React.createContext(null) export function useToast(): ToastContextValue { @@ -21,47 +25,51 @@ export function useToast(): ToastContextValue { return ctx } -export function ToastProvider({ - children, -}: { - children: React.ReactNode -}): React.ReactElement { - const { resolvedTheme } = useTheme() +export function ToastProvider({ children }: ToastProviderProps) { + return ( + + {children} + + ) +} + +function ToastNotifications({ children }: ToastProviderProps) { + const { add, toasts } = Toast.useToastManager() const notify = React.useCallback( - (content: React.ReactNode, options?: ToastOptions) => { - const id = toast(content, { - duration: options?.durationMs ?? 2500, - id: options?.id, + (content: React.ReactNode, { durationMs, id }: ToastOptions = {}) => { + const hasId = id !== undefined && id !== '' + const toastId = add({ + title: content, + timeout: durationMs === Infinity ? 0 : durationMs, + id: hasId ? `${typeof id}:${id}` : undefined, }) - return String(id) + return hasId ? String(id) : toastId }, - [], + [add], ) - const contextValue = React.useMemo( - () => ({ notify }), - [notify], - ) + const contextValue = React.useMemo(() => ({ notify }), [notify]) return ( {children} - + + + {toasts.map((toast) => ( + + + + + + ))} + + ) } From e46c615f276ffb0d118e80040bf587189ba6ed81 Mon Sep 17 00:00:00 2001 From: Jonghyeon Ko Date: Mon, 23 Nov 2026 00:46:51 +0900 Subject: [PATCH 2/2] Simplify toast ID handling and fix ID reuse --- src/components/ToastProvider.tsx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/components/ToastProvider.tsx b/src/components/ToastProvider.tsx index 9c40c206f..3e5af8d0a 100644 --- a/src/components/ToastProvider.tsx +++ b/src/components/ToastProvider.tsx @@ -37,15 +37,12 @@ function ToastNotifications({ children }: ToastProviderProps) { const { add, toasts } = Toast.useToastManager() const notify = React.useCallback( - (content: React.ReactNode, { durationMs, id }: ToastOptions = {}) => { - const hasId = id !== undefined && id !== '' - const toastId = add({ + (content: React.ReactNode, { durationMs, id }: ToastOptions = {}) => + add({ title: content, timeout: durationMs === Infinity ? 0 : durationMs, - id: hasId ? `${typeof id}:${id}` : undefined, - }) - return hasId ? String(id) : toastId - }, + id: id?.toString(), + }), [add], )