---
title: "Two Clicks, One Stale Panel: A Race in Our Pricing Wizard"
description: "Two clicks 360 ms apart could leave our pricing wizard on a stale step. How we scheduled a framer-motion AnimatePresence race inside a test, then fixed it."
author: "Vaynerov Technologies"
published: 2026-12-01
canonical: "https://vaynerov.com/articles/two-clicks-one-stale-panel"
---

# Two Clicks, One Stale Panel: A Race in Our Pricing Wizard

Two quick clicks on Next could leave our pricing wizard showing a question it had already moved past. With the CPU throttled and the clicks 360 ms apart, it happened in 7 of 8 runs. The state was right; the screen was wrong. Here is how we reproduced the race, scheduled it frame by frame, fixed it, and kept a test that objects the day the library's behavior changes.

Our [pricing calculator](https://vaynerov.com/pricing) is an eight-step wizard, from platforms to contact details. Two of its steps, Features and AI Modules, are optional, so Next stays enabled on both. On a busy enough machine, two quick clicks on Next from the Features step could leave the wizard showing two different steps at once. The step indicator had moved on to step 5, Design, and Next was disabled, because Design needs a choice. The panel on screen still asked “Do you need AI capabilities?”, and it stayed that way until the page was reloaded.

Nothing in our state was wrong. The wizard knew exactly where it was; the screen showed a step it had already left.

That makes it a particular kind of race: not two pieces of code fighting over data, but a view that stopped following its data. The same race stranded a joining player in [Tesseract](https://vaynerov.com/articles/chess-in-four-dimensions), the four-dimensional chess game in our Lab.

| Figure | Measure |
| --- | --- |
| 7 of 8 | runs stranded at a 360 ms gap, before the fix |
| 1 of 52 | scheduled interleavings stranded the old Tesseract switch |
| 0 of 64 | runs stranded after the fix, gaps from 0 to 400 ms |
| 0 of 12 | production runs stranded after the deploy |

_Each browser run presses Next twice, a fixed gap apart, with the CPU throttled sixfold. The 52 interleavings come from a unit test that schedules Tesseract's online view frame by frame._

## How do you reproduce a bug that needs a slow CPU?

You make a fast machine slow, by the same amount every time. Our script opened the wizard in Chromium, answered the first two steps and slowed the CPU sixfold with the browser's built-in throttling. Then it pressed Next twice from the Features step, with real input events, the second press a fixed gap after the first. At a gap of 360 ms, 7 of 8 runs stranded on the stale AI panel. In the eighth, the second click missed, so that run proved nothing either way.

The window is narrow because it sits at the end of one animation. Each step slid out over 0.35 seconds. The wizard stranded only when the second click and the end of the Features step's exit landed in the same React batch, the one render pass React gives to updates that arrive together. A throttled main thread makes that collision likely. An end-to-end run had also hit it once under parallel load: it timed out waiting for the Design step.

## Where else did it happen?

In Tesseract's online mode, a guest joining a match could stay on “Waiting for your opponent” while the host's screen said “Opponent connected”. In two batches of test joins on production builds, that happened 5 times in 18 and 2 times in 16.

Again, the state was right. The signed handshake had finished: the guest was seated, pings were flowing both ways, and the match had started behind the panel. Only the screen had not moved. A joining guest flips the online view twice in under a second, from the lobby to the Waiting panel when the room code is set, then to the match when the host's welcome lands. A busy main thread lines those two updates up, which is why the failures clustered on the slowest joins.

## Why does AnimatePresence wait mode strand a panel?

Because in framer-motion 12.34, a view that is entered and left inside one exit can be mounted straight into the exiting state, and that exit never completes. Both switches, the components that swap one view for the next, used `AnimatePresence` in `mode="wait"`, which holds the next view back until the leaving view's exit animation has ended.

We traced the sequence on Tesseract's switch, and the wizard's fix points back to that write-up. When the leaving view's exit ended in the same React batch as the second flip, framer-motion swapped in the view it had been holding back, one that had never mounted. In that same render it saw that this view was no longer present either, and mounted it directly as an exiting view. Its exit was reported complete before `AnimatePresence` had registered it, so the report was swallowed; and because the view's presence never changed again, no exit animation ever ran. In Tesseract, that view was the Waiting panel. In the wizard, it was the AI step.

The bug lived entirely in the animation layer. With reduced motion turned on, the wizard swaps steps without `AnimatePresence`, so it cannot strand. The wizard's state logic needed no change.

```diff
- <AnimatePresence mode="wait" custom={state.direction}>
+ <AnimatePresence mode="popLayout" custom={state.direction}>
```

_The wizard's step switch, before and after (pricing/client.tsx). One attribute ends the stranding; the rest of this piece is how we knew it was the right one._

## Schedule the race instead of waiting for it

A race you wait for proves nothing on the runs where it doesn't happen, so the Tesseract fix ships with a test that makes it happen on demand. The test, `online-view-race.test.ts`, renders the real online view with real React DOM and real framer-motion. Only the session hook is a stub, because the bug lives entirely between “the session says playing” and “the screen says playing”.

There is no browser. The DOM is a minimal in-memory tree, and the test owns time: it advances `requestAnimationFrame` and `performance.now` one 16 ms frame at a time, and every React commit happens inside `act`. Even the stand-in elements are deliberate. They are not `HTMLElement`s, because framer-motion checks for one before it hands an animation to the browser's Web Animations API, and every animation here has to run on the frame loop the test drives.

Then the test walks the whole window. For each of 26 frame offsets, covering the lobby's exit with a margin on both sides, it delivers the host's welcome twice: once in a React batch of its own, and once inside the batch of that frame's animation callbacks. The second is how a busy main thread delivers it, with the result of the welcome's key derivation and the frame that ends the exit queued behind one long task. On the old wait-mode switch, exactly 1 of those 52 interleavings strands the guest: the welcome delivered in the same batch as the frame that completes the exit. On the fixed switch, none does.

> The race is not waited for. It is scheduled.

## What fixed it?

Mounting every view as present before it can be the one leaving. That removes what the stranding needs, a view that leaves without ever having mounted, so every exit is a real transition that completes. The wizard now runs in `popLayout`: the arriving step mounts at once, the leaving one is lifted out of the layout flow, and the two slides overlap instead of queuing. With the fix, the same script ran 64 times over eight gaps from 0 to 400 ms, and every run reached Design. After the deploy, 12 runs against production, at gaps of 345 to 375 ms, did too.

Tesseract's switch now runs in the default sync mode, a 0.28-second cross-fade instead of a sequence. The signed protocol and the session hook are untouched; the whole fix is in the view. Both fixes went live on November 27.

![Dot grid of scripted wizard runs. Before the fix, at a 360 ms gap: eight dots, seven filled as stranded and one marked as a missed click. After the fix: sixty-four hollow dots across eight gaps from 0 to 400 ms. On production after the deploy: twelve hollow dots.](https://vaynerov.com/articles/art/two-clicks-one-stale-panel--runs.svg?v=eqqdqjbjz)

_One dot per scripted run. Before the fix, at 360 ms: 7 of 8 stranded, and the eighth missed its second click. After it: 64 runs over gaps of 0, 120, 240, 330, 345, 360, 375 and 400 ms, then 12 on production at 345–375 ms, with none stranded._

## The frame nobody should see

One frame at the end of each exit needed its own fix. In framer-motion, the opacity fade ends one frame before the leaving step is removed, and that frame paints the step at full opacity. The old exit stopped 300 pixels out, still partly inside the wizard's clipping container, so the step flashed back into view, on the live site too.

So the leaving step now travels its full width, to `-100%` instead of 300 pixels, in 0.18 seconds instead of 0.35. By the time the fade ends, the step is already outside the `overflow-hidden` container, and the full-opacity frame paints where nobody can see it. Leaving in about half the time also means the two headings never sit on top of each other long enough to read as one.

## Tests that object

Both fixes have tests that object if they are undone, and one more test objects if framer-motion's behavior changes.

- **The wizard's source test.** `pricing-wizard-switch.test.ts` fails if the step switch is ever anything but `popLayout`, or if the steps' container stops being positioned and clipped.
- **The scheduled sweep.** Put Tesseract's switch back in wait mode and 1 of the 52 interleavings strands again, which fails the test.
- **The end-to-end join.** Tesseract's join test now also asserts that no Waiting panel is left over a seated match. It already checked the seat chip, but a chip that reads the state cannot see a stale panel sitting on top of it.
- **The control.** A test named “reproduces with a bare wait-mode switch” sends the same two flips through a plain `AnimatePresence mode="wait"` and expects the never-mounted panel to be stranded. If a framer-motion release changes that behavior, this test fails on purpose while the sweep keeps passing. That failure is a signal to revisit the workaround, not a regression.

Our rule going forward: no wait mode where a switch can flip twice inside one exit.

In [Craft in the Age of Generated Code](https://vaynerov.com/articles/craft-in-the-age-of-generated-code), Edward Amirain, our founder, wrote that we stopped asking who wrote a line and started asking “what, in the build, would object if the line were wrong”. For a one-attribute fix, that answer is most of the work: a source test, a scheduled race, an end-to-end check, and a control that is waiting to fail.

* * *

The wizard is at [vaynerov.com/pricing](https://vaynerov.com/pricing#calculator). It runs on the same calculator engine that priced the three worked examples in [What a Software Project Costs](https://vaynerov.com/articles/what-a-software-project-costs), and two quick clicks on Next now land where the indicator says. Tesseract's online mode is at [vaynerov.com/games/tesseract](https://vaynerov.com/games/tesseract): one of you creates a room, the other types the code, and the guest's screen follows its seat. If one of your products has a screen that sometimes disagrees with its own state, we would be glad to [hear about it](https://vaynerov.com/contact).
