MetaMask / MetaMask/metamask-mobile
[Bug]: useSignatureRequest Hook Causing Excessive Selector Calls
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 1.7k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 669
Description
**Describe the bug**
There appears to be a significant performance issue related to the useSignatureRequest hook implementation. The issue causes excessive calls to selectors, particularly when interacting with signature requests like signTypedData at the MetaMask test dapp, where it was triggered 77 times for a single signature request.
**Problem**
- Excessive Calls: The useSignatureRequest hook is being called 77 times during a single signTypedData interaction, indicating a severe performance bottleneck.
- Multiple Components Using Hook: At least 22 components use this hook, creating a multiplicative effect where each component triggers the selector independently. ()
- Inefficient Selector Chain: The hook depends on both useApprovalRequest and selectSignatureRequestById, creating a chain of dependencies that can trigger unnecessary re-renders.
- Deep Selector Usage: Uses createDeepEqualSelector which performs deep equality checks that can be expensive for complex signature request objects.
- Lack of Memoization: The hook doesn't memoize its result, causing components to re-render even when the signature request hasn't changed.
**Expected behavior**
The useSignatureRequest hook should be called only when the signature request actually changes, not 77 times for a single interaction.
**Screenshots/Recordings**
**Steps to reproduce**
1. Open MetaMask test dapp
2. Initiate a signTypedData request
3. Monitor console logs and performance metrics
4. Observe 77 calls to useSignatureRequest hook
**Error messages or log output**
```shell
```
**Detection stage**
On main branch
**Version**
7.57.0
**Build type**
None
**Device**
Huawei P30 Lite
**Operating system**
Other (please elaborate in the "Additional Context" section)
**Additional context**
Shouldn't be OS specific but tested with Android.
**Performance Impact:**
- Affects all signature request flows (PersonalSign, EthSignTypedData)
- Multiple components are affected due to widespread hook usage
- Similar pattern may exist in other confirmation hooks
Contributor guide
Assessment
This issue has not been assessed yet.