fix(motion): app shell speaks the motion language — sidebar glides on toggle, steps slide in, points tick, no overshoot, admin on the same tokens (BUG-2331)
Desktop sidebar collapse/expand glides the column one standard step (never while the edge is dragged); session rows, menus, subject picker, account menu and tooltips move on quick/instant with faster exits; login and onboarding steps arrive 8px from the reading direction; points numbers tick from the side they moved (CreditsValue); redeem success settles on emphasis + ease-out; antd motion tokens follow lib/motion/tokens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
This commit is contained in:
@@ -31476,3 +31476,30 @@
|
||||
- 尚未处理(第 2 步):问答页、星盘页、报告/年度/合盘/生时纠正、外壳与登录/设置/管理后台各处手写动效按计划逐区改到档位上(含报告进度条 width 改 scaleX、生时纠正自选条 flex-basis/left 改位移、侧栏和问答星盘面板滑入、数字变化、跳到最新按钮淡入)。
|
||||
- 关联记录:BUG-2276(磨砂遮罩)、BUG-2308、BUG-2320、BUG-2305(问答时间条与等待动画,第 2 步并入同一语言)。
|
||||
- 修复版本:分支 `claude/motion-foundation-2327`(未推送)。
|
||||
|
||||
## BUG-2331 | 外壳动效第 2 步:侧栏收起展开一下跳过去,登录/引导换步、积分变化、兑换成功、后台动效各用各的节奏
|
||||
|
||||
- 状态:fixed(本地提交,待并入动效整体发布)
|
||||
- 首次发现 / 最近更新:2026-11-24(负责人要求全站动效做到苹果级细腻;按「状态变化」逐项排查外壳区)/ 2026-11-24
|
||||
- 现象:
|
||||
- 电脑上点侧栏收起/展开,侧栏宽度 288↔64 瞬间跳变,正文一下子挪位,看不出侧栏去了哪。
|
||||
- 侧栏会话菜单、顶栏「选择星盘」、账户菜单、提示气泡还是 120ms 写死,没跟 BUG-2327 的节奏;退出不比进入快。
|
||||
- 登录换步(邮箱→验证码→两步验证→设密码)和三屏引导换屏是 180–220ms 写死的淡入,没有方向。
|
||||
- 余额数字(侧栏、账户与点数)扣点、退点、兑换后直接换掉,看不出变了。
|
||||
- 兑换成功弹出用了回弹曲线(cubic-bezier(.2,.9,.3,1.2),过冲),0.42s。
|
||||
- 后台(antd)用组件库自带的动效时长和带回弹的曲线。
|
||||
- 根因:BUG-2327 只统一了 components/ui 共用组件;外壳各处的过渡是各自写的原始时长,侧栏宽度切换从没加过过渡。
|
||||
- 修复:
|
||||
- `components/shell-frame.tsx`:点收起/展开时给外壳标一个 `data-shell-gliding`(一个 standard 档后撤掉),侧栏列在两档宽度之间滑过去;拖动侧栏边缘时不标,边缘始终跟手。手机侧栏是 Sheet,沿用 2327。
|
||||
- `globals.css` 末尾 `BUG-2331 motion — shell` 一段,全部只用 2327 的时长/曲线变量:会话行悬停按下 instant;新会话行淡入(不加 transform 过渡,拖动排序的行仍贴着指针);会话菜单、选择星盘、账户菜单、提示气泡进入 quick、退出 instant + ease-exit;登录换步和引导换屏从阅读方向 8px 滑入(standard),引导进度条颜色 standard;账户弹窗和遮罩 standard;兑换成功改成 emphasis + ease-out,不过冲。
|
||||
- 新组件 `components/credits-value.tsx`:余额数字变化时从变化的方向(增加向上、减少向下)落定,首次显示不动;侧栏余额和「账户与点数」余额都用它。
|
||||
- `components/admin/admin-app.tsx`:antd 主题的 motionDurationFast/Mid/Slow = 100/160/240ms,各条 motionEase* 换成站内曲线(不再有 Back 回弹)。
|
||||
- 减弱动效时变量归零,全部直接出现。
|
||||
- 验证:
|
||||
- 新增 `frontend/tests/motion-shell-2331.test.ts`(7 条):外壳段只用变量、不写原始时长和曲线;只动透明度/位移/颜色(侧栏列宽这一处例外,且只在 gliding 时);拖动时不滑;拖动排序的行没有 transform 过渡;兑换成功不过冲;余额首屏不动、变化才动;后台用同一套变量。
|
||||
- tsc 0 错,eslint 0 错误;2327 守卫、动效预设、类名定义契约测试通过;check-built-css 对编译出的样式表通过。
|
||||
- 帧耗测量(无头 Chrome,静态页套本分支编译样式,80 节长正文 + 30 条会话,收起/展开各 4 次):滑动和直接跳都稳定 16.7ms/帧,没有超过 20ms 的帧;滑动期间每帧一次重排,合计约 0.3s / 32 帧。另用 400 节超长页测得:无论滑不滑,改 `--shell-sidebar-width` 都会触发整棵子树重算样式(每次约 0.3–0.5s),这是原有写法的开销,不是本次新增,记为后续优化点。
|
||||
- 未做:真实构建页面上的路由切换帧耗(需要登录态的本地构建)、真机。
|
||||
- 防复发:外壳区新动效只能用 2327 变量;会被拖动的元素不得给 transform 加过渡;宽度过渡只允许侧栏列这一处且只在点按切换时开启。
|
||||
- 关联记录:BUG-2327(动效语言与共用组件)、BUG-2253(侧栏余额)、BUG-2313/2314(退出、验证码自动登录)、BUG-2275(选择星盘)、#330(兑换成功)。
|
||||
- 修复版本:分支 `claude/motion-shell-2331`(未推送)。
|
||||
|
||||
@@ -9041,3 +9041,56 @@ button.report-ask-excerpt-toggle { height: 32px; padding: 0; color: var(--color-
|
||||
/* The active tile lifts its children with position: relative (.sidebar-nav-link[data-active] > :not(...)); the tag stays in the corner. */
|
||||
.sidebar-nav-link > .sidebar-nav-tag, .sidebar-nav-link[data-active="true"] > .sidebar-nav-tag { position: absolute; z-index: 2; }
|
||||
.sidebar-nav-tag { position: absolute; top: 4px; right: 4px; padding: 2px 5px; border-radius: 999px; background: var(--sidebar-solid, var(--color-canvas)); color: var(--color-ink-secondary); font-size: 10px; line-height: 1.2; white-space: nowrap; pointer-events: none; }
|
||||
|
||||
/* BUG-2331 motion — shell. Every state change in the app shell speaks the BUG-2327
|
||||
language: instant/quick/standard/emphasis steps, --ease-out to settle,
|
||||
--ease-standard for in-place swaps, --ease-exit to leave, no overshoot.
|
||||
Only opacity/transform/colour animate, except the one deliberate case below
|
||||
(the desktop sidebar column), which is measured in BUG_HISTORY. Under
|
||||
prefers-reduced-motion the tokens collapse to zero, so everything here is instant. */
|
||||
|
||||
/* Desktop sidebar collapse/expand: the column glides between its two widths
|
||||
so the page shows where the sidebar went. Only on the toggle (ShellFrame sets
|
||||
data-shell-gliding for one standard step); dragging the edge never glides. */
|
||||
.shell-frame[data-shell-gliding="true"] > .shell-sidebar-slot {
|
||||
transition: flex-basis var(--motion-standard) var(--ease-standard), width var(--motion-standard) var(--ease-standard);
|
||||
will-change: flex-basis, width;
|
||||
}
|
||||
|
||||
/* Sidebar rows, menus and pickers: hover and press are instant, popups quick. */
|
||||
/* A new conversation row fades in where it lands; no transform transition, so a
|
||||
dragged row (dnd-kit sets transform inline) stays exactly under the pointer. */
|
||||
@starting-style { .sidebar-session { opacity: 0; } }
|
||||
.sidebar-session { transition-property: background-color, box-shadow, color, opacity; transition-duration: var(--motion-instant), var(--motion-instant), var(--motion-instant), var(--motion-quick); transition-timing-function: var(--ease-standard), var(--ease-standard), var(--ease-standard), var(--ease-out); }
|
||||
.sidebar-session-menu,
|
||||
.chat-profile-picker-popup,
|
||||
.account-menu-popup,
|
||||
[role="tooltip"] { transition: opacity var(--motion-quick) var(--ease-out), transform var(--motion-quick) var(--ease-out); }
|
||||
.sidebar-session-menu[data-ending-style],
|
||||
.chat-profile-picker-popup[data-ending-style],
|
||||
.account-menu-popup[data-ending-style],
|
||||
[role="tooltip"][data-ending-style] { transition-duration: var(--motion-instant); transition-timing-function: var(--ease-exit); }
|
||||
|
||||
/* Points that changed (CreditsValue) settle in from the direction they moved. */
|
||||
.sidebar-account-credits-value,
|
||||
.billing-balance-number { display: inline-block; font-variant-numeric: tabular-nums; }
|
||||
[data-credits-tick] { animation: credits-tick var(--motion-standard) var(--ease-out) both; }
|
||||
[data-credits-tick="up"] { --credits-from: 4px; }
|
||||
[data-credits-tick="down"] { --credits-from: -4px; }
|
||||
@keyframes credits-tick { from { opacity: 0; transform: translateY(var(--credits-from, 4px)); } to { opacity: 1; transform: none; } }
|
||||
|
||||
/* Login and onboarding steps: each step arrives from the reading direction,
|
||||
quick fade with a short standard slide; the step it replaces is already gone. */
|
||||
.auth-step { transition: opacity var(--motion-quick) var(--ease-out), transform var(--motion-standard) var(--ease-out); }
|
||||
@starting-style { .auth-step { opacity: 0; transform: translateX(8px); } }
|
||||
.onboarding-screen { animation: onboarding-screen-step-in var(--motion-standard) var(--ease-out) both; }
|
||||
@keyframes onboarding-screen-step-in { from { opacity: 0; transform: translateX(8px); } to { opacity: 1; transform: none; } }
|
||||
.onboarding-card-reveal { animation-duration: var(--motion-standard); animation-timing-function: var(--ease-out); }
|
||||
.onboarding-progress li { transition: background-color var(--motion-standard) var(--ease-standard); }
|
||||
|
||||
/* Account dialogs (settings, billing, redeem form) and their scrim. */
|
||||
.account-modal { animation-duration: var(--motion-standard); animation-timing-function: var(--ease-out); }
|
||||
.account-modal-overlay { animation-duration: var(--motion-standard); animation-timing-function: var(--ease-out); }
|
||||
|
||||
/* Redeem success: still the moment of the flow, now settling without overshoot. */
|
||||
.redeem-success-dialog { animation: redeem-success-pop var(--motion-emphasis) var(--ease-out) both; }
|
||||
|
||||
@@ -24,6 +24,7 @@ import { App as AntdApp, ConfigProvider, Spin, theme } from "antd";
|
||||
import { useEffect, useRef, type ReactNode } from "react";
|
||||
|
||||
import { watchKeyboardInset } from "@/lib/admin/keyboard-inset";
|
||||
import { MOTION_EASE, MOTION_MS } from "@/lib/motion/tokens";
|
||||
|
||||
import {
|
||||
adminAccessControlProvider,
|
||||
@@ -59,6 +60,18 @@ export function AdminApp({ children }: { children: ReactNode }) {
|
||||
boxShadowSecondary: "0 1px 2px rgba(29, 29, 31, .06)",
|
||||
boxShadowTertiary: "none",
|
||||
fontFamily: "var(--font-inter, Inter), system-ui, sans-serif",
|
||||
// BUG-2331: antd motion on the site's language (lib/motion/tokens.ts).
|
||||
motionDurationFast: `${MOTION_MS.instant / 1000}s`,
|
||||
motionDurationMid: `${MOTION_MS.quick / 1000}s`,
|
||||
motionDurationSlow: `${MOTION_MS.standard / 1000}s`,
|
||||
motionEaseOut: `cubic-bezier(${MOTION_EASE.out.join(", ")})`,
|
||||
motionEaseInOut: `cubic-bezier(${MOTION_EASE.standard.join(", ")})`,
|
||||
motionEaseOutBack: `cubic-bezier(${MOTION_EASE.out.join(", ")})`,
|
||||
motionEaseInBack: `cubic-bezier(${MOTION_EASE.exit.join(", ")})`,
|
||||
motionEaseInQuint: `cubic-bezier(${MOTION_EASE.exit.join(", ")})`,
|
||||
motionEaseOutQuint: `cubic-bezier(${MOTION_EASE.out.join(", ")})`,
|
||||
motionEaseOutCirc: `cubic-bezier(${MOTION_EASE.out.join(", ")})`,
|
||||
motionEaseInOutCirc: `cubic-bezier(${MOTION_EASE.standard.join(", ")})`,
|
||||
},
|
||||
components: {
|
||||
Layout: {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { CreditsValue } from "@/components/credits-value";
|
||||
import { FeedbackDialog } from "@/components/feedback-dialog";
|
||||
import { SidebarCurrentHighlight } from "@/components/shell-motion";
|
||||
import { useSortableSessions } from "@/components/sidebar-sortable-loader";
|
||||
@@ -514,7 +515,7 @@ export function AppSidebar({
|
||||
: <span className="profile-initial" aria-hidden="true">{account.initial}</span>}
|
||||
{showExpandedContent ? <span><b>{account.name}</b></span> : null}
|
||||
{/* BUG-2253 (产品负责人 2026-11-23): the balance on the account row, without opening the menu. */}
|
||||
{showExpandedContent ? <span className="sidebar-account-credits" aria-label={`余额 ${account.credits} 点`}>{account.credits} 点</span> : null}
|
||||
{showExpandedContent ? <span className="sidebar-account-credits" aria-label={`余额 ${account.credits} 点`}><CreditsValue value={account.credits} className="sidebar-account-credits-value" /> 点</span> : null}
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent
|
||||
className="account-menu-popup w-auto min-w-56"
|
||||
|
||||
@@ -5,11 +5,13 @@
|
||||
* never a blank area.
|
||||
*/
|
||||
|
||||
import { CreditsValue } from "@/components/credits-value";
|
||||
|
||||
export function BillingBalance({ credits }: { readonly credits: number }) {
|
||||
return (
|
||||
<header className="billing-balance">
|
||||
<p className="billing-balance-label">余额</p>
|
||||
<p className="billing-balance-value">{credits} 点</p>
|
||||
<p className="billing-balance-value"><CreditsValue value={credits} className="billing-balance-number" /> 点</p>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
/**
|
||||
* BUG-2331: a points number that changed (a charge, a refund, a redeemed code) settles
|
||||
* in from the side it moved toward — up when it grew, down when it fell — so the change
|
||||
* reads as a change and not as a redraw. The first render just shows the number.
|
||||
*/
|
||||
export function CreditsValue({ value, className }: { readonly value: number; readonly className?: string }) {
|
||||
const previous = useRef(value);
|
||||
const [tick, setTick] = useState<{ key: number; direction: "up" | "down" } | null>(null);
|
||||
useEffect(() => {
|
||||
if (previous.current === value) return;
|
||||
const direction = value > previous.current ? "up" : "down";
|
||||
previous.current = value;
|
||||
setTick((current) => ({ key: (current?.key ?? 0) + 1, direction }));
|
||||
}, [value]);
|
||||
return (
|
||||
<span
|
||||
key={tick?.key ?? 0}
|
||||
className={className}
|
||||
data-credits-tick={tick ? tick.direction : undefined}
|
||||
>
|
||||
{value}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, type ReactNode } from "react";
|
||||
import { useEffect, useRef, useState, type ReactNode } from "react";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useSidebar } from "@/components/ui/sidebar";
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
SIDEBAR_WIDTH_MIN,
|
||||
SIDEBAR_WIDTH_TABLET,
|
||||
} from "@/lib/sidebar-state";
|
||||
import { MOTION_MS } from "@/lib/motion/tokens";
|
||||
import { useUiStore } from "@/stores/ui-store";
|
||||
|
||||
export function ShellFrame({ sidebar, children }: { sidebar: ReactNode; children: ReactNode }) {
|
||||
@@ -30,6 +31,20 @@ export function ShellFrame({ sidebar, children }: { sidebar: ReactNode; children
|
||||
hydrate();
|
||||
}, [hydrate]);
|
||||
|
||||
// BUG-2331: the collapse/expand toggle glides the column between its two widths
|
||||
// (standard step); a drag never sets this, so the edge stays under the pointer.
|
||||
const [gliding, setGliding] = useState(false);
|
||||
const lastOpen = useRef(open);
|
||||
const dragging = useRef(false);
|
||||
useEffect(() => {
|
||||
if (lastOpen.current === open) return undefined;
|
||||
lastOpen.current = open;
|
||||
if (!desktop || dragging.current) return undefined;
|
||||
setGliding(true);
|
||||
const timer = window.setTimeout(() => setGliding(false), MOTION_MS.standard + 40);
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [open, desktop]);
|
||||
|
||||
const resize = useDragWidth({
|
||||
width: pixelWidth,
|
||||
min: SIDEBAR_WIDTH_MIN,
|
||||
@@ -49,6 +64,7 @@ export function ShellFrame({ sidebar, children }: { sidebar: ReactNode; children
|
||||
// bundle runs) the slot is "pending": CSS sizes it by media query and the
|
||||
// stored width, never by its content (the narrow cold-boot sidebar).
|
||||
data-shell-resize={!ready ? "pending" : desktop ? "live" : "mobile"}
|
||||
data-shell-gliding={gliding ? "true" : undefined}
|
||||
style={desktop ? { ["--shell-sidebar-width" as string]: `${pixelWidth}px` } : undefined}
|
||||
>
|
||||
<div className="shell-sidebar-slot">
|
||||
@@ -60,6 +76,17 @@ export function ShellFrame({ sidebar, children }: { sidebar: ReactNode; children
|
||||
className="shell-resize-handle"
|
||||
aria-label="调整侧栏宽度"
|
||||
{...resize}
|
||||
onPointerDown={(event) => {
|
||||
dragging.current = true;
|
||||
const release = () => {
|
||||
dragging.current = false;
|
||||
window.removeEventListener("pointerup", release);
|
||||
window.removeEventListener("pointercancel", release);
|
||||
};
|
||||
window.addEventListener("pointerup", release);
|
||||
window.addEventListener("pointercancel", release);
|
||||
resize.onPointerDown(event);
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import test from "node:test";
|
||||
|
||||
// BUG-2331: the app shell (sidebar, login, onboarding, account dialogs, points, admin) moves
|
||||
// on the BUG-2327 tokens only, never with a raw duration, never with overshoot.
|
||||
|
||||
const css = readFileSync(new URL("../src/app/globals.css", import.meta.url), "utf8");
|
||||
const read = (path: string) => readFileSync(new URL(`../src/${path}`, import.meta.url), "utf8");
|
||||
const marker = "/* BUG-2331 motion — shell.";
|
||||
const block = css.slice(css.indexOf(marker));
|
||||
|
||||
test("the shell block exists and uses only motion tokens", () => {
|
||||
assert.ok(css.includes(marker), "the BUG-2331 block is appended to globals.css");
|
||||
const durations = block.match(/\b\d+(?:\.\d+)?m?s\b/g) ?? [];
|
||||
assert.deepEqual(durations, [], `no raw durations in the shell block: ${durations.join(", ")}`);
|
||||
assert.doesNotMatch(block, /cubic-bezier\(/, "curves come from the --ease-* tokens");
|
||||
});
|
||||
|
||||
test("the shell block animates only opacity and transform (plus the one sidebar column glide)", () => {
|
||||
const props = [...block.matchAll(/transition(?:-property)?:\s*([^;]+);/g)].map((m) => m[1]);
|
||||
for (const value of props) {
|
||||
const named = value.split(",").map((part) => part.trim().split(/\s+/)[0]);
|
||||
for (const name of named) {
|
||||
assert.ok(
|
||||
["opacity", "transform", "background-color", "box-shadow", "color", "flex-basis", "width"].includes(name),
|
||||
`unexpected transition property ${name}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
assert.match(block, /\.shell-frame\[data-shell-gliding="true"\] > \.shell-sidebar-slot \{\s*transition: flex-basis var\(--motion-standard\)/);
|
||||
assert.doesNotMatch(block.replace(/\.shell-frame\[data-shell-gliding="true"\] > \.shell-sidebar-slot \{[^}]*\}/, ""), /transition[^;]*\bwidth\b/);
|
||||
});
|
||||
|
||||
test("the sidebar column glides only on toggle, never while the edge is dragged", () => {
|
||||
const frame = read("components/shell-frame.tsx");
|
||||
assert.match(frame, /data-shell-gliding=\{gliding \? "true" : undefined\}/);
|
||||
assert.match(frame, /if \(!desktop \|\| dragging\.current\) return undefined;/);
|
||||
assert.match(frame, /MOTION_MS\.standard/);
|
||||
});
|
||||
|
||||
test("a dragged conversation row keeps no transform transition", () => {
|
||||
const rule = block.match(/\.sidebar-session \{ transition-property: ([^;]+);/);
|
||||
assert.ok(rule);
|
||||
assert.doesNotMatch(rule[1], /transform/);
|
||||
});
|
||||
|
||||
test("redeem success settles without overshoot", () => {
|
||||
assert.match(block, /\.redeem-success-dialog \{ animation: redeem-success-pop var\(--motion-emphasis\) var\(--ease-out\) both; \}/);
|
||||
});
|
||||
|
||||
test("a changed points number ticks from the side it moved; the first render does not", () => {
|
||||
const source = read("components/credits-value.tsx");
|
||||
assert.match(source, /if \(previous\.current === value\) return;/);
|
||||
assert.match(source, /data-credits-tick=\{tick \? tick\.direction : undefined\}/);
|
||||
assert.match(read("components/app-sidebar.tsx"), /<CreditsValue value=\{account\.credits\}/);
|
||||
assert.match(read("components/billing-balance.tsx"), /<CreditsValue value=\{credits\}/);
|
||||
});
|
||||
|
||||
test("admin antd motion uses the same tokens", () => {
|
||||
const admin = read("components/admin/admin-app.tsx");
|
||||
for (const token of ["motionDurationFast", "motionDurationMid", "motionDurationSlow", "motionEaseOut", "motionEaseOutBack"]) {
|
||||
assert.match(admin, new RegExp(`${token}: `), token);
|
||||
}
|
||||
assert.match(admin, /motionEaseOutBack: `cubic-bezier\(\$\{MOTION_EASE\.out\.join/);
|
||||
});
|
||||
Reference in New Issue
Block a user