From bcafbe2aae59df86a8dd7cf5f5f40e6d9f290f4e Mon Sep 17 00:00:00 2001 From: Jeremy Ruppel Date: Mon, 26 Oct 2026 18:45:39 -0400 Subject: [PATCH] chore(site): enable static-components oxlint rule (#31224) Enables oxlint's `react(static-components)` rule in `site/.oxlintrc.jsonc`, moving it from the correctness backlog to `"error"`. The rule's one violation was `Shimmer`, which resolved its element with `motion.create()` during render. A module-level cache kept the component stable at runtime, but the rule cannot see that, and React Compiler skipped optimizing the component. `Shimmer` now picks from a static `{ p: motion.p, span: motion.span }` map, and `as` is narrowed to `"p" | "span"`. All existing callers pass `as="span"`. > Generated by Coder Agents on behalf of @jeremyruppel. --- site/.oxlintrc.jsonc | 2 +- .../components/ChatElements/Shimmer.tsx | 27 +++++-------------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/site/.oxlintrc.jsonc b/site/.oxlintrc.jsonc index 85f58434934..b43ca941ea4 100644 --- a/site/.oxlintrc.jsonc +++ b/site/.oxlintrc.jsonc @@ -109,6 +109,7 @@ "refs": "error", "erasing-op": "error", "no-unused-expressions": "error", + "static-components": "error", // --- security --- "jsx-no-target-blank": "error", @@ -238,7 +239,6 @@ "no-noninteractive-element-interactions": "off", // (small) "no-useless-fallback-in-spread": "off", // (small) "no-conditional-tests": "off", // (small) - "static-components": "off", // (small) "no-restricted-imports": [ "error", diff --git a/site/src/pages/AgentsPage/components/ChatElements/Shimmer.tsx b/site/src/pages/AgentsPage/components/ChatElements/Shimmer.tsx index 5b19b3d7f4c..192bfdac921 100644 --- a/site/src/pages/AgentsPage/components/ChatElements/Shimmer.tsx +++ b/site/src/pages/AgentsPage/components/ChatElements/Shimmer.tsx @@ -1,28 +1,15 @@ import { cn } from "cn"; -import type { MotionProps } from "motion/react"; import { MotionConfig, MotionConfigContext, motion } from "motion/react"; import { useContext } from "react"; -type MotionHTMLProps = MotionProps & Record; - -// Cache motion components at module level to avoid creating during render -const motionComponentCache = new Map< - keyof React.JSX.IntrinsicElements, - React.ComponentType ->(); - -const getMotionComponent = (element: keyof React.JSX.IntrinsicElements) => { - let component = motionComponentCache.get(element); - if (!component) { - component = motion.create(element); - motionComponentCache.set(element, component); - } - return component; +const motionComponents = { + p: motion.p, + span: motion.span, }; type TextShimmerProps = { children: string; - as?: React.ElementType; + as?: keyof typeof motionComponents; className?: string; duration?: number; spread?: number; @@ -30,14 +17,12 @@ type TextShimmerProps = { const ShimmerComponent = ({ children, - as: Component = "p", + as = "p", className, duration = 2, spread = 2, }: TextShimmerProps) => { - const MotionComponent = getMotionComponent( - Component as keyof React.JSX.IntrinsicElements, - ); + const MotionComponent = motionComponents[as]; // skipAnimations jumps to the final keyframe, which leaves the // gradient offscreen, so hold it centered for captures.