follow up to userenderdebug

This commit is contained in:
Nate 2025-09-15 14:22:29 -07:00
parent 364489c573
commit 931afc63aa
2 changed files with 29 additions and 4 deletions

View file

@ -7,13 +7,13 @@ import { CSSProperties, useEffect, useRef } from "react";
*
* - Returns a `ref` to attach to a container element and a `count` that
* increments on every render of the component using this hook.
* - On each render, it briefly adds a CSS class (default: `toolbar-rerender-flash`)
* - On each render, it briefly adds a CSS class (default: `rerender-flash`)
* to the element for a quick visual flash.
* - Use together with <RenderCountBadge /> to show the render count inline.
*
* Options:
* - enabled: boolean to toggle the effect (default true)
* - flashClassName: class added on each render (default `toolbar-rerender-flash`)
* - flashClassName: class added on each render (default `rerender-flash`)
* - flashDurationMs: duration of the flash animation in ms (default 180)
*/
@ -24,7 +24,7 @@ export function useRenderDebug(options?: {
}) {
const {
enabled = true,
flashClassName = "toolbar-rerender-flash",
flashClassName = "rerender-flash",
flashDurationMs = 180,
} = options || {};
@ -56,7 +56,7 @@ export function RenderCountBadge(props: {
const { count, title = `Renders: ${count}`, style, className } = props;
return (
<span
className={`toolbar-render-count ${className || ""}`}
className={`render-count ${className || ""}`}
title={title}
style={style}
>

View file

@ -119,3 +119,28 @@ body {
.scroll-container:is(:hover, :focus)::-webkit-scrollbar {
display: block; /* Show scrollbar only on hover or focus */
}
/* Debug: visible flash when component re-renders */
@keyframes rerenderFlash {
0% {
box-shadow: 0 0 0 2px rgba(255, 0, 0, 0.9) inset;
}
100% {
box-shadow: 0 0 0 0 rgba(255, 0, 0, 0) inset;
}
}
.rerender-flash {
animation: rerenderFlash 180ms ease-out;
}
.render-count {
display: inline-block;
margin-right: 6px;
padding: 0 4px;
border-radius: 3px;
background: rgba(255, 0, 0, 0.15);
color: rgba(255, 0, 0, 0.9);
font-weight: 600;
letter-spacing: 0.02em;
}