TypeScript
perf(web): the provider accent color picker compiles without manual memoization (#20612)
Julius Marmingea8dcb960d0d1
diff --git a/apps/web/src/components/settings/ProviderAccentColorPicker.tsx b/apps/web/src/components/settings/ProviderAccentColorPicker.tsxindex 65773d8e1f7..2768f01498d 100644--- a/apps/web/src/components/settings/ProviderAccentColorPicker.tsx+++ b/apps/web/src/components/settings/ProviderAccentColorPicker.tsx@@ -1,7 +1,7 @@"use client";import { PlusIcon, XIcon } from "lucide-react";-import { useCallback, useEffect, useRef, useState } from "react";+import { useEffect, useRef, useState } from "react";import { hexToHsv, hsvToHex, type HsvColor } from "../../lib/color";import { ColorHueSlider, ColorSaturationValuePlane } from "../ui/color-picker";@@ -21,13 +21,10 @@ function ProviderCustomColorPanel(props: {const currentColor = hsvToHex(hsv.h, hsv.s, hsv.v);const [hexDraft, setHexDraft] = useState<string | null>(null);- const commitHsv = useCallback(- (nextHsv: HsvColor) => {- setHsv(nextHsv);- onCommit(hsvToHex(nextHsv.h, nextHsv.s, nextHsv.v));- },- [onCommit],- );+ const commitHsv = (nextHsv: HsvColor) => {+ setHsv(nextHsv);+ onCommit(hsvToHex(nextHsv.h, nextHsv.s, nextHsv.v));+ };return (<div className="w-56 bg-popover">@@ -161,36 +158,33 @@ export function ProviderAccentColorPicker(props: {};}, []);- const commitAccentColor = useCallback(- (value: string) => {- const normalizedValue = normalizeProviderAccentColor(value) ?? "";- setOptimisticValue(normalizedValue);-- if (commitDelayMs <= 0) {- pendingCommitRef.current = null;- if (commitTimeoutRef.current !== null) {- clearTimeout(commitTimeoutRef.current);- commitTimeoutRef.current = null;- }- onCommit(normalizedValue);- return;- }+ const commitAccentColor = (value: string) => {+ const normalizedValue = normalizeProviderAccentColor(value) ?? "";+ setOptimisticValue(normalizedValue);- pendingCommitRef.current = normalizedValue;+ if (commitDelayMs <= 0) {+ pendingCommitRef.current = null;if (commitTimeoutRef.current !== null) {clearTimeout(commitTimeoutRef.current);- }- commitTimeoutRef.current = setTimeout(() => {commitTimeoutRef.current = null;- const pendingCommit = pendingCommitRef.current;- pendingCommitRef.current = null;- if (pendingCommit !== null) {- onCommitRef.current(pendingCommit);- }- }, commitDelayMs);- },- [commitDelayMs, onCommit],- );+ }+ onCommit(normalizedValue);+ return;+ }++ pendingCommitRef.current = normalizedValue;+ if (commitTimeoutRef.current !== null) {+ clearTimeout(commitTimeoutRef.current);+ }+ commitTimeoutRef.current = setTimeout(() => {+ commitTimeoutRef.current = null;+ const pendingCommit = pendingCommitRef.current;+ pendingCommitRef.current = null;+ if (pendingCommit !== null) {+ onCommitRef.current(pendingCommit);+ }+ }, commitDelayMs);+ };const normalized = normalizeProviderAccentColor(optimisticValue);const picker = (