How React ViewTransition animates reorders without FLIP
Use React ViewTransition for list reorders, card-to-header morphs, and Suspense fades. Keep drag and interruptible springs in JavaScript, and confirm canary support first.
This article is published in English.
Sources: I Deleted Half Our FLIP Code and Let the Browser Animate Instead
A bug report on a Next.js document workspace put the complaint in one line: "The comments panel feels drunk."
The wording was fair. Reply to a thread and that thread leapt into the first slot, while every card beneath it dropped a place inside the same frame. Opening one of those cards dropped you on the detail screen, with no visual trace of where the click had started. The data was correct. The motion was blunt enough that the product looked cheaper than the work behind it.
An earlier patch had already tried to hide this, and it had aged badly. Across two years the UI had picked up layout props from framer-motion, plus a custom FLIP helper (measure, then invert, then play) that people were reluctant to edit, along with several useLayoutEffect hooks whose only job was reading boxes before the browser painted. About 80% of updates looked fine. Roughly 20% missed, and the miss showed up as a flicker that would not appear when someone sat down to chase it.
React's <ViewTransition>, sitting on the browser View Transitions API, replaced a large share of that measuring code. The component has sharp corners too, and they show up after the happy path is working.
Check the React build you actually ship before you plan a project around this. <ViewTransition> has lived on the canary channel and on the experimental channel, so confirm the export is really there. Skip memorized version numbers and read the release notes. A remembered digit goes stale. The Next.js integration drifts in the same way.
Position changes and page continuity
One complaint was hiding two different failures.
Movement is rows changing place. The DOM commits in a single frame, so the items jump. FLIP exists for that jump, which is why the old helpers spent their time on geometry.
Continuity is the case where a card should become the next page. Those are separate routes and separate component trees, so there is no old rectangle you can line up against a new one. The previous screen faked the handoff with a fade. A fade is what you ship once you have accepted that the morph is out of reach.
The browser API covers both cases with the same sequence. It photographs the screen, lets your DOM update run, photographs the screen again, and then runs a CSS animation from the first picture to the second. You never read layout yourself. Mark which nodes are one object, and the browser interpolates.
<ViewTransition> is the React piece that chooses when the browser transition should begin, and it assigns the names.
Which updates React will animate
The easy mistake is to expect an animation on every state change. The first attempt usually gets this backwards, so read it carefully. React will not fire a view transition for each setState. If it did, every character typed into an input would strobe. A transition starts only when the update is already in a bucket React treats as deferrable:
- an update you place inside
startTransition - an update that flows from
useDeferredValue - a
<Suspense>boundary exchanging its fallback for the finished UI - navigation, and the App Router already performs that navigation as a transition of its own
A bare setState inside a click handler is urgent work. React renders it synchronously and skips the animation. The thread reorder began as a direct write:
function onReply(threadId: string, text: string) {
addReply(threadId, text);
setThreads((prev) => bumpToTop(prev, threadId));
}
onReply records the reply text, then calls bumpToTop so the thread that just received it moves to the front of the array. That state write has to move into the transition callback:
import { startTransition } from "react";
function onReply(threadId: string, text: string) {
addReply(threadId, text);
startTransition(() => {
setThreads((prev) => bumpToTop(prev, threadId));
});
}
addReply still runs immediately. Only setThreads sits inside startTransition. That wrapper is the switch. In a realtime product it is also a useful filter. Updates arriving on a websocket keep calling setState the ordinary way, so they land at once and do not animate. A reorder gets the slide only when the person at this machine caused it. Three people can reply in the same moment and nobody's list starts to dance.
Enter and exit add a second rule that burns time when you miss it. <ViewTransition> must sit directly on the DOM node it should animate, with no other DOM element ahead of that node in the markup the component returns. Insert a wrapper div and React has nothing to bind the animation to. That silent failure can eat a long debugging session.
Reordering threads without measuring
What remains of that list is the whole component:
import { ViewTransition } from "react";
export function ThreadList({ threads }: { threads: Thread[] }) {
return (
<ul className="threads">
{threads.map((t) => (
<ViewTransition key={t.id}>
<li className="thread">
<ThreadCard thread={t} />
</li>
</ViewTransition>
))}
</ul>
);
}
ThreadList maps threads and wraps each <li> in <ViewTransition>, keyed by t.id, with ThreadCard inside. Once the order shifts during a transition, React tags every item, the browser records the before picture and the after picture, and each card travels from the slot it left to the slot it now occupies. The useLayoutEffect reads for this list, and the FLIP helper that served them, left in the same pull request.
One name, card to header
The morph that mattered most was the document card growing into the header on the page that shows that document.
Give both nodes the same name. When the card leaves the tree and the header enters during that one transition, both React and the browser regard the pair as a single object and animate from the outgoing picture to the incoming one. React calls that pairing a shared element transition.
The index renders the card like this:
<ViewTransition name={`doc-${doc.id}`} share="doc-morph">
<article className="doc-card">
<h3>{doc.title}</h3>
<p>{doc.excerpt}</p>
</article>
</ViewTransition>
The detail route renders the header like this:
<ViewTransition name={`doc-${doc.id}`} share="doc-morph">
<header className="doc-header">
<h1>{doc.title}</h1>
</header>
</ViewTransition>
name is the join. Building it from doc.id gives every card a distinct name. share selects the animation once a matching pair exists. Pass a string and React stamps it on as the class for the view transition, so the stylesheet can address that pair.
::view-transition-group(.doc-morph) {
animation-duration: 280ms;
animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
}
The group named .doc-morph runs for 280ms on cubic-bezier(0.2, 0.8, 0.2, 1). The trip back is the same pairing played in reverse: the header shrinks down into its card. That direction arrived with no extra wiring, and it looked too free until someone pressed back and watched.
CSS for enter, exit, and update
You set enter and exit for mount and unmount, update for a node that stays mounted, and share for a paired morph. default fills in for any of those you leave unset. The allowed values are the keywords "auto" and "none", or a class your CSS defines. A class string is the handoff into the stylesheet. React chooses when the transition runs. The stylesheet chooses the curve.
New comments slide in, and removed ones leave, by naming a class on each side and turning the fallback off:
<ViewTransition key={c.id} enter="comment-in" exit="comment-out" default="none">
<div className="comment">{c.body}</div>
</ViewTransition>
The key is c.id, so React can tell a new comment from a deleted one. enter is comment-in, exit is comment-out, and default is "none". The matching CSS is plain pseudo-elements and two keyframes:
::view-transition-new(.comment-in) {
animation: 200ms ease-out both comment-slide-in;
}
::view-transition-old(.comment-out) {
animation: 160ms ease-in both comment-slide-out;
}
@keyframes comment-slide-in {
from { opacity: 0; transform: translateY(8px); }
}
@keyframes comment-slide-out {
to { opacity: 0; transform: translateY(-8px); }
}
A fresh comment uses ::view-transition-new(.comment-in): 200ms, ease-out, both, on comment-slide-in, which starts at opacity 0 and translateY(8px). A removed comment uses ::view-transition-old(.comment-out): 160ms, ease-in, both, on comment-slide-out, which ends at opacity 0 and translateY(-8px).
default="none" is doing real work. Leave it off and every case you did not name drops back to the browser cross-fade. You get a faint ghost of the old pixels, and the React tree does not explain where it came from.
Loading states paid for the same pattern. Around one Suspense boundary, give the skeleton and the loaded panel their own transitions:
<Suspense
fallback={
<ViewTransition exit="fade-out">
<Skeleton />
</ViewTransition>
}
>
<ViewTransition enter="fade-in" default="none">
<CommentsPanel />
</ViewTransition>
</Suspense>
The fallback wraps Skeleton in a <ViewTransition> whose exit is fade-out. The resolved tree wraps CommentsPanel in a <ViewTransition> whose enter is fade-in and whose default is "none". The skeleton fades away, the comments fade in, and the layout does not pop between them. That cleared a complaint older than the reorder bug.
App Router navigations
Navigations in the App Router are already transitions. A <ViewTransition> placed in a page should fire on its own when the router moves through <Link>, and when code calls router.push. Next.js still hides the feature on an experimental switch inside next.config. The shape has looked roughly like this:
// next.config.ts
const nextConfig = {
experimental: {
viewTransition: true,
},
};
export default nextConfig;
experimental.viewTransition is set to true, and the object is the default export. Treat the snippet as a hint, not a contract. These flags get renamed, or they graduate out of experimental, often enough that you should read the docs for the Next.js release you run.
Two mistakes showed up only after a few broken navigations. Keep named shared nodes inside the page, or inside components that page renders. Do not place them in layout.tsx. Layouts stay mounted while you move between sibling routes, so a <ViewTransition> living there never enters and never exits. The debugger has little to point at. The second mistake is timing. A card-to-header morph needs both nodes on screen during that one navigation. Stream the header from inside a Suspense boundary and the named node can still be missing when the transition records the incoming frame. Once the header sat outside the suspended region, the morph returned.
Reduced motion and missing support
Honor prefers-reduced-motion. It is a single CSS block, and skipping it is hard to justify:
@media (prefers-reduced-motion: reduce) {
::view-transition-group(*),
::view-transition-old(*),
::view-transition-new(*) {
animation: none !important;
}
}
Inside the media query, ::view-transition-group(*), ::view-transition-old(*), and ::view-transition-new(*) all get animation: none !important. The state update still commits and the content still changes. The animation is simply absent. Anyone who opted out of motion sees the content change and nothing else.
Browsers without same-document view transitions miss quietly. React applies the update and skips the animation. Nothing throws, and you do not write a feature check. Chromium and Safari have been gaining support. Firefox is the browser you should not assume will play along, so look at a current compatibility table when you estimate how many people will see the motion. Build the screen so it is complete when nothing moves, and treat the motion as extra.
Failures that took the longest
Two elements, one name
At the moment a transition runs, every name on the page has to be unique. Two nodes carrying one view-transition-name cause the browser to cancel the transition outright, rather than guess which node should win. The duplicate showed up with one card rendered in the primary list and also inside a strip labeled recently opened. The symptom was silence: no animation, and no loud error. When a morph refuses to run and the console stays quiet, look for a repeated name before anything else.
Stretched snapshots
The browser is interpolating two images. A short card becoming a tall header means those images change size on the way, and halfway through the resize the text can look crushed. Most of that cleared once the pseudo-element images were told to fill their group:
::view-transition-old(.doc-morph),
::view-transition-new(.doc-morph) {
height: 100%;
object-fit: cover;
}
Both ::view-transition-old(.doc-morph) and ::view-transition-new(.doc-morph) set height: 100% and object-fit: cover. When the cover crop was still not enough, the shared node itself got simpler. A morph reads cleanly when the thing moving is mostly a box and a title. A dense layout inside the picture fights the scale.
The layer above the page
For the duration of the animation, those pseudo-elements paint on a layer that sits over the document. Clipping from an ancestor overflow: hidden, and any stacking context above the node, no longer reaches those pseudo-elements. A sticky toolbar ended up painted underneath until it was given a view-transition-name of its own. That name turns the toolbar into a stable layer, separate from the root snapshot.
Short durations only
Until that animation finishes, clicks and keystrokes on the page do nothing. Six hundred milliseconds feels like lag. Two hundred and fifty feels like finish. The durations that landed sat between 160 and 300 milliseconds, scaled with how far the element had to travel.
Frozen pictures
Anything moving inside the captured node freezes in the picture. A video frame stops. A blinking caret stops. Leave the editor surface outside <ViewTransition>. It should not move. Motion stays on the surrounding chrome.
Animations that stayed in JavaScript
Wiping out every JavaScript animation helper would be a reason to get suspicious.
A JavaScript animation library stayed for three jobs.
Drag and drop stays in JavaScript. Moving a comment with the pointer, or shifting a sidebar row, is continuous and wants physics. A view transition is a start-to-finish sequence. It is a poor fit for a live drag.
Motion you can interrupt. Fire another update while an animation is still running and a view transition is cut off so the next one can begin. A spring can aim at the new target without that hard cut.
UI that follows a finger. A dismiss swipe, a refresh pull, any gesture whose position is the pointer: those stay in JavaScript.
The split is easy to apply. If the motion means an update already happened and you want the difference shown, <ViewTransition> is the tool. If the motion means a person is physically driving the element, leave it in JavaScript.
When the browser should do it
Reach for <ViewTransition> when the pain is a state change that looks sudden: lists reordering, rows entering and leaving, loading UI appearing, and continuity from one page to the next, for example a list card that grows into the detail header. The measuring code can go. The CSS is straightforward to read. Browsers without the API fall back to no animation, and that fallback is acceptable.
Leave the component alone, or keep the library you already trust for that slice of UI, when motion stays continuous, or a gesture is driving it, when it has to stay interruptible, or when a canary-channel dependency is too risky on a production path. Confirm what your React version and your Next.js version actually support before you commit to it. Hide <ViewTransition> behind a thin wrapper you own, so a later swap of the implementation touches a single file.
The browser should handle the moments that mean here is what changed. A library should handle the moments that mean you are holding the element. A lot of code left the repository, the flicker that hit about a fifth of updates is gone, and the comments panel stopped attracting that complaint.