arqex / react-datetime

A lightweight but complete datetime picker react component.
1.99k stars 873 forks source link

Component crashes hard if input value does not match expected date format #801

Closed niklasnatter closed 2 years ago

niklasnatter commented 2 years ago

I'm Submitting a ...

[x] Bug report
[ ] Feature request
[ ] Support request

Steps to Reproduce

  1. Render the <Datetime /> with the value prop
  2. Change the value prop to something that does not match the expected date format

Expected Results

The error should be logged to the console, but the component should not crash hard.

Actual Results

An error is thrown and the component crashes hard.

Minimal Reproduction of the Problem

Runnable example on stackblitz.com

Other Information (e.g. stacktraces, related issues, suggestions how to fix)

The setViewDate method accesses a log function that does not exist anymore. The log function was moved outside the class in https://github.com/arqex/react-datetime/commit/d4450038cd901f1e0f31bcd365448820f60c6f67#diff-cae892f0886b91915576f17fd54c818f7ef44b721a3885d4a742039f1c8cad03L557-R611. https://github.com/arqex/react-datetime/blob/4e880f2167789867d6074a655c18c16717a92e49/src/DateTime.js#L534-L537

Stacktrace

Screenshot 2021-09-06 at 11 42 37

johnhunter commented 2 years ago

Same here 😞

niklasnatter commented 2 years ago

I think that this problem was introduced in version 3.1.0, which was released a few days ago. I have created a pull request to fix the issue here https://github.com/arqex/react-datetime/pull/803

If you run into this problem in your project, you can use the following version constraint in your package.json as a workaround. The workaround will prevent npm from installing the newly released version that contains the problem.

"react-datetime": ">=3.0.0 <3.1.0 || ^3.1.1"
johnhunter commented 2 years ago

Thanks, I hope it gets merged and published soon. Shame tests don't cover this.

arqex commented 2 years ago

Sorry about it guys! It should be fixed in v3.1.1 that has just been released.

The cause was a half baked refactor that got into the master branch as part of the last version. @johnhunter is right, I should add this case to the tests soon.

niklasnatter commented 2 years ago

Dont worry - thanks for the fast release, we are really appreciating this! 🙂 Hope you are having a good day!