From 7e59802b4577b03ac3eadd2f10fa95026da86d8f Mon Sep 17 00:00:00 2001 From: Victor Oliva Date: Tue, 31 Mar 2026 13:07:13 +0200 Subject: [PATCH] fix: remove flicker on custom icons --- src/components/BinaryEditButton.tsx | 4 ++-- src/components/BinaryInput.tsx | 3 ++- src/components/Icons.tsx | 21 ++++++++++----------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/components/BinaryEditButton.tsx b/src/components/BinaryEditButton.tsx index 9a282ba..caf45fb 100644 --- a/src/components/BinaryEditButton.tsx +++ b/src/components/BinaryEditButton.tsx @@ -6,7 +6,7 @@ import { Modal } from "@/components/Modal" import { useGenericSynchronizeInput } from "@/components/useSynchroniseInput" import { NOTIN } from "@polkadot-api/react-builder" import { Download, FileUp } from "lucide-react" -import { ComponentProps, FC, useMemo, useState } from "react" +import { ComponentProps, FC, useCallback, useMemo, useState } from "react" import { twMerge } from "tailwind-merge" // @ts-expect-error save-as typings not available import { saveAs } from "save-as" @@ -37,7 +37,7 @@ export const BinaryEditButton: FC< "cursor-pointer hover:text-polkadot-500", iconProps?.className, )} - onClick={() => setOpen(true)} + onClick={useCallback(() => setOpen(true), [])} /> setOpen(false)} /> diff --git a/src/components/BinaryInput.tsx b/src/components/BinaryInput.tsx index 3c71c90..d7289a5 100644 --- a/src/components/BinaryInput.tsx +++ b/src/components/BinaryInput.tsx @@ -2,12 +2,12 @@ import { byteArraysAreEqual } from "@/utils/byteArray" import { NOTIN } from "@polkadot-api/react-builder" import { Binary } from "@polkadot-api/substrate-bindings" import { FileUp } from "lucide-react" +import { fromHex, toHex } from "polkadot-api/utils" import { FC, useState } from "react" import { twMerge } from "tailwind-merge" import { SwitchBinary } from "./Icons" import { TextInputField } from "./TextInputField" import { useGenericSynchronizeInput } from "./useSynchroniseInput" -import { fromHex, toHex } from "polkadot-api/utils" export const BinaryInput: React.FC<{ encodedValue: Uint8Array | NOTIN @@ -88,6 +88,7 @@ export const BinaryInput: React.FC<{ setLocalInput(toHex(Binary.fromText(inputValue))) } }} + tabIndex={-1} > diff --git a/src/components/Icons.tsx b/src/components/Icons.tsx index 2eebc60..2760f67 100644 --- a/src/components/Icons.tsx +++ b/src/components/Icons.tsx @@ -12,7 +12,7 @@ import { LucideProps, User, } from "lucide-react" -import { FC, useEffect, useRef } from "react" +import { FC, useCallback, useEffect, useRef } from "react" import { Props, ReactSVG } from "react-svg" import { twMerge } from "tailwind-merge" import binarySvg from "./icons/binary.svg" @@ -36,17 +36,16 @@ const CustomIcon: FC< ref.current.setAttribute("height", String(size)) }, [size]) - return ( - { - ref.current = svg - svg.setAttribute("width", String(size)) - svg.setAttribute("height", String(size)) - }} - /> + const beforeInjection = useCallback( + (svg: SVGSVGElement) => { + ref.current = svg + svg.setAttribute("width", String(size)) + svg.setAttribute("height", String(size)) + }, + [size], ) + + return } const customIcon = (url: string) => (props: CustomIconProps) => (