nosir / cleave.js

Format input text content when you are typing...
http://nosir.github.io/cleave.js
Apache License 2.0
17.95k stars 1.62k forks source link

Pasting to empty React instance results in error (excluding keyboard paste) #691

Open aduth opened 2 years ago

aduth commented 2 years ago

Steps to reproduce:

  1. Copy some text to your clipboard, like this: 1234
  2. Go to React JS demo page: https://jsfiddle.net/nosir/gLLsrxxf/
  3. Right click the first field in the preview, and click "Paste"

Expected: No errors in developer tools console. Actual: There's a console error:

cleave-react.min.js:8 Uncaught TypeError: Cannot read properties of undefined (reading 'slice')

In some initial debugging, it seems to be due to the fact that onChange calls Util.getPostDelimiter with owner.lastInputValue, but lastInputValue is undefined when first initialized. No errors are logged if you paste with keyboard (CmdV), but only because the combination of key presses incurs preceding keydown events which would ensure lastInputValue is assigned by the time onChange is invoked.