jquense / react-big-calendar

gcal/outlook like calendar component
http://jquense.github.io/react-big-calendar/examples/index.html
MIT License
7.81k stars 2.23k forks source link

When selectable is true, click into calendar and press any key on keyboard at same time, this error appears. #2424

Open quanghuyTiPiCi opened 1 year ago

quanghuyTiPiCi commented 1 year ago

Check that this is really a bug

Reproduction link

https://codesandbox.io/s/gracious-panini-5jwfwq?file=/src/App.js

Bug description

When selectable is true, click into calendar and press any key on keyboard at same time, this error appears. Screenshot 2023-07-22 171140

Expected Behavior

No response

Actual Behavior

No response

react-big-calendar version

1.8.1

React version

18.2.0

Platform/Target and Browser Versions

Chrome, Firefox, etc...

Validations

Would you like to open a PR for this bug?

cutterbl commented 1 year ago

This error comes from using a string for a date property, instead of a true JS Date object. See our documentation on Understanding Dates

quanghuyTiPiCi commented 1 year ago

I used the correct JS Date object according to the documentation, but the error persists. Left click and any key in the same time. Version <= 0.39.7 work.

New-video image

cutterbl commented 1 year ago

That getDate error only shows if some date is not a JS Date, whether it's a calendar prop or an event's start or end, something is not a true JS Date

quanghuyTiPiCi commented 1 year ago

the example Selectable in the documentation also appears this error. Is it really a bug? image slots is undefined

cutterbl commented 1 year ago

@quanghuyTiPiCi I'm sorry. I see what you're doing now. Seeing the code you point out, it looks as if there may not be any slots defined here. I've reopened the bug. I'll take a look as soon as I'm able (unless anyone else has a moment to look).

brandonparis commented 1 year ago

Just here to +1 on this bug, took me a while to figure out what was happening but can confirm we're seeing this bug as well on v1.8.2

Pratik888800 commented 8 months ago

Not able to replicate the issue with the current version image_2024-01-19_135744972

quanghuyTiPiCi commented 8 months ago

when mouse down into calendar and press any keyboard button, this error will occur. image

LorienHW commented 7 months ago

we see this all the time - i think whats happening is that handleSelectSlot sets the _pendingSelection but then calls selectDates on a timer, and before selectDates executes something else calls clearSelection which empties out the _pendingSelection array. Maybe this means some other action is already in progress and so it would be ok to simply return early from selectDates if _pendingSelection is empty? @cutterbl

Edit: will submit a PR

forceddd commented 6 months ago

@cutterbl @LorienHW @quanghuyTiPiCi I think this is a Selector problem. When we hold down the left button and then press the keyboard, the Selector will emit the select event instead of the click event. But there is no selection area at this time, and then we get this error. In addition, the Selector does not clear the previous selection area, which creates another bug.

https://github.com/jquense/react-big-calendar/assets/63057542/b1f9a1e7-c26d-4abc-be77-7ccb8ce759ca

I modified some logic in the Selector. When this happens, the Selector will emit the click event, and every time it terminates, the previous state will be cleared. Can you check the PR to see if there are other problems? This is the effect after modification.

https://github.com/jquense/react-big-calendar/assets/63057542/c03de3cc-885f-41d5-85c3-f6cbc26acf25

LorienHW commented 6 months ago

the issue also repros just by clicking around a lot. the handleSelectSlot function sets the _pendingSelection and then uses a setTimeout to call the selectDates. Because its not called synchronously there is an opportunity for clearSelection to be called by something else (for example a key press), and empties out the _pendingSelection array. So I think either handleSelectSlot needs to call selectDates synchronously OR just make sure there is something in _pendingSelection before attempting to process it which is what my PR does. The change i submitted does fix the issue, and seems to work correctly. So I'd put it in as a safe guard anyway just to be sure - https://github.com/jquense/react-big-calendar/pull/2528