Skip to content

chore: bump react-hook-form, @hookform/resolvers, yup#18704

Merged
Lemonexe merged 2 commits intodevelopfrom
bump-react-hook-form-et-al
May 6, 2025
Merged

chore: bump react-hook-form, @hookform/resolvers, yup#18704
Lemonexe merged 2 commits intodevelopfrom
bump-react-hook-form-et-al

Conversation

@Lemonexe
Copy link
Copy Markdown
Contributor

@Lemonexe Lemonexe commented May 2, 2025

Description

Replacement for closed #18677, because I needed to rename branch (if you're curious, see #18700)

  • b4cce0a Bump react-hook-form and related packages (because they're QA'd together).
  • b62f02b Mobile Trade form: Fix infinite render loop occurring only in unit tests by not resetting form when you select the same asset or currency
    • IMHO this also enhances the UX slightly 🙂

Related Issue

Resolve #18090

Screenshots

Mobile trading form: don't reset amounts when asset or fiat currency is changed to the same one:
mobile trading form reset.webm

🔍🖥️ Suite web test results: View in Currents

🔍🖥️ Suite desktop test results: View in Currents

🔍🖥️ Suite native android test results: View in Currents

@Lemonexe Lemonexe added mobile Suite Lite issues and PRs send Send page trading Related to Trading labels May 2, 2025
isElectrum?: boolean;
};

const signVerifySchema: yup.ObjectSchema<SignVerifyFields> = yup.object({
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solve TS error at L76 (string | undefined not assignable to string for path, signature)

The problem arose when bumping @hookform/resolvers + react-hook-form, and then bumping yup did not help.
It took me a while to realize that the former two are not at fault, it's yup that was insufficiently typed (in both versions I tried!), and react-hook-form merely tightened its types to catch that.

dispatch(
setBuySelectedReceiveAccount({ selectedReceiveAccount: undefined }),
);
}
Copy link
Copy Markdown
Contributor Author

@Lemonexe Lemonexe May 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only clear the cryptoValue | fiatValue field when you really selected a different asset, or different fiatCurrency.

This fixes an infinite render loop, that only manifested in @testing-library/react-native unit tests
(the app worked fine)

Note: I spend considerably time debugging this, trying to find the real root cause why this started happening after bumping react-hook-form to 7.55. I did not succeed 😞
This whole form is very complex, with a lot of watch→setValue interactions that are rather difficult to trace. I tried disabling many such interactions, and validations, to at least see if I can break the cycle, but to no avail. I also tried:

  • wrapping the hook in renderHookWithStoreProviderAsync in a FormProvider
  • mocking useDebounce
  • any of the three setValues here in cases 'fiatCurrency' and 'asset' are enough to crash
  • in the useQuotes.test, this line is enough to crash (without the other setValues)

This issue sounds relevant, but I reproduced the same crash even in 7.55, not just 7.56

@Lemonexe Lemonexe marked this pull request as ready for review May 2, 2025 17:38
@Lemonexe Lemonexe requested review from a team as code owners May 2, 2025 17:38
const useAmountAndCurrencyFieldsChangeEffect = ({ setValue, getValues, watch }: TradingBuyForm) => {
const dispatch = useDispatch();
const prevNetworkId = useRef<string | undefined>(undefined);
const prevCryptoId = useRef<CryptoId | undefined>(undefined);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using cryptoId I can distinguish tokens of the same network and solve #18677 (review)

Copy link
Copy Markdown
Contributor

@jbazant jbazant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mobile Trade part looks great. Thank you for the solution.

@Lemonexe Lemonexe merged commit b54709a into develop May 6, 2025
88 checks passed
@Lemonexe Lemonexe deleted the bump-react-hook-form-et-al branch May 6, 2025 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mobile Suite Lite issues and PRs send Send page trading Related to Trading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bump react-hook-form & @hookform/resolvers

4 participants