Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)48k · #6106

vercel-react-view-transitions

Skill này làm gì

Công cụ này giúp tạo hoạt ảnh mượt mà khi chuyển giữa các phần của website xây dựng bằng React hoặc Next.js. Các phần tử di chuyển liên kết với nhau giữa các màn hình, như thể chúng là cùng một đối tượng đang đổi chỗ.

Khi nào nên dùng

  • ✓Khi chuyển từ danh sách các mục sang chi tiết của một mục.
  • ✓Khi chuyển đổi giữa các tab hoặc phần khác nhau.
  • ✓Khi dữ liệu mới được tải và màn hình cần cập nhật với hiệu ứng.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/vercel-react-view-transitions/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/vercel-react-view-transitions/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Tạo hoạt ảnh mượt khi người dùng nhấn vào một sản phẩm trong danh sách và chuyển sang trang chi tiết.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ dùng một công nghệ trình duyệt gọi là `document.startViewTransition` để chụp ‘ảnh’ màn hình trước và sau khi thay đổi. Sau đó, nó dùng các lớp CSS để tạo hoạt ảnh chuyển đổi giữa các ảnh này, kết nối các phần tử thay đổi.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

React View Transitions

Animate between UI states using the browser's native document.startViewTransition. Declare what with <ViewTransition>, trigger when with startTransition / useDeferredValue / Suspense, control how with CSS classes. Unsupported browsers skip animations gracefully.

When to Use

  • Use this skill when the task matches this description: Guide React and Next.js view transitions, shared element animations, route transitions, transition types, and reduced-motion-safe UI state animation.

When to Animate

Every <ViewTransition> should communicate a spatial relationship or continuity. If you can't articulate what it communicates, don't add it.

Implement all applicable patterns from this list, in this order:

Priority Pattern What it communicates
1 Shared element (name) "Same thing — going deeper"
2 Suspense reveal "Data loaded"
3 List identity (per-item key) "Same items, new arrangement"
4 State change (enter/exit) "Something appeared/disappeared"
5 Route change (layout-level) "Going to a new place"

This is an implementation order, not a "pick one" list. Implement every pattern that fits the app. Only skip a pattern if the app has no use case for it.

Choosing Animation Style

Context Animation Why
Hierarchical navigation (list → detail) Type-keyed nav-forward / nav-back Communicates spatial depth
Lateral navigation (tab-to-tab) Bare <ViewTransition> (fade) or default="none" No depth to communicate
Suspense reveal enter/exit string props Content arriving
Revalidation / background refresh default="none" Silent — no animation needed

Reserve directional slides for hierarchical navigation (list → detail) and ordered sequences (prev/next photo, carousel, paginated results). For ordered sequences, the direction communicates position: "next" slides from right, "previous" from left. Lateral/unordered navigation (tab-to-tab) should not use directional slides — it falsely implies spatial depth.


Availability

  • Next.js: Do not install react@canary — the App Router already bundles React canary internally. ViewTransition works out of the box. npm ls react may show a stable-looking version; this is expected.
  • Without Next.js: Install react@canary react-dom@canary (ViewTransition is not in stable React).
  • Browser support: Chromium 111+, Firefox 144+, Safari 18.2+. Graceful degradation on unsupported browsers.

Implementation Workflow

When adding view transitions to an existing app, follow references/implementation.md step by step. Start with the audit — do not skip it. Copy the CSS recipes from references/css-recipes.md into the global stylesheet — do not write your own animation CSS.


Core Concepts

The <ViewTransition> Component

import { ViewTransition } from 'react';

<ViewTransition>
  <Component />
</ViewTransition>

React auto-assigns a unique view-transition-name and calls document.startViewTransition behind the scenes. Never call startViewTransition yourself.

Animation Triggers

Trigger When it fires
enter <ViewTransition> first inserted during a Transition
exit <ViewTransition> first removed during a Transition
update DOM mutations inside a <ViewTransition>. With nested VTs, mutation applies to the innermost one
share Named VT unmounts and another with same name mounts in the same Transition

Only startTransition, useDeferredValue, or Suspense activate VTs. Regular setState does not animate.

Critical Placement Rule

<ViewTransition> only activates enter/exit if it appears before any DOM nodes:

// Works
<ViewTransition enter="auto" exit="auto">
  <div>Content</div>
</ViewTransition>

// Broken — div wraps the VT, suppressing enter/exit
<div>
  <ViewTransition enter="auto" exit="auto">
    <div>Content</div>
  </ViewTransition>
</div>

Styling with View Transition Classes

Props

Values: "auto" (browser cross-fade), "none" (disabled), "class-name" (custom CSS), or { [type]: value } for type-specific animations.

<ViewTransition default="none" enter="slide-in" exit="slide-out" share="morph" />

…

Câu hỏi thường gặp

Tôi có cần cài thêm gì không?

Nếu bạn dùng Next.js thì không cần cài thêm gì. Nếu không dùng Next.js, bạn cần cài các phiên bản React cụ thể (`react@canary` và `react-dom@canary`).

‘Shared element animations’ (hoạt ảnh phần tử chung) là gì?

Đó là các hoạt ảnh trong đó cùng một phần tử (như hình ảnh hoặc tiêu đề) xuất hiện trên hai màn hình khác nhau, và hoạt ảnh nối phiên bản cũ với phiên bản mới, tạo cảm giác liền mạch.

Nếu trình duyệt của người dùng không hỗ trợ thì sao?

Hoạt ảnh đơn giản sẽ không chạy, và website vẫn hoạt động bình thường. Nó không làm hỏng trải nghiệm người dùng.

Chi tiết

Mô tả gốc của tác giả

Guide React and Next.js view transitions, shared element animations, route transitions, transition types, and reduced-motion-safe UI state animation.

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#6106
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự