~/discoveries/work 2026-11-21
The 1 ms animation that never finished
A typed terminal on this site left 148 of 430 glyphs invisible even though the browser reported every animation as finished. The fix, the measurement, and a second gotcha with calc() and var().
- css
- animation
- debugging
- chromium
Symptom
The home page has a terminal that types itself. To get a per-character reveal without JavaScript timers, each glyph is a span with its own CSS animation, delayed by its index. It looked right on my machine and wrong on others: some characters never appeared.
I counted instead of trusting my eyes. After load, 148 of 430 glyphs had a computed opacity of 0. The odd part is that element.getAnimations() reported those same animations as finished.
The code that failed
.type-glyph {
opacity: 0;
animation: type-glyph 1ms steps(1) var(--d) forwards;
}
@keyframes type-glyph {
to { opacity: 1; }
}The base style hides the glyph. The animation is supposed to flip it to visible after its delay and hold that value with forwards. A one millisecond duration with a single step looked like the cheapest way to say "switch on at time d".
How I measured it
The check is a short script run in the page after load. It walks every glyph, reads the computed opacity, and counts the ones still at 0. It also compares that with the animation state. This is the shape of it, not a test file in the repository.
const glyphs = [...document.querySelectorAll(".type-glyph")];
const hidden = glyphs.filter((g) => getComputedStyle(g).opacity === "0");
const finished = glyphs.filter((g) =>
g.getAnimations().every((a) => a.playState === "finished"),
);
console.log({ total: glyphs.length, hidden: hidden.length, finished: finished.length });Before the fix this printed 430 total and 148 hidden, with the animations reported as finished. A finished animation with a hidden result means the end state of the animation was not applied to the computed style.
The fix
.type-glyph {
animation: type-glyph 40ms linear var(--d) both;
}
@keyframes type-glyph {
from { opacity: 0; }
}- No base opacity. The element is visible by default, so a glyph can never be stuck hidden by a missing animation effect.
- The keyframe animates from the hidden value to the element's own value, so the resting state is the normal style, not a filled-forward value.
- both fills backwards as well, which keeps the glyph hidden during its delay.
- 40 ms linear instead of 1 ms steps(1). The reveal is a short fade rather than a switch.
Same script, same page: 0 of 430 hidden.
Cause, as hypotheses. I did not verify any of this in the Chromium source. One: with a 1 ms duration and many animations starting in the same frames, an animation can reach its end between style updates, and a forwards fill of the final keyframe may not be applied over the opacity: 0 base. Two: the base opacity: 0 and a forwards fill are two separate declarations that must win in the cascade, and I removed that dependency instead of proving which side lost. The fix works; the explanation is a guess.
A second gotcha, same day
The line-by-line typing used one animation per line, with its duration computed from the character count.
.type-line {
animation: type calc(var(--chars) * var(--type-step, 20ms)) steps(var(--chars), end) var(--delay, 0ms) both;
}A line of 10 characters had --type-step: 90ms set inline on the same element, so I expected 0.9 s. The computed animation-duration was 0.2 s, which is 10 times the 20 ms fallback. The inline custom property was ignored inside that calc().
<span
className="type-line"
style={{ "--chars": text.length, animationDuration: `${text.length * 90}ms` }}
>Setting animationDuration inline gave 0.9 s. As before, I do not know the root cause. My hypotheses are an ordering problem between the shorthand's var() substitution and the inline property, or a unit-typed value reaching calc() as the fallback. Neither is verified.
What I would do next time
- Trust computed style, not getAnimations(). The first said 148 glyphs were hidden; the second said everything was fine.
- Make the default state the visible one, and let the animation take things away, not add them.
- Avoid sub-frame durations. At 60 Hz one frame is about 16.7 ms, so 1 ms asks for an effect the page cannot show.
- When a value is computed from a custom property and comes out as the fallback, set the final value inline and move on.