"Terribly high CPU usage, the MacBook gets really hot" - a fanless MacBook Air on a 144Hz screen. Measured on that machine with headed engines (process CPU plus the per-process GPU time macOS keeps): an idle Aero library cost LibreWolf ~110% CPU and ~230ms/s of GPU, the study feed ~130%, Chromium up to ~57% CPU and ~350ms/s of GPU, Safari ~220-250ms/s of WindowServer GPU. Priced one by one: - the gradient mask on .ice-floats re-rendered the animated layer offscreen on every frame (~75 points of Gecko CPU). The floats now rise through a plain rectangular band clear of the header, the bottom chrome and the rail, and fade in and out inside it, so the clip never cuts a visible one; - the overlay grain forced a backdrop readback per frame for a texture that measured a mean <=0.11/255 difference: removed; - the invisible blob drift made every frame a full-screen redraw: the blobs are painted once; - static glass (answer tiles, feedback panel, chips, inputs, dropzones, lists, segmented controls, Aero hint chips) re-blurred the moving scene every frame: only floating glass blurs now, and Aero's baked chat chrome drops a live blur that never showed under the bake; - the scene also parks while the window has no focus and under any dialog or sheet scrim (.scene-pause); the loading icon is a compositor-run CSS animation instead of a framer-motion main-thread loop. After, focused and animating: LibreWolf library 109% -> 33% CPU, study 134% -> 34%, chat 130% -> 42%; Chromium GPU 2.5-4.4x lower with 7-22 points less CPU; Safari's WindowServer GPU -20-26% in Aero, about half in dark. Unfocused or under a sheet: nothing. bubbles-test sweeps every float through 41 phases against the band and pins the parking and the cost contract; tests/heat-probe.mjs (macOS) repeats the measurement; the suites find Playwright's Chromium on macOS. All 15 suites pass, lint clean, the contrast scan lost a finding. Version 0.6.7, SW v89. Co-authored-by: Cursor <cursoragent@cursor.com>
126 lines
4.2 KiB
TypeScript
126 lines
4.2 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
import { motion } from "framer-motion";
|
|
import { useAppReducedMotion as useReducedMotion } from "@/lib/motion-pref";
|
|
|
|
import { Button, ProgressBar } from "@/components/ui";
|
|
import { useI18n } from "@/lib/i18n";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
/**
|
|
* The one loading screen for every model pipeline — deck/notes creation,
|
|
* homework, and the route-level "preparing…" screens: the app icon, the
|
|
* rotating stage message as the headline, the two-step progress bar, the
|
|
* checklist of stages, an optional tip and Cancel.
|
|
*
|
|
* Extracted from the deck wizard (the look people already know) so the
|
|
* homework flows and route loads read exactly the same.
|
|
*/
|
|
|
|
export type LoadingStage = {
|
|
id: string;
|
|
/** First line of the checklist (= the stage's first message). */
|
|
labelKey: string;
|
|
/** Rotating messages while this stage runs. */
|
|
messageKeys: string[];
|
|
};
|
|
|
|
export function LoadingState({
|
|
stages,
|
|
activeStage,
|
|
message,
|
|
messageKey,
|
|
tipKeys,
|
|
onCancel,
|
|
}: {
|
|
/** Pipeline stages in order. Omit for a plain "working" screen. */
|
|
stages?: LoadingStage[];
|
|
/** Which stage is running now (matches a stage id). */
|
|
activeStage?: string;
|
|
/** Live message from the server; wins until the first rotation tick. */
|
|
message?: string;
|
|
/** Static message for screens without stages. */
|
|
messageKey?: string;
|
|
/** Pick one of these at random and show it under the stages. */
|
|
tipKeys?: string[];
|
|
onCancel?: () => void;
|
|
}) {
|
|
const { t } = useI18n();
|
|
const reduceMotion = useReducedMotion();
|
|
const [tick, setTick] = useState(0);
|
|
const [tip, setTip] = useState<string | null>(null);
|
|
|
|
useEffect(() => {
|
|
if (!stages) return;
|
|
const timer = window.setInterval(() => setTick((value) => value + 1), 3200);
|
|
return () => window.clearInterval(timer);
|
|
}, [stages]);
|
|
|
|
useEffect(() => {
|
|
if (!tipKeys || tipKeys.length === 0) return;
|
|
setTip(tipKeys[Math.floor(Math.random() * tipKeys.length)]);
|
|
}, [tipKeys]);
|
|
|
|
const activeIndex = stages ? Math.max(0, stages.findIndex((stage) => stage.id === activeStage)) : 0;
|
|
const rotation = stages?.[activeIndex]?.messageKeys ?? [];
|
|
const shown =
|
|
tick === 0 && message
|
|
? message
|
|
: rotation.length > 0
|
|
? t(rotation[tick % rotation.length])
|
|
: messageKey
|
|
? t(messageKey)
|
|
: "";
|
|
|
|
return (
|
|
<div
|
|
role="status"
|
|
aria-busy="true"
|
|
className="relative flex min-h-[70dvh] flex-col items-center justify-center gap-6 text-center"
|
|
>
|
|
{/* The app icon, not the bare snowflake — same logo as the header,
|
|
sidebar and empty states. */}
|
|
<div aria-hidden className={cn("relative size-28", !reduceMotion && "loading-bob")}>
|
|
{/* eslint-disable-next-line @next/next/no-img-element -- static app icon, no optimisation needed */}
|
|
<img src="/icons/icon-512.png" alt="" className="size-28 rounded-[1.75rem] shadow-lift" />
|
|
</div>
|
|
|
|
<div className="relative w-full max-w-md space-y-3">
|
|
<motion.p
|
|
key={shown}
|
|
initial={reduceMotion ? false : { opacity: 0, y: 8 }}
|
|
animate={{ opacity: 1, y: 0 }}
|
|
transition={{ duration: 0.22, ease: "easeOut" }}
|
|
className="text-xl font-extrabold text-[var(--text)]"
|
|
aria-live="polite"
|
|
>
|
|
{shown}
|
|
</motion.p>
|
|
|
|
{stages && stages.length > 0 ? (
|
|
<ProgressBar value={activeIndex + 1} max={stages.length} label={t("upload.generationProgress")} />
|
|
) : null}
|
|
|
|
{stages && stages.length > 1 ? (
|
|
<ol className="space-y-1 text-left text-[14.5px] leading-relaxed text-[var(--text-muted)]">
|
|
{stages.map((stage, index) => (
|
|
<li key={stage.id} className="flex items-center gap-2">
|
|
<span aria-hidden>{index < activeIndex ? "✅" : index === activeIndex ? "🌀" : "⬜"}</span>
|
|
{t(stage.labelKey)}
|
|
</li>
|
|
))}
|
|
</ol>
|
|
) : null}
|
|
|
|
{tip ? <p className="pt-2 text-[12.5px] text-[var(--text-subtle)]">{t(tip)}</p> : null}
|
|
|
|
{onCancel ? (
|
|
<Button variant="ghost" size="sm" className="touch-target" onClick={onCancel}>
|
|
{t("upload.cancel")}
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|