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

vercel-react-view-transitions

Skill này làm gì

Skill này giúp thêm các chuyển động có hoạt ảnh giữa các màn hình và trạng thái trong ứng dụng React. Skill dành cho lập trình viên frontend muốn chuyển động tinh tế mà không cần mã hoạt ảnh nặng.

Khi nào nên dùng

  • ✓Khi bạn muốn một hoạt ảnh mượt khi chuyển giữa các trang hoặc route.
  • ✓Khi bạn muốn một phần tử chuyển động từ danh sách sang màn hình chi tiết.
  • ✓Khi bạn muốn các mục trong danh sách có hoạt ảnh khi được sắp xếp lại hoặc thêm vào.

Liên kết skill

https://github.com/vercel-labs/agent-skills/blob/main/skills/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/vercel-labs/agent-skills/blob/main/skills/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

“Thêm một chuyển động mượt khi người dùng nhấn vào thẻ sản phẩm và mở trang chi tiết.”

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

Cách hoạt động

Skill dùng một thành phần ViewTransition để chỉ định phần nào sẽ chuyển động, và bắt đầu thay đổi bằng các hook chuyển đổi. Kiểu dáng được đặt bằng class CSS, và trình duyệt không hỗ trợ sẽ bỏ qua hoạt ảnh một cách an toàn.

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 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 (page-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: Use stable react and react-dom 19.3 or newer (ViewTransition and addTransitionType became stable in React 19.3). Earlier stable React versions do not include these APIs.
  • Browser support: Chromium 125+ (React needs the v2 object form of startViewTransition), 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. Use references/css-recipes.md for the applicable CSS and adapt it to the app.


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>, or the boundary itself changing size/position due to an immediate sibling. 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" />

If default is "none", all trigge

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

Trình duyệt cũ có bị lỗi không?

Không. Trình duyệt không hỗ trợ View Transition API sẽ bỏ qua hoạt ảnh một cách êm ái.

Mọi phần tử đều nên có hoạt ảnh không?

Không. Mỗi hoạt ảnh nên thể hiện một mối liên hệ rõ ràng, nếu không thì không nên thêm.

Kiểu dáng được kiểm soát thế nào?

Thông qua các class CSS và pseudo-element của view transition.

Chi tiết

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

Guide for implementing smooth, native-feeling animations using React's View Transition API (`<ViewTransition>` component, `addTransitionType`, and CSS view transition pseudo-elements). Use this skill whenever the user wants to add page transitions, animate route changes, create shared element animations, animate enter/exit of components, animate list reorder, implement directional (forward/back) navigation animations, or integrate view transitions in Next.js. Also use when the user mentions view transitions, `startViewTransition`, `ViewTransition`, transition types, or asks about animating bet

repo: vercel-labs/agent-skills

Độ phổ biến

Sao GitHub
33k
Vị trí xếp hạng
#8432
Giấy phép
—
Cập nhật
28/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ự