react-input-mask icon indicating copy to clipboard operation
react-input-mask copied to clipboard

Autofill on iOS (Chrome, Safari) causes infinite loop and crashes the application

Open zozich opened this issue 6 years ago • 6 comments

When I try to autofill any value into phone input created via ReactInputMask, it crashes the application. This is the error we receive in console on production: https://reactjs.org/docs/error-decoder.html/?invariant=185

This is how InputMask is called from parent:

<InputMask
        mask='(99) 999-99-99'
        type='tel'
        alwaysShowMask
        fontSize={fontSize}
        phoneChanged={phoneChanged}
        value={(getValue() || '').substring(code.length)}
        name='phone-suffix'
      />

And this is how it looks inside:

function InputMask(props) {
  const { mask, maskChar, formatChars, alwaysShowMask, fontSize, phoneChanged, name, ...rest } = props;

  return (
    <ReactInputMask
      mask={mask}
      maskChar={maskChar}
      formatChars={formatChars}
      alwaysShowMask={alwaysShowMask}
      onChange={phoneChanged}
      {...rest}
    >
      {(inputProps) => (
        <TextInput
          fontSize={fontSize}
          name={name}
          {...inputProps}
        />
      )}
    </ReactInputMask>
  );
}

Reproducible only on iOS

zozich avatar Nov 30 '19 01:11 zozich

Faced the same issue in Chrome iOS Credit card mask 9999 9999 9999 9999 Application crashes when autocomplete

therealsqvad avatar Dec 04 '19 16:12 therealsqvad

@therealsqvad This is where I migrated instead and what solves the issue https://github.com/s-yadav/react-number-format

zozich avatar Dec 11 '19 15:12 zozich

FWIW this appears to be fixed in the latest alpha of 3.0. I reproduced it with the latest stable release in a CodeSandbox then updated to the latest alpha and don't see that error anymore.

https://codesandbox.io/s/maskedinputcomparisons-libhi

joefiorini avatar Jan 24 '20 17:01 joefiorini

Was facing same issue and found that forgot to pass the value prop to the mask.

mfaheemakhtar avatar Sep 24 '21 06:09 mfaheemakhtar

Just reproduced this same issue on iOS only.

gkelley avatar Jan 10 '22 21:01 gkelley

Same thing here. I managed to fix the crash by passing maxLength={5} to the expiary date element. It should help you

ornakash avatar Feb 23 '23 14:02 ornakash