Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(chat): respect the app's reduced-motion setting in the streaming fade

AdityaUmalea36a9573e49b
diff --git a/src/components/ChatMarkdown.stream-fade.test.ts b/src/components/ChatMarkdown.stream-fade.test.ts
index 7db480c9ec..ffbb6a932b 100644
--- a/src/components/ChatMarkdown.stream-fade.test.ts
+++ b/src/components/ChatMarkdown.stream-fade.test.ts
@@ -84,4 +84,14 @@ describe("a streaming reply fades in what arrives", () => {
draw("Streaming for someone who asked for less motion ");
expect(take()).toEqual([]);
});
+
+ it("leaves the reply still when the app is set to less motion, whatever the system asks", () => {
+ document.documentElement.dataset.reducedMotion = "true";
+ try {
+ draw("Streaming with the app set to less motion ");
+ expect(take()).toEqual([]);
+ } finally {
+ delete document.documentElement.dataset.reducedMotion;
+ }
+ });
});
diff --git a/src/lib/stream-fade-in.ts b/src/lib/stream-fade-in.ts
index 71ef777fa9..1befa6e61f 100644
--- a/src/lib/stream-fade-in.ts
+++ b/src/lib/stream-fade-in.ts
@@ -2,14 +2,13 @@
// fade lives on the elements' animations, never in the markup, so the streamed page stays the page the saved message
// draws.
import { useLayoutEffect, useRef, type RefObject } from "react";
+import { reducedMotion } from "@/lib/onboarding";
/** What fades in: the reply's top-level blocks (a list by its items), list items and table rows. */
const STREAM_FADE_TARGETS = ":scope > :not(ul, ol), li, tr";
const FADE: Keyframe[] = [{ opacity: 0 }, { opacity: 1 }];
const FADE_TIMING: KeyframeAnimationOptions = { duration: 320, easing: "cubic-bezier(0.22, 1, 0.36, 1)" };
-const reducedMotion = () => window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
-
/** Footnotes sit at the reply's end and a long table draws only the rows in view, so neither keeps page order. */
const keepsPageOrder = (target: Element) => !target.closest("[data-footnotes], [data-virtual]");