From a6caa88d9c5286e17a696fa0c4240af1b7a8b488 Mon Sep 17 00:00:00 2001 From: poli0981 <127664709+poli0981@users.noreply.github.com> Date: Thu, 14 May 2026 14:01:10 +0700 Subject: [PATCH] =?UTF-8?q?fix(toast):=20close=20button=20now=20dismisses?= =?UTF-8?q?=20on=20click=20=E2=80=94=20upgrade=20sonner=20v1.7=20to=20v2?= =?UTF-8?q?=20(#52)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit User report: the toast close button (×) was visible on both desktop and mobile, but clicking/tapping it didn't dismiss the toast. Reading sonner v1.7.4's bundled source, the toast root attaches an `onPointerDown` that calls `r.target.setPointerCapture(r.pointerId)` unconditionally whenever the toast is dismissible. Combined with React 19's new event delegation (root-attached listeners instead of document-wide), this pointer capture quirk swallows the synthetic click event on the close button — so the bundled handler that calls `dismiss()` never runs. The bug fires on both mouse and touch because the PointerEvent capture is API-unified. Upgrade sonner from ^1.7.0 to ^2.0.7. Sonner v2 rewrote the pointer/swipe handling and ships first-class React 19 support; the close-button click now fires reliably on both desktop and mobile. The seven `toast.success/warning/ error/info` usage sites and the `` props (`position`, `theme`, `richColors`, `closeButton`, `toastOptions.classNames`) are API-compatible between v1 and v2 — typecheck and the 193 unit tests pass without changes. Bonus: add a `::after` hit-area expansion on `[data-close-button]` (visible size stays at sonner's 20px default; effective tap target ~36–40px) plus `touch-action: manipulation` to eliminate the 300ms tap delay on touch devices. Defensive — sonner v2 already fixes the underlying click issue, but the larger hit target is a free mobile UX win. Also adds: - `docs/tested-viewports.md` — the manual device test matrix the maintainer has been verifying against (BlackBerry Z30 / Galaxy S9+ / Pixel 3/4/7 / iPhone SE/12/14 Pro/XR/Pro Max / iPad / BlackBerry PlayBook). Documents the Nokia Lumia 520 (320x533) as a known limitation below the recommended minimum 360x640. - README EN + VI link to the new doc. - THIRD-PARTY.md bumps sonner version 1.7 to 2.0.7. Co-authored-by: Claude Opus 4.7 (1M context) --- README.md | 2 +- README.vi.md | 2 +- THIRD-PARTY.md | 2 +- docs/tested-viewports.md | 54 ++++++++++++++++++++++++++++++++++++++++ package-lock.json | 8 +++--- package.json | 2 +- src/styles/globals.css | 12 +++++++++ 7 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 docs/tested-viewports.md diff --git a/README.md b/README.md index fa9f8cb..1189a7d 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ JSONPrism is a refracting tool for developers. It takes a single JSON input and - **Smart shape detection** — recognizes flat objects, arrays of objects, scalars; suggests the best target format. - **Per-format options** — pretty-print, indentation, dialect (for SQL), alignment (for Markdown), and more. - **Dark + light themes** — Prism Spectrum palette with violet / cyan / amber / rose accents. -- **Responsive — designed for viewports ≥ 360 × 640.** Smaller screens still work but may feel cramped; on mobile, Input and Output use a Tabs UI to give each panel full height. +- **Responsive — designed for viewports ≥ 360 × 640.** Smaller screens still work but may feel cramped; on mobile, Input and Output use a Tabs UI to give each panel full height. See [`docs/tested-viewports.md`](docs/tested-viewports.md) for the full device test matrix. - **EN + VI** — bilingual interface out of the box. More languages welcome. - **Tauri desktop build** — drag-and-drop file workflow, offline-first (Phase 2 milestone). diff --git a/README.vi.md b/README.vi.md index b18338d..3439aec 100644 --- a/README.vi.md +++ b/README.vi.md @@ -42,7 +42,7 @@ JSONPrism là công cụ "tán sắc" cho developer. Nhận một JSON đầu v - **Phát hiện shape thông minh** — nhận diện flat object, mảng object, scalar; gợi ý format đích phù hợp. - **Tuỳ chọn theo từng format** — pretty-print, indentation, dialect (SQL), alignment (Markdown), v.v. - **Theme sáng/tối** — bảng màu Prism Spectrum với violet / cyan / amber / rose. -- **Responsive — tối ưu cho viewport ≥ 360 × 640.** Màn hình nhỏ hơn vẫn dùng được nhưng có thể chật; trên mobile, Input và Output dùng Tabs UI để mỗi panel có toàn bộ chiều cao. +- **Responsive — tối ưu cho viewport ≥ 360 × 640.** Màn hình nhỏ hơn vẫn dùng được nhưng có thể chật; trên mobile, Input và Output dùng Tabs UI để mỗi panel có toàn bộ chiều cao. Xem [`docs/tested-viewports.md`](docs/tested-viewports.md) cho ma trận thiết bị đã kiểm thử. - **Đa ngôn ngữ EN + VI** — sẵn sàng từ ngày đầu. Hoan nghênh thêm ngôn ngữ khác. - **Bản desktop Tauri** — drag-and-drop file, hoạt động offline (mốc Phase 2). diff --git a/THIRD-PARTY.md b/THIRD-PARTY.md index dc4dd08..81c6433 100644 --- a/THIRD-PARTY.md +++ b/THIRD-PARTY.md @@ -31,7 +31,7 @@ the relevant notices. This file is a starting point. | `@radix-ui/react-switch` | ^1.1.0 | MIT | [radix-ui.com](https://www.radix-ui.com/) | | `@radix-ui/react-tabs` | ^1.1.0 | MIT | [radix-ui.com](https://www.radix-ui.com/) | | `lucide-react` | ^0.460.0 | ISC | [lucide.dev](https://lucide.dev/) | -| `sonner` | ^1.7.0 | MIT | [sonner.emilkowal.ski](https://sonner.emilkowal.ski/) | +| `sonner` | ^2.0.7 | MIT | [sonner.emilkowal.ski](https://sonner.emilkowal.ski/) | | `react-dropzone` | ^14.3.0 | MIT | [react-dropzone.js.org](https://react-dropzone.js.org/) | The component patterns under `src/components/ui/` are generated from diff --git a/docs/tested-viewports.md b/docs/tested-viewports.md new file mode 100644 index 0000000..43399c5 --- /dev/null +++ b/docs/tested-viewports.md @@ -0,0 +1,54 @@ +# Tested viewports + +JSONPrism's mobile and tablet rendering is verified across the devices below. + +Status legend: + +- ✅ Works as expected +- ⚠️ Cramped but functional +- ❌ Known limitation (typically below recommended minimum) + +Recommended minimum viewport: **360 × 640**. Phones in landscape orientation are best-effort — see [recommendation](#recommendation). + +## Test results (last verified 2026-05-14) + +### Phones (portrait) + +| Device | Viewport | Status | Notes | +| ------------------------------------------------ | --------- | ------ | ------------------------------ | +| BlackBerry Z30 / Samsung Galaxy Note 3 / Nexus 5 | 360 × 640 | ✅ | Minimum recommended viewport | +| Samsung Galaxy S9+ | 320 × 658 | ✅ | Below recommended width, works | +| Pixel 4 | 353 × 745 | ✅ | | +| Pixel 3 | 393 × 786 | ✅ | | +| iPhone SE (2nd/3rd gen) | 375 × 667 | ✅ | | +| iPhone 12 Pro | 390 × 844 | ✅ | | +| iPhone 14 Pro | 393 × 852 | ✅ | Verified on real device | +| iPhone XR | 414 × 896 | ✅ | | +| Pixel 7 | 412 × 915 | ✅ | | +| iPhone 14 Pro Max | 420 × 932 | ✅ | | + +### Tablets + +| Device | Viewport | Status | Notes | +| ------------------- | ---------- | ------ | -------------------------------------------------- | +| BlackBerry PlayBook | 600 × 1024 | ✅ | | +| iPad | 768 × 1024 | ✅ | Side-by-side input/output kicks in at `md` (768px) | + +### Known limitations + +| Device | Viewport | Status | Notes | +| -------------- | --------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------ | +| Nokia Lumia 520 | 320 × 533 | ❌ | Code editor disappears — viewport is below the recommended minimum height (640). Worth revisiting in a future round if demand surfaces. | + +## Recommendation + +- **Portrait orientation only on phones.** Landscape on phones (height < width) compresses each tab's content area to ~150–200px after chrome and is best-effort. +- **Below recommended minimum (360 × 640)**: layout is functional but the code editor may collapse on very short heights (< 600px). + +## How to retest + +1. Open Chrome DevTools → "Toggle device toolbar" (Ctrl+Shift+M). +2. Pick a device from the dropdown or set a custom viewport. +3. Verify on the Home page: Header navigation visible, Input/Output Tabs accessible, FormatPicker trigger fits, no horizontal scroll on ``. + +Test results contributed by the maintainer. PRs welcome to expand the matrix. diff --git a/package-lock.json b/package-lock.json index 02fa7ce..a50b001 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,7 +48,7 @@ "react-i18next": "^15.0.0", "react-router-dom": "^7.0.0", "smol-toml": "^1.3.0", - "sonner": "^1.7.0", + "sonner": "^2.0.7", "tailwind-merge": "^2.5.0", "zustand": "^5.0.0" }, @@ -5603,9 +5603,9 @@ } }, "node_modules/sonner": { - "version": "1.7.4", - "resolved": "https://registry.npmjs.org/sonner/-/sonner-1.7.4.tgz", - "integrity": "sha512-DIS8z4PfJRbIyfVFDVnK9rO3eYDtse4Omcm6bt0oEr5/jtLgysmjuBl1frJ9E/EQZrFmKx2A8m/s5s9CRXIzhw==", + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/sonner/-/sonner-2.0.7.tgz", + "integrity": "sha512-W6ZN4p58k8aDKA4XPcx2hpIQXBRAgyiWVkYhT7CvK6D3iAu7xjvVyhQHg2/iaKJZ1XVJ4r7XuwGL+WGEK37i9w==", "license": "MIT", "peerDependencies": { "react": "^18.0.0 || ^19.0.0 || ^19.0.0-rc", diff --git a/package.json b/package.json index c7a5bc3..63f9e75 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "react-i18next": "^15.0.0", "react-router-dom": "^7.0.0", "smol-toml": "^1.3.0", - "sonner": "^1.7.0", + "sonner": "^2.0.7", "tailwind-merge": "^2.5.0", "zustand": "^5.0.0" }, diff --git a/src/styles/globals.css b/src/styles/globals.css index 823d5fc..56a9dcb 100644 --- a/src/styles/globals.css +++ b/src/styles/globals.css @@ -198,4 +198,16 @@ ) 1; } + + /* Expand the Sonner close-button hit-test radius for touch. + Visible size stays at sonner's 20px default; the ::after pseudo + gives an effective ~36–40px tap target without changing layout. */ + [data-sonner-toaster] [data-close-button] { + touch-action: manipulation; + } + [data-sonner-toaster] [data-close-button]::after { + content: ''; + position: absolute; + inset: -8px; + } }