Skip to content

Commit 22c9e54

Browse files
fix(a11y): guard parseUnits in BigNumberInput sync effect against throws
An intermediate/unparseable input string while the user is typing could cause the useEffect that syncs the DOM value on external prop changes to throw. Wrap parseUnits in a try/catch and use a sentinel value to force the DOM overwrite when the current string is not parseable.
1 parent 3b7b376 commit 22c9e54

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/components/sharedComponents/BigNumberInput.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,15 @@ export const BigNumberInput: FC<BigNumberInputProps> = ({
7575
if (!current) {
7676
return
7777
}
78-
const currentInputValue = parseUnits(current.value.replace(/,/g, '') || '0', decimals)
78+
// The input may contain an intermediate/unparseable string while the user is
79+
// typing; guard against a parseUnits throw so an external value update never
80+
// crashes the effect.
81+
let currentInputValue: bigint
82+
try {
83+
currentInputValue = parseUnits(current.value.replace(/,/g, '') || '0', decimals)
84+
} catch {
85+
currentInputValue = BigInt(-1) // sentinel: force the DOM value to be overwritten
86+
}
7987

8088
if (currentInputValue !== value) {
8189
current.value = formatUnits(value, decimals)

0 commit comments

Comments
 (0)