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.
This commit is contained in:
1 parent
1e0a481a60
commit
bcafbe2aae
2 files changed
+7
-22
No files matched your search
@@ -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",
|
||||
|
||||
@@ -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<string, unknown>;
|
||||
|
||||
// Cache motion components at module level to avoid creating during render
|
||||
const motionComponentCache = new Map<
|
||||
keyof React.JSX.IntrinsicElements,
|
||||
React.ComponentType<MotionHTMLProps>
|
||||
>();
|
||||
|
||||
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.
|
||||
|
||||
Reference in new issue
Block a user