RangeError: Invalid string length #49943
Labels
Needs: Attention
Issues where the author has responded to feedback.
Needs: Repro
This issue could be improved with a clear list of steps to reproduce the issue.
Description
Getting "RangeError: Invalid string length" after react-native version upgrade to 0.78 while executing test cases.
` RangeError: Invalid string length
Test case :
Screen :
`export type RegistrationFormData = {
email: string
password: string
confirmPassword: string
firstName: string
dateOfBirth: string
}
export type RegistrationFormDataKeys = keyof RegistrationFormData
export type RegistrationFormScreenProps = {
onHeaderPressClose: () => void
afterRegister: (regToken: string, firstName: string) => void
}
export const RegistrationFormScreen: React.FC = ({
onHeaderPressClose,
afterRegister,
}) => {
const { t } = useTranslation()
const [loading, setLoading] = useState(false)
const dispatch = useDispatch()
const { buildTestId } = useTestIdBuilder()
const form = useForm({
shouldFocusError: false,
resolver: zodResolver(
z
.object({
email: EMAIL_SCHEMA(t, true),
password: z.string().trim().min(1),
confirmPassword: z.string().trim().min(1),
firstName: z.string().optional(),
dateOfBirth: DATE_SCHEMA(t).optional(),
})
.refine(data => data.password === data.confirmPassword, {
path: ['confirmPassword'],
message: t('form_error_different_from_password'),
}),
),
})
useFocusErrors(form)
const { setErrors } = useValidationErrors(form)
const onSubmit = form.handleSubmit(async data => {
setLoading(true)
try {
const accountsRegisterResponse = await dispatch(register(data)).unwrap()
afterRegister(accountsRegisterResponse.regToken, accountsRegisterResponse.profile.firstName)
form.reset()
} catch (error: unknown) {
if (error instanceof CdcStatusValidationError) {
setErrors(error)
} else if (error instanceof ErrorWithCode) {
ErrorAlertManager.current?.showError(error)
} else {
logger.warn('account register error cannot be interpreted', JSON.stringify(error))
ErrorAlertManager.current?.showError(new UnknownError('Register'))
}
} finally {
setLoading(false)
}
})
return (
<ModalScreen whiteBottom testID={buildTestId('registration_form')}>
<ModalScreenHeader
titleI18nKey="registration_form_headline"
testID={buildTestId('registration_form_headline')}
onPressClose={onHeaderPressClose}
/>
<FormFieldWithControl
name={'email'}
component={TextFormField}
labelI18nKey="registration_form_email"
testID={buildTestId('registration_form_email')}
control={form.control}
autoCapitalize="none"
autoComplete="email"
autoCorrect={false}
keyboardType="email-address"
isRequired
disableAccessibilityForLabel
textContentType="username"
/>
<FormFieldWithControl
name={'password'}
component={PasswordFormField}
labelI18nKey="registration_form_password"
testID={buildTestId('registration_form_password')}
control={form.control}
isRequired
disableAccessibilityForLabel
textContentType="password"
registrationScenario
/>
<FormFieldWithControl
name={'confirmPassword'}
component={PasswordFormField}
labelI18nKey="registration_form_confirmPassword"
testID={buildTestId('registration_form_confirmPassword')}
control={form.control}
isRequired
disableAccessibilityForLabel
textContentType={Platform.OS === 'ios' ? 'oneTimeCode' : 'newPassword'}
registrationScenario
/>
<FormFieldWithControl
name={'firstName'}
component={TextFormField}
labelI18nKey="registration_form_firstName"
testID={buildTestId('registration_form_firstName')}
control={form.control}
disableAccessibilityForLabel
/>
<FormFieldWithControl
name={'dateOfBirth'}
component={DateFormField}
labelI18nKey="registration_form_dateOfBirth"
testID={buildTestId('registration_form_dateOfBirth')}
control={form.control}
disableAccessibilityForLabel
displayMandatoryFieldHint
/>
<Button
disabled={!form.formState.isDirty}
testID={buildTestId('registration_form_submit')}
i18nKey="registration_form_submit"
onPress={onSubmit}
/>
)
}
`
Steps to reproduce
Run test case
React Native Version
0.78.0
Affected Platforms
Build - MacOS
Output of
npx @react-native-community/cli info
Stacktrace or Logs
Reproducer
Please check this repo - https://github.com/vinvijdev/IssueReproducer
Run - yarn test src/screens/account/registration/registration-form-screen.test
Screenshots and Videos
No response
The text was updated successfully, but these errors were encountered: