Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(motion): reduced motion is instant everywhere, and lint rejects system-only checks (MUL-9969) (#11303)

Jiayuan Zhangdaf52e7045e7
diff --git a/apps/desktop/eslint.config.mjs b/apps/desktop/eslint.config.mjs
index f6cc0f68fa..ed2b63b36a 100644
--- a/apps/desktop/eslint.config.mjs
+++ b/apps/desktop/eslint.config.mjs
@@ -2,6 +2,7 @@ import globals from "globals";
import reactConfig from "@multica/eslint-config/react";
import { ICON_LIBRARY_IMPORT_PATTERNS, REDUCED_MOTION_IMPORT } from "@multica/eslint-config/base";
import { NO_ROUND_CONTROLS } from "@multica/eslint-config/control-shape";
+import { NO_SYSTEM_ONLY_REDUCED_MOTION } from "@multica/eslint-config/reduced-motion";
import {
NO_UNTRANSLATED_ATTRIBUTES,
NO_UNTRANSLATED_JSX_TEXT,
@@ -86,6 +87,7 @@ export default [
NO_UNTRANSLATED_JSX_TEXT,
NO_UNTRANSLATED_TOAST,
NO_ROUND_CONTROLS,
+ NO_SYSTEM_ONLY_REDUCED_MOTION,
],
},
},
@@ -101,6 +103,7 @@ export default [
"Direct router.navigate from application code breaks the Coordinator protocol (MUL-4741). Route it through the navigation adapter in src/platform.",
},
NO_ROUND_CONTROLS,
+ NO_SYSTEM_ONLY_REDUCED_MOTION,
],
},
},
diff --git a/apps/web/eslint.config.mjs b/apps/web/eslint.config.mjs
index 7c653da8be..a466e8e322 100644
--- a/apps/web/eslint.config.mjs
+++ b/apps/web/eslint.config.mjs
@@ -1,31 +1,40 @@
import nextConfig from "@multica/eslint-config/next";
+import { NO_SYSTEM_ONLY_REDUCED_MOTION } from "@multica/eslint-config/reduced-motion";
import {
NO_UNTRANSLATED_ATTRIBUTES,
NO_UNTRANSLATED_JSX_TEXT,
NO_UNTRANSLATED_TOAST,
} from "../../packages/views/eslint-i18n-guard.mjs";
+const TESTS = ["**/*.test.{ts,tsx}", "**/test/**/*.{ts,tsx}"];
+
export default [
...nextConfig,
{ ignores: [".next/", ".source/"] },
+ {
+ // The marketing site never mounts the Appearance settings, so the system
+ // setting is the only one it can follow.
+ files: ["**/*.{ts,tsx}"],
+ ignores: ["app/(landing)/**", "features/landing/**", ...TESTS],
+ rules: {
+ "no-restricted-syntax": ["error", NO_SYSTEM_ONLY_REDUCED_MOTION],
+ },
+ },
{
files: ["app/**/*.{ts,tsx}"],
- ignores: [
- "app/(landing)/**",
- "**/*.test.{ts,tsx}",
- "**/test/**/*.{ts,tsx}",
- ],
+ ignores: ["app/(landing)/**", ...TESTS],
rules: {
"no-restricted-syntax": [
"error",
NO_UNTRANSLATED_ATTRIBUTES,
NO_UNTRANSLATED_JSX_TEXT,
NO_UNTRANSLATED_TOAST,
+ NO_SYSTEM_ONLY_REDUCED_MOTION,
],
},
},
{
- files: ["**/*.test.{ts,tsx}", "**/test/**/*.{ts,tsx}"],
+ files: TESTS,
rules: {
"react/display-name": "off",
},
diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json
index 9b725eeff7..cb92b4743f 100644
--- a/packages/eslint-config/package.json
+++ b/packages/eslint-config/package.json
@@ -11,7 +11,8 @@
"./react": "./react.js",
"./next": "./next.js",
"./control-shape": "./control-shape.js",
- "./full-page-navigation": "./full-page-navigation.js"
+ "./full-page-navigation": "./full-page-navigation.js",
+ "./reduced-motion": "./reduced-motion.js"
},
"dependencies": {
"@eslint/js": "^9.28.0",
diff --git a/packages/eslint-config/reduced-motion.js b/packages/eslint-config/reduced-motion.js
new file mode 100644
index 0000000000..783ce03a39
--- /dev/null
+++ b/packages/eslint-config/reduced-motion.js
@@ -0,0 +1,23 @@
+// Reduced motion has two sources: the system's `prefers-reduced-motion` and
+// the Appearance page's Reduce motion switch. A bare media query string, read
+// through `matchMedia` or a media-query hook, sees only the first, so the
+// switch silently does nothing there. `packages/core/appearance` owns the one
+// sanctioned query and is not covered by this rule.
+//
+// Matches the query as a string literal or a template literal anywhere, which
+// covers `matchMedia("(prefers-reduced-motion: reduce)")`, `window.matchMedia?.(…)`
+// and a query kept in a constant.
+//
+// Exported for `no-restricted-syntax`, whose options flat config replaces
+// wholesale: a package that sets its own entries must list this one again.
+
+const QUERY = "/^\\s*\\(\\s*prefers-reduced-motion/";
+
+export const NO_SYSTEM_ONLY_REDUCED_MOTION = {
+ selector: [
+ `Literal[value=${QUERY}]`,
+ `TemplateLiteral > TemplateElement:first-child[value.raw=${QUERY}]`,
+ ].join(", "),
+ message:
+ "A prefers-reduced-motion query sees only the system setting, not the Appearance Reduce motion switch. Use useReducedMotion() in render or prefersReducedMotion() outside it, both from @multica/core/appearance; in CSS use the motion-reduce: variants (packages/ui/docs/motion.md).",
+};
diff --git a/packages/eslint-config/reduced-motion.test.js b/packages/eslint-config/reduced-motion.test.js
new file mode 100644
index 0000000000..3444d2c149
--- /dev/null
+++ b/packages/eslint-config/reduced-motion.test.js
@@ -0,0 +1,106 @@
+import assert from "node:assert/strict";
+import { test } from "node:test";
+import { fileURLToPath } from "node:url";
+import { ESLint, Linter } from "eslint";
+import tseslint from "typescript-eslint";
+import { NO_SYSTEM_ONLY_REDUCED_MOTION } from "./reduced-motion.js";
+
+const linter = new Linter();
+
+function flagged(code) {
+ const messages = linter.verify(
+ code,
+ [
+ {
+ files: ["**/*.ts"],
+ languageOptions: { parser: tseslint.parser },
+ rules: { "no-restricted-syntax": ["error", NO_SYSTEM_ONLY_REDUCED_MOTION] },
+ },
+ ],
+ "fixture.ts",
+ );
+ const fatal = messages.find((m) => m.fatal);
+ if (fatal) throw new Error(`fixture failed to parse: ${fatal.message}`);
+ return messages.length > 0;
+}
+
+const FLAGGED = [
+ ["window.matchMedia", 'window.matchMedia("(prefers-reduced-motion: reduce)").matches;'],
+ ["optional window.matchMedia", 'window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;'],
+ ["bare matchMedia", 'matchMedia("(prefers-reduced-motion: reduce)").matches;'],
+ ["single quotes", "matchMedia('(prefers-reduced-motion: reduce)');"],
+ ["no-preference", 'matchMedia("(prefers-reduced-motion: no-preference)");'],
+ ["template literal", "matchMedia(`(prefers-reduced-motion: reduce)`);"],
+ ["query kept in a constant", 'const QUERY = "(prefers-reduced-motion: reduce)";'],
+ ["media-query hook", 'useMediaQuery("(prefers-reduced-motion: reduce)");'],
+];
+
+const ALLOWED = [
+ ["the core helper", "prefersReducedMotion();"],
+ ["another media query", 'window.matchMedia("(prefers-color-scheme: dark)").matches;'],
+ ["a Tailwind variant", 'const className = "motion-reduce:transition-none";'],
+ ["a sentence naming the setting", 'const hint = "Honours prefers-reduced-motion";'],
+ ["a CSS rule string", 'const rule = "@media (prefers-reduced-motion: reduce) { * { transition: none; } }";'],
+ ["a template literal that only mentions it", "const hint = `Follows ${name} (prefers-reduced-motion)`;"],
+];
+
+for (const [name, code] of FLAGGED) {
+ test(`flags ${name}`, () => assert.equal(flagged(code), true));
+}
+
+for (const [name, code] of ALLOWED) {
+ test(`allows ${name}`, () => assert.equal(flagged(code), false));
+}
+
+test("message points to the core helpers", () => {
+ assert.match(NO_SYSTEM_ONLY_REDUCED_MOTION.message, /@multica\/core\/appearance/);
+});
+
+// The real package configs: views, web and desktop follow the Appearance
+// switch; core implements it and the marketing site never mounts it.
+const QUERY_SOURCE = 'export const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;\n';
+const IMPORT_SOURCE = 'import { useReducedMotion } from "motion/react";\nexport { useReducedMotion };\n';
+
+const workspace = (path) => fileURLToPath(new URL(`../../${path}`, import.meta.url));
+const configs = new Map();
+function eslintFor(cwd) {
+ if (!configs.has(cwd)) configs.set(cwd, new ESLint({ cwd: workspace(cwd) }));
+ return configs.get(cwd);
+}
+
+async function hits(cwd, filePath, source, ruleId) {
+ const [result] = await eslintFor(cwd).lintText(source, { filePath: `${workspace(cwd)}/${filePath}` });
+ return result.messages.filter((m) => m.ruleId === ruleId).length;
+}
+
+const COVERED = [
+ ["packages/views", "issues/components/motion.ts"],
+ ["packages/views", "dev-toolbar/motion.tsx"],
+ ["apps/web", "components/motion.tsx"],
+ ["apps/web", "app/[workspaceSlug]/motion.tsx"],
+ ["apps/desktop", "src/renderer/src/components/motion.tsx"],
+ ["apps/desktop", "src/renderer/src/components/desktop-dev-toolbar.tsx"],
+];
+
+for (const [cwd, file] of COVERED) {
+ test(`${cwd}/${file} rejects a bare reduced-motion query`, async () => {
+ assert.equal(await hits(cwd, file, QUERY_SOURCE, "no-restricted-syntax"), 1);
+ });
+
+ test(`${cwd}/${file} rejects motion's useReducedMotion`, async () => {
+ assert.equal(await hits(cwd, file, IMPORT_SOURCE, "no-restricted-imports"), 1);
+ });
+}
+
+const EXEMPT = [
+ ["packages/core", "appearance/motion.ts"],
+ ["apps/web", "features/landing/site/motion.tsx"],
+ ["apps/web", "app/(landing)/motion.tsx"],
+ ["packages/views", "issues/components/motion.test.ts"],
+];
+
+for (const [cwd, file] of EXEMPT) {
+ test(`${cwd}/${file} may read the system query`, async () => {
+ assert.equal(await hits(cwd, file, QUERY_SOURCE, "no-restricted-syntax"), 0);
+ });
+}
diff --git a/packages/ui/styles/base.css b/packages/ui/styles/base.css
index 86cd45f949..96331ebec4 100644
--- a/packages/ui/styles/base.css
+++ b/packages/ui/styles/base.css
@@ -188,9 +188,9 @@
@media (prefers-reduced-motion: reduce) {
.animate-inbox-enter-next,
- .animate-inbox-enter-prev {
- animation-name: inbox-enter-fade;
- animation-duration: 120ms;
+ .animate-inbox-enter-prev,
+ .animate-inbox-enter-fade {
+ animation: none;
}
}
diff --git a/packages/ui/styles/reduced-motion.test.ts b/packages/ui/styles/reduced-motion.test.ts
new file mode 100644
index 0000000000..541f8550bf
--- /dev/null
+++ b/packages/ui/styles/reduced-motion.test.ts
@@ -0,0 +1,50 @@
+// @vitest-environment node
+import { readFileSync } from "node:fs";
+import { join } from "node:path";
+import { describe, expect, it } from "vitest";
+
+const css = readFileSync(join(__dirname, "base.css"), "utf8");
+
+/** The bodies of every `@media (prefers-reduced-motion: reduce)` block. */
+function reducedMotionBlocks(source: string): string[] {
+ const blocks: string[] = [];
+ const opener = /@media\s*\(prefers-reduced-motion:\s*reduce\)\s*\{/g;
+ for (let match = opener.exec(source); match; match = opener.exec(source)) {
+ let depth = 1;
+ let end = opener.lastIndex;
+ while (depth > 0 && end < source.length) {
+ if (source[end] === "{") depth++;
+ else if (source[end] === "}") depth--;
+ end++;
+ }
+ blocks.push(source.slice(opener.lastIndex, end - 1));
+ }
+ return blocks;
+}
+
+/** Rules inside a block as `[selectors, declarations]`. */
+function rules(block: string): [string[], string][] {
+ return [...block.matchAll(/([^{}]+)\{([^{}]*)\}/g)].map(([, selectors, body]) => [
+ selectors!.split(",").map((selector) => selector.trim()),
+ body!,
+ ]);
+}
+
+describe("base.css under the system reduced-motion setting", () => {
+ const classes = [...new Set(css.match(/\.animate-inbox-enter-[\w-]+/g))];
+ const reduced = reducedMotionBlocks(css).flatMap(rules);
+
+ it("defines the Inbox detail transitions", () => {
+ expect(classes.sort()).toEqual([
+ ".animate-inbox-enter-fade",
+ ".animate-inbox-enter-next",
+ ".animate-inbox-enter-prev",
+ ]);
+ });
+
+ it.each(classes)("%s does not animate, not even as a fade", (name) => {
+ const rule = reduced.find(([selectors]) => selectors.includes(name));
+ expect(rule, `${name} needs a rule in @media (prefers-reduced-motion: reduce)`).toBeDefined();
+ expect(rule![1]).toMatch(/(^|;|\s)animation:\s*none\s*;/);
+ });
+});
diff --git a/packages/views/eslint.config.mjs b/packages/views/eslint.config.mjs
index af5a9718fa..ba1760f089 100644
--- a/packages/views/eslint.config.mjs
+++ b/packages/views/eslint.config.mjs
@@ -2,6 +2,7 @@ import reactConfig from "@multica/eslint-config/react";
import { ICON_LIBRARY_IMPORT_PATTERNS, REDUCED_MOTION_IMPORT } from "@multica/eslint-config/base";
import { NO_ROUND_CONTROLS } from "@multica/eslint-config/control-shape";
import { NO_FULL_PAGE_NAVIGATION } from "@multica/eslint-config/full-page-navigation";
+import { NO_SYSTEM_ONLY_REDUCED_MOTION } from "@multica/eslint-config/reduced-motion";
import i18next from "eslint-plugin-i18next";
import {
NO_UNTRANSLATED_ATTRIBUTES,
@@ -48,6 +49,7 @@ export default [
NO_UNTRANSLATED_TOAST,
NO_ROUND_CONTROLS,
NO_FULL_PAGE_NAVIGATION,
+ NO_SYSTEM_ONLY_REDUCED_MOTION,
],
"no-restricted-imports": [
"error",
@@ -65,7 +67,7 @@ export default [
files: ["dev-toolbar/**/*.{ts,tsx}", "**/dev-actions.ts"],
rules: {
"i18next/no-literal-string": "off",
- "no-restricted-syntax": ["error", NO_ROUND_CONTROLS, NO_FULL_PAGE_NAVIGATION],
+ "no-restricted-syntax": ["error", NO_ROUND_CONTROLS, NO_FULL_PAGE_NAVIGATION, NO_SYSTEM_ONLY_REDUCED_MOTION],
},
},
];
diff --git a/packages/views/inbox/components/inbox-empty-state.test.tsx b/packages/views/inbox/components/inbox-empty-state.test.tsx
index 7584766223..1eb7c66a22 100644
--- a/packages/views/inbox/components/inbox-empty-state.test.tsx
+++ b/packages/views/inbox/components/inbox-empty-state.test.tsx
@@ -1,6 +1,7 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { act, cleanup, fireEvent, screen } from "@testing-library/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { useAppearanceStore } from "@multica/core/appearance";
import { inboxKeys, snoozedInboxOptions } from "@multica/core/inbox/queries";
import { useInboxSelectionStore, type InboxTab } from "@multica/core/inbox/selection-store";
import type { SnoozedInboxIssue } from "@multica/core/types";
@@ -126,6 +127,21 @@ describe("InboxEmptyState", () => {
expect(nav.push).toHaveBeenCalledWith("/acme/inbox?view=snoozed");
});
+ it("rises into Inbox Zero, and shows it at once with reduced motion", () => {
+ const card = () => screen.getByRole("heading", { name: "Inbox cleared" }).closest("[class*='max-w-md']");
+ renderEmpty({ inboxZeroRises: true });
+ expect(card()).toHaveClass("animate-inbox-enter-next");
+ cleanup();
+
+ useAppearanceStore.getState().set({ reduceMotion: true });
+ try {
+ renderEmpty({ inboxZeroRises: true });
+ expect(card()?.className).not.toMatch(/animate-inbox-enter/);
+ } finally {
+ useAppearanceStore.getState().reset();
+ }
+ });
+
it("offers inline undo for the just-archived notification and navigates back on click", async () => {
useInboxSelectionStore.setState({
lastClearedByWorkspace: {
diff --git a/packages/views/inbox/components/inbox-empty-state.tsx b/packages/views/inbox/components/inbox-empty-state.tsx
index 053cb23a7d..c72bf5335b 100644
--- a/packages/views/inbox/components/inbox-empty-state.tsx
+++ b/packages/views/inbox/components/inbox-empty-state.tsx
@@ -242,7 +242,7 @@ export function InboxEmptyState({
key={`card-${bleedKey}`}
className={cn(
"relative z-10 -mt-8 flex max-w-md flex-col items-center",
- reduceMotion ? "animate-inbox-enter-fade" : rises ? "animate-inbox-enter-next" : "animate-inbox-enter-fade",
+ !reduceMotion && (rises ? "animate-inbox-enter-next" : "animate-inbox-enter-fade"),
)}
>
<div
diff --git a/packages/views/issues/components/issue-detail.test.tsx b/packages/views/issues/components/issue-detail.test.tsx
index d7512e2a16..e0b0ee1369 100644
--- a/packages/views/issues/components/issue-detail.test.tsx
+++ b/packages/views/issues/components/issue-detail.test.tsx
@@ -21,6 +21,8 @@ import enIssues from "../../locales/en/issues.json";
import { useIssueSidebarSectionsStore } from "@multica/core/issues/stores/issue-sidebar-sections-store";
import { useSubIssuesCollapseStore } from "@multica/core/issues/stores/sub-issues-collapse-store";
import { configureShortcutPlatform } from "@multica/core/shortcuts";
+import { useAppearanceStore } from "@multica/core/appearance";
+import { useInboxSelectionStore } from "@multica/core/inbox/selection-store";
const TEST_RESOURCES = { en: { agents: enAgents, common: enCommon, inbox: enInbox, issues: enIssues } };
@@ -1641,6 +1643,42 @@ describe("IssueDetail (shared)", () => {
expect(screen.queryByRole("button", { name: enInbox.context_menu.archive })).not.toBeInTheDocument();
});
+ describe("advancing to the next notification", () => {
+ const entering = (container: HTMLElement) => container.querySelector("[class*='animate-inbox-enter']");
+ async function advance() {
+ useInboxSelectionStore.getState().recordTransition("ws-1", "issue-1", "next");
+ const view = renderWithArchive();
+ await screen.findByRole("button", { name: enCommon.more_actions });
+ await waitFor(() => expect(useInboxSelectionStore.getState().transitionByWorkspace["ws-1"]).toBeUndefined());
+ return view;
+ }
+ afterEach(() => {
+ useAppearanceStore.getState().reset();
+ vi.unstubAllGlobals();
+ });
+
+ it("slides the issue in from the direction of travel", async () => {
+ const { container } = await advance();
+ expect(entering(container)).toHaveClass("animate-inbox-enter-next");
+ });
+
+ it("shows the issue at once with the Appearance Reduce motion switch", async () => {
+ useAppearanceStore.getState().set({ reduceMotion: true });
+ const { container } = await advance();
+ expect(entering(container)).toBeNull();
+ });
+
+ it("shows the issue at once with the system reduced-motion setting", async () => {
+ vi.stubGlobal("matchMedia", vi.fn((query: string) => ({
+ matches: query === "(prefers-reduced-motion: reduce)",
+ addEventListener: vi.fn(),
+ removeEventListener: vi.fn(),
+ })));
+ const { container } = await advance();
+ expect(entering(container)).toBeNull();
+ });
+ });
+
it("keeps pinning in the more-actions menu rather than the header", async () => {
mockApiObj.listPins.mockResolvedValue([
{
diff --git a/packages/views/issues/components/issue-detail.tsx b/packages/views/issues/components/issue-detail.tsx
index 7cff760519..8e55494363 100644
--- a/packages/views/issues/components/issue-detail.tsx
+++ b/packages/views/issues/components/issue-detail.tsx
@@ -4022,12 +4022,11 @@ export function IssueDetail({ issueId, onDelete, inbox, defaultSidebarOpen = tru
: cn(READING_COLUMN, "px-[var(--space-sm,0.75rem)] py-[var(--space-lg,1.5rem)] max-md:pb-chat-launcher md:px-[var(--space-xl,2rem)] md:py-[var(--space-xl,2rem)]"),
hideUnalignedLanding && "opacity-0",
!hideUnalignedLanding &&
+ !reduceMotion &&
activeInboxTransition &&
- (reduceMotion
- ? "animate-inbox-enter-fade"
- : activeInboxTransition === "next"
- ? "animate-inbox-enter-next"
- : "animate-inbox-enter-prev"),
+ (activeInboxTransition === "next"
+ ? "animate-inbox-enter-next"
+ : "animate-inbox-enter-prev"),
)}
>
<IssueDuplicateBanner
diff --git a/packages/views/issues/components/use-run-comment-motion.test.tsx b/packages/views/issues/components/use-run-comment-motion.test.tsx
index f07d452178..d1ce4826d6 100644
--- a/packages/views/issues/components/use-run-comment-motion.test.tsx
+++ b/packages/views/issues/components/use-run-comment-motion.test.tsx
@@ -1,4 +1,5 @@
import { useState } from "react";
+import { useAppearanceStore } from "@multica/core/appearance";
import { act, cleanup, fireEvent, render, renderHook, screen, waitFor } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { AgentTask } from "@multica/core/types";
@@ -107,6 +108,33 @@ describe("run comment motion", () => {
expect(animate).not.toHaveBeenCalled();
});
+ it("disables run arrival, reply and status motion with the Appearance Reduce motion switch", () => {
+ useAppearanceStore.getState().set({ reduceMotion: true });
+ try {
+ const view = render(<Slot status="running" />);
+ view.rerender(<Slot status="running" entering />);
+ view.rerender(<Slot status="running" entering replyId="reply" />);
+ view.rerender(<Slot status="completed" entering replyId="reply" />);
+ expect(animate).not.toHaveBeenCalled();
+ expect(screen.getByText("completed")).toBeInTheDocument();
+ expect(screen.getByText("Reply")).toBeInTheDocument();
+ } finally {
+ useAppearanceStore.getState().reset();
+ }
+ });
+
+ it("turns the disclosure arrow at once with the Appearance Reduce motion switch", () => {
+ useAppearanceStore.getState().set({ reduceMotion: true });
+ try {
+ render(<Disclosure />);
+ fireEvent.click(screen.getByRole("button", { name: "Toggle" }), { detail: 1 });
+ expect(animate).not.toHaveBeenCalled();
+ expect(screen.getByText("Activity")).toBeInTheDocument();
+ } finally {
+ useAppearanceStore.getState().reset();
+ }
+ });
+
it("pauses ambient run motion outside the viewport", async () => {
let notify!: IntersectionObserverCallback;
const observe = vi.fn();
diff --git a/packages/views/layout/collection-list/collection-batch-bar.test.tsx b/packages/views/layout/collection-list/collection-batch-bar.test.tsx
new file mode 100644
index 0000000000..61b13496c4
--- /dev/null
+++ b/packages/views/layout/collection-list/collection-batch-bar.test.tsx
@@ -0,0 +1,58 @@
+import { act, screen } from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { useAppearanceStore } from "@multica/core/appearance";
+import { renderWithI18n } from "../../test/i18n";
+import { CollectionBatchBar } from "./collection-batch-bar";
+
+function bar(count: number) {
+ return (
+ <CollectionBatchBar count={count} onClear={() => {}}>
+ <button type="button">Archive</button>
+ </CollectionBatchBar>
+ );
+}
+
+/** One animation frame: motion applies instant values on its next frame. */
+const nextFrame = () => act(() => new Promise<void>((resolve) => requestAnimationFrame(() => resolve())));
+
+const toolbar = () => screen.queryByRole("toolbar");
+
+afterEach(() => {
+ useAppearanceStore.getState().reset();
+ vi.unstubAllGlobals();
+});
+
+describe("CollectionBatchBar", () => {
+ it("fades and rises in when rows are selected", async () => {
+ const view = renderWithI18n(bar(0));
+ view.rerender(bar(2));
+ await nextFrame();
+ expect(toolbar()).toBeInTheDocument();
+ expect(Number(toolbar()!.style.opacity)).toBeLessThan(1);
+ });
+
+ describe.each([
+ ["the Appearance Reduce motion switch", () => useAppearanceStore.getState().set({ reduceMotion: true })],
+ [
+ "the system reduced-motion setting",
+ () =>
+ vi.stubGlobal("matchMedia", vi.fn((query: string) => ({
+ matches: query === "(prefers-reduced-motion: reduce)",
+ addEventListener: vi.fn(),
+ removeEventListener: vi.fn(),
+ }))),
+ ],
+ ])("with %s", (_name, reduce) => {
+ it("shows the bar fully in the first frame and removes it in the first frame", async () => {
+ reduce();
+ const view = renderWithI18n(bar(0));
+ view.rerender(bar(2));
+ await nextFrame();
+ expect(toolbar()).toHaveStyle({ opacity: "1", transform: "translateY(0)" });
+
+ view.rerender(bar(0));
+ await nextFrame();
+ expect(toolbar()).toBeNull();
+ });
+ });
+});
diff --git a/packages/views/layout/collection-list/collection-batch-bar.tsx b/packages/views/layout/collection-list/collection-batch-bar.tsx
index bee088b91b..6cb02914f8 100644
--- a/packages/views/layout/collection-list/collection-batch-bar.tsx
+++ b/packages/views/layout/collection-list/collection-batch-bar.tsx
@@ -55,15 +55,12 @@ export function CollectionBatchBar({
animate={{
opacity: 1,
transform: "translateY(0)",
- transition: { duration: UI_MOTION_DURATION.fast, ease: UI_EASE_OUT },
+ transition: { duration: reduceMotion ? 0 : UI_MOTION_DURATION.fast, ease: UI_EASE_OUT },
}}
exit={{
opacity: 0,
transform: offset,
- transition: {
- duration: reduceMotion ? UI_MOTION_DURATION.fast : UI_MOTION_DURATION.micro,
- ease: UI_EASE_OUT,
- },
+ transition: { duration: reduceMotion ? 0 : UI_MOTION_DURATION.micro, ease: UI_EASE_OUT },
}}
>
<div className="mr-1 flex items-center gap-1.5 border-r pl-1 pr-2">
diff --git a/packages/views/settings/components/billing-tab.tsx b/packages/views/settings/components/billing-tab.tsx
index 55ef8eb400..7f9e141459 100644
--- a/packages/views/settings/components/billing-tab.tsx
+++ b/packages/views/settings/components/billing-tab.tsx
@@ -16,6 +16,7 @@ import {
RefreshCw,
} from "@multica/ui/icons";
import { ApiError, errorCode } from "@multica/core/api";
+import { prefersReducedMotion } from "@multica/core/appearance";
import { autopilotQuotaUsageOptions } from "@multica/core/autopilots";
import {
useChangeWorkspacePlan,
@@ -133,10 +134,7 @@ function scrollToUpgrade() {
const target = document.querySelector<HTMLElement>(
`[${SETTINGS_ANCHOR_ATTR}="${UPGRADE_SECTION_ANCHOR}"]`,
);
- const reduceMotion =
- typeof window.matchMedia === "function" &&
- window.matchMedia("(prefers-reduced-motion: reduce)").matches;
- target?.scrollIntoView?.({ block: "start", behavior: reduceMotion ? "auto" : "smooth" });
+ target?.scrollIntoView?.({ block: "start", behavior: prefersReducedMotion() ? "auto" : "smooth" });
}
const SEAT_PURCHASE_POLL_TIMEOUT_MS = 2 * 60_000;
const SEAT_PURCHASE_PREVIEW_DEBOUNCE_MS = 800;
diff --git a/packages/views/settings/components/settings-page.tsx b/packages/views/settings/components/settings-page.tsx
index 89dff48090..cef96210a4 100644
--- a/packages/views/settings/components/settings-page.tsx
+++ b/packages/views/settings/components/settings-page.tsx
@@ -24,6 +24,7 @@ import {
Workflow,
Zap,
} from "@multica/ui/icons";
+import { prefersReducedMotion } from "@multica/core/appearance";
import { useCurrentWorkspace, useWorkspacePaths } from "@multica/core/paths";
import { useFeatureEnabled } from "@multica/core/config";
import { useCurrentMember } from "@multica/core/permissions";
@@ -381,12 +382,9 @@ export function SettingsPage({ extraDeviceTabs = [] }: SettingsPageProps = {}) {
}
return;
}
- const reduceMotion =
- typeof window.matchMedia === "function" &&
- window.matchMedia("(prefers-reduced-motion: reduce)").matches;
target.scrollIntoView?.({
block: "center",
- behavior: reduceMotion ? "auto" : "smooth",
+ behavior: prefersReducedMotion() ? "auto" : "smooth",
});
target.setAttribute("data-flash", "true");
flashTimer = setTimeout(() => target.removeAttribute("data-flash"), FLASH_MS);
diff --git a/packages/views/voice/voice-ui.tsx b/packages/views/voice/voice-ui.tsx
index 1547972c30..63d9ea564a 100644
--- a/packages/views/voice/voice-ui.tsx
+++ b/packages/views/voice/voice-ui.tsx
@@ -3,7 +3,7 @@
import { useEffect, useRef, type PointerEvent, type SyntheticEvent } from "react";
import { AnimatePresence, motion } from "motion/react";
import { AlertCircle, Check, Mic, MicOff, RotateCcw, X } from "@multica/ui/icons";
-import { useReducedMotion } from "@multica/core/appearance";
+import { prefersReducedMotion, useReducedMotion } from "@multica/core/appearance";
import { Button } from "@multica/ui/components/ui/button";
import { IconButton } from "@multica/ui/components/common/icon-button";
import { ShimmerText } from "@multica/ui/components/common/shimmer-text";
@@ -74,7 +74,7 @@ function Waveform({ density, className }: { density: keyof typeof WAVE_GEOMETRY;
const ctx = canvas?.getContext("2d");
if (!canvas || !ctx) return;
const { pitch, bar, fade } = WAVE_GEOMETRY[density];
- const still = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
+ const still = prefersReducedMotion();
const color = getComputedStyle(canvas).color;
let width = 0;
let height = 0;
diff --git a/scripts/motion/inbox-detail.mjs b/scripts/motion/inbox-detail.mjs
new file mode 100644
index 0000000000..46bd3f5f11
--- /dev/null
+++ b/scripts/motion/inbox-detail.mjs
@@ -0,0 +1,82 @@
+// Scenario for scripts/motion/capture.mjs: archiving from the Inbox detail,
+// which advances to the next notification and slides its issue in
+// (.animate-inbox-enter-next). It needs the `sidebar` fixture:
+//
+// make env-exec ARGS="-- node scripts/dev-fixtures.mjs sidebar"
+// make env-exec ARGS="-- node scripts/motion/capture.mjs scripts/motion/inbox-detail.mjs --out ../motion"
+//
+// Each pass archives two notifications, so one run uses six; run the fixture
+// again for another. The reduced passes cover both sources: the system
+// setting, and the Appearance page's Reduce motion switch.
+
+const TARGETS = {
+ column: '[data-tab-scroll-root^="main:"] > div',
+ bar: "[data-inbox-bar]",
+};
+const ARCHIVES = 2;
+const PASSES = [
+ { name: "motion", options: {} },
+ { name: "system reduced motion", options: { reducedMotion: true }, reduced: true },
+ {
+ name: "Appearance Reduce motion",
+ options: { storage: { multica_appearance: JSON.stringify({ state: { reduceMotion: true }, version: 0 }) } },
+ reduced: true,
+ },
+];
+
+// Boxes cannot show a fade, which is what reduced motion used to fall back
+// to, so the column's opacity is read every frame too (as a percentage).
+function watchOpacity(page) {
+ return page.evaluate((selector) => {
+ const state = { values: [], stopped: false };
+ window.__motionOpacity = state;
+ const frame = () => {
+ if (state.stopped) return;
+ const el = document.querySelector(selector);
+ if (el) state.values.push(Number(getComputedStyle(el).opacity) * 100);
+ requestAnimationFrame(frame);
+ };
+ requestAnimationFrame(frame);
+ }, TARGETS.column);
+}
+const stopOpacity = (page) =>
+ page.evaluate(() => {
+ window.__motionOpacity.stopped = true;
+ return window.__motionOpacity.values;
+ });
+
+async function openInbox(open, options) {
+ const page = await open("/inbox", options);
+ const row = page.locator("[data-inbox-row]").first();
+ await row.waitFor({ timeout: 60000 });
+ await row.click();
+ await page.waitForSelector(`${TARGETS.bar} button`, { timeout: 30000 });
+ await page.waitForTimeout(1500); // fonts, queries, the first entry
+ return page;
+}
+
+export default async function inboxDetail({ open, sample, check, checks }) {
+ const { track, animated, instant } = checks;
+ for (const pass of PASSES) {
+ const page = await openInbox(open, pass.options);
+ for (let i = 1; i <= ARCHIVES; i++) {
+ const label = `${pass.name}, archive ${i} → next notification`;
+ const before = page.url();
+ const archive = page.locator(TARGETS.bar).getByRole("button", { name: /^Archive/ });
+ await watchOpacity(page);
+ const frames = await sample(page, label, TARGETS, () => archive.click(), { quietMs: 600 });
+ const opacity = await stopOpacity(page);
+ await page.waitForURL((url) => url.href !== before, { timeout: 5000 }).catch(() => {});
+ check(`${label}: opens the next issue`, { ok: page.url() !== before, detail: page.url().split("?")[1] ?? page.url() });
+ const y = track(frames, "column", "y");
+ if (pass.reduced) {
+ check(`${label}: issue lands without moving`, instant(y));
+ check(`${label}: issue appears without a fade`, instant(opacity));
+ } else {
+ check(`${label}: issue slides in`, animated(y));
+ check(`${label}: issue fades in`, animated(opacity));
+ }
+ await page.waitForTimeout(800);
+ }
+ }
+}