这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@DanielRuf
Copy link
Contributor

No description provided.

@DanielRuf DanielRuf requested a review from amsul March 14, 2019 14:34
Copy link
Owner

@amsul amsul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Just some minor things to address 👍

lib/picker.js Outdated
event.preventDefault()
P.open()
})
}, 300))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

300 seems rather long..if it's a race condition introduced in Chrome 73, I can't imagine it would need that long 🤔

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add a comment here as to why it's debounced (with a reference to the issue).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, which value would you recommend? 100ms or lower?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would assume that since it's a race condition at the browser level, we wouldn't need anything more than a few milliseconds. To be safe, I think just 50ms should be sufficient. At 100ms, it starts to impact the experience minutely.

@DanielRuf
Copy link
Contributor Author

I have applied the proposed changes. When we are ready to merge I will squash the commits into one.

@amsul
Copy link
Owner

amsul commented Mar 15, 2019

@DanielRuf I think we're ready to merge em in. We can ship a new build for 3.6.1 after.

@DanielRuf
Copy link
Contributor Author

I'll do the change to 50 instead of 100 ms and then squash the commits

@DanielRuf DanielRuf force-pushed the fix/1138-debounce-open branch from 4899c87 to 9282a80 Compare March 15, 2019 21:27
@DanielRuf
Copy link
Contributor Author

Ready to be merged. Thanks for the feedback.

@colinhowe
Copy link
Contributor

colinhowe commented Mar 27, 2019

Hi, we've just hit this on our site. Using the most recent version of pickadate we're seeing that the close event is being fired immediately after opening ~50% of the time. If you want to replicate it consistently you need to do a long click on the input box (which explains why it happens 50% of the time). When the click is fired it is using the input box as the target element and totally ignoring the new element that has appeared.

You can see this behaviour on the demo site: https://amsul.ca/pickadate.js/

This behaviour only started in Chrome 73 and is not present in Safari 12.0.3.

The dirty fix that springs to mind is to have the open handler register whether the opening click has completed or not. If the click has not been completed then the close handler should do a no-op.

Edit: further debugging has shown that on a slow click the focus event is fired followed by a click event on mouse up. On a normal click just the click event is fired once and so gets handled correctly.

@DanielRuf
Copy link
Contributor Author

Hi @colinhowe, please read the PR and the comments and see the changes. This is a regression in Chrome. This PR is just a workaround to fix it.

@DanielRuf
Copy link
Contributor Author

@DanielRuf
Copy link
Contributor Author

This behaviour only started in Chrome 73 and is not present in Safari 12.0.3.

Because webKit !== Chromium ;-)

@colinhowe
Copy link
Contributor

I realise that about Safari. It was more to give additional context. Anyway, I've tracked down what has happened in Chromium. I'll raise a PR as I believe the issue we're seeing is different to this one.

@DanielRuf
Copy link
Contributor Author

No, it is the exact same issue which is fixed by this PR.

@DanielRuf
Copy link
Contributor Author

Please try the patch / changes of this PR.

@colinhowe
Copy link
Contributor

I am using master which contains this PR. It is not the exact same issue. You can replicate on your own demo page which is also running this PR.

  1. Go to https://amsul.ca/pickadate.js/
  2. Click and hold on the picker
  3. Release

Expected behaviour: calendar stays open
Actual behaviour: it closes

@DanielRuf
Copy link
Contributor Author

  • Click and hold on the picker
  • Release

No one does this. You have to increase the timeout to dethrottle it. The cause is still the same.

@colinhowe
Copy link
Contributor

The website uses 3.6.2 - I did check before sending you the instructions.

The instructions are purposefully exaggerated. All you have to do is be slow enough between mousedown and mouseup to trigger a DOM change. I figured saying 'click for ~50ms' would be less helpful.

As a general fyi, older people do use the internet. They do click slowly.

@gregblass
Copy link

FYI - I just had a client let me know that on some slower machines, 100ms doesn't seem to be enough to do the trick.

@DanielRuf
Copy link
Contributor Author

@gregblass we are aware of it and there is an open issue which tries a different workaround.

@gregblass
Copy link

Got it! Hey would you mind linking me to that?

@DanielRuf
Copy link
Contributor Author

See #1145

@ivanvgh
Copy link

ivanvgh commented Jun 7, 2020

@DanielRuf I'm sorry. I should have been more active and send the patches to these repos myself. I also got this datepicker and slider repo which I recall I had discussion with you about confused.

Anyhow, the quick fix for this one will be just asking the UA to route the up events to the same input elements that started this with so that the logic of dismissing the popup due to the click handler doesn't get triggered. So before I send the patch and the real fix, could you load this page. I assume this still has the bad behavior here (i.e. popup closing if the user does a long click). Is that right? I'm not familiar with the versioning of this library but I just want to make sure we test the patch on a live example that does show the problem.

Now just open the devtools and paste this code:

document.querySelector('.picker__input').addEventListener('pointerdown', e=>e.target.setPointerCapture(e.pointerId));

It should fix the problem for the first date picker. Do you see any problem after this patch to that page?

You are rigth, but I think this will fix the whole problem:
document.querySelectorAll('.datepicker').forEach(t => t.addEventListener('mousedown', e=>e.preventDefault()));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants