Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix __addScrollListeners for polyfilled browsers #263

Merged
merged 1 commit into from
Feb 9, 2018
Merged

Fix __addScrollListeners for polyfilled browsers #263

merged 1 commit into from
Feb 9, 2018

Conversation

limonte
Copy link
Contributor

@limonte limonte commented Feb 8, 2018

The comment above the line I changed says:

Listen for scroll events in all shadowRoots hosting this overlay only when in native ShadowDOM

It's not possible to detect the native ShadowDOM by checking only 'attachShadow' in Element.prototype && 'getRootNode' in Element.prototype:

Firefox IE11

@limonte
Copy link
Contributor Author

limonte commented Feb 8, 2018

@valdrinkoshi I would recommend you to set up your editor to auto-trim trailing whitespaces, e.g. the setting for VS Code: https://stackoverflow.com/a/30884298/1331425

For now, it'd be easier to do CR with whitespaces diff disabled: https://github.com/PolymerElements/iron-overlay-behavior/pull/263/files?w=1

Copy link
Member

@valdrinkoshi valdrinkoshi left a comment

Choose a reason for hiding this comment

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

Hi @limonte thanks for the contribution!

It's not clear what issue the current implementation is creating, mind filing it so we can discuss it? I tried skimming through predixdesignsystem/px-data-grid#331, but couldn't understand the scenario: looks like the problem is that with ShadyDOM we trigger twice the __onCaptureScroll, but not clear to me why is that a problem.

Also, this PR needs a test to avoid future regressions.
I left some comments to the current implementation in the meantime 👌

@@ -645,7 +645,7 @@
this.__rootNodes = [];
// Listen for scroll events in all shadowRoots hosting this overlay only
// when in native ShadowDOM.
if ('attachShadow' in Element.prototype && 'getRootNode' in Element.prototype) {
if (!window.ShadyDOM && 'attachShadow' in Element.prototype && 'getRootNode' in Element.prototype) {
Copy link
Member

Choose a reason for hiding this comment

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

This won't be compatible with polymer 1.x (as it depends on webcomponents v0 which is not implemented with ShadyDOM). This whole check could be replaced with:

if (Polymer.Settings.useShadow) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

scrollable = f.$.scrollable;
overlay = f.$.overlay;
});
if (!window.ShadyDOM) {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of having this if wrapping the whole suite, you can use suiteSetup and skip the whole suit:

suite('scroll actions in shadow root', function() {
  suiteSetup(function() {
    if (!Polymer.Settings.useShadow) {
      this.skip();
    }
  });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍


suite('scroll actions in shadow root, overlay distributed', function() {
suite('scroll actions in shadow root, overlay distributed', function() {
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, you can use suiteSetup

suite('scroll actions in shadow root, overlay distributed', function() {
  suiteSetup(function() {
    if (!Polymer.Settings.useShadow) {
      this.skip();
    }
  });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

@limonte
Copy link
Contributor Author

limonte commented Feb 8, 2018

It's not clear what issue the current implementation is creating, mind filing it so we can discuss it? I tried skimming through predixdesignsystem/px-data-grid#331, but couldn't understand the scenario: looks like the problem is that with ShadyDOM we trigger twice the __onCaptureScroll, but not clear to me why is that a problem.

In px-data-grid component we have px-dropdown which extends iron-dropdown which extends iron-overlay-behavior. The issue was that once px-dropdown is opened in Firefox or IE11 the scrolling in px-data-grid stops working. Here's the gif:

peek 2018-02-08 22-34

What happens here is basically that scroller component stops firing 'scroll' events. After a lot of digging, I found this issue in checking for native Shadow DOM which fixes the px-data-grid's issue and I guess a lot of scrolling issues.

Also, this PR needs a test to avoid future regressions.

I'm not sure what should I test in this case, could you please help me with the idea how to perform the test?

Thanks a lot for the quick and great feedback!

@valdrinkoshi
Copy link
Member

I tried install the version in master and play with it locally:
px-data-grid-scroll

I noticed that the scroll is not blocked when I scroll with the trackpad (not with the scroll handler, through the pointer). I think that should be locked no matter what, so there seems to be something going on with scroll handling there. It would be helpful to have a smaller repro, e.g. this doesn't happen in the demo page of iron-overlay-behavior https://www.webcomponents.org/element/PolymerElements/iron-overlay-behavior/demo/demo/index.html
iron-overlay-behavior-scroll

@limonte
Copy link
Contributor Author

limonte commented Feb 8, 2018

I noticed that the scroll is not blocked when I scroll with the trackpad (not with the scroll handler, through the pointer). I think that should be locked no matter what, so there seems to be something going on with scroll handling there.

There's actually no handling there, because there's nothing to handle, 'scroll' events are stolen by iron-overlay-behavior:

peek 2018-02-08 23-14

@valdrinkoshi
Copy link
Member

valdrinkoshi commented Feb 8, 2018

iron-overlay-behavior doesn't stop scroll events propagation, that seems to be done in vaadin-grid components. I noticed that vaadin-grid-scroll-mixin stops scroll propagation, while vaadin-grid-outer-scroller does restore the scroll position on scroll.

My understanding is that you want <iron-dropdown> to lock scrolling when is vertical, and allow it when it's horizontal, is this correct?

Currently, <iron-dropdown> blocks scrolling. You can either set the allowOutsideScroll=true or scrollAction="refit" to have the <iron-dropdown> refit when scrolls happens, or set the property scrollAction="cancel" to have the dropdown cancel (aka close) on scroll.

For any other custom behavior, consider toggling allowOutsideScroll or scrollAction at appropriate times.

@limonte
Copy link
Contributor Author

limonte commented Feb 9, 2018

Even after adding allowOutsideScroll to all iron-dropdowns (predixdesignsystem/px-data-grid#635), the issue is still the same.

@valdrinkoshi
Copy link
Member

valdrinkoshi commented Feb 9, 2018

oh! This is a bug of ShadyDOM, where shadowRoot.removeEventListener doesn't actually remove the listener - webcomponents/shadydom#190
See
removeeventlistener

Copy link
Member

@valdrinkoshi valdrinkoshi left a comment

Choose a reason for hiding this comment

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

Even when webcomponents/shadydom#190 will be fixed, I still think this PR would make iron-overlay-behavior more performant by avoiding to add scroll event listeners when those are not needed.

I don't think there is an easy way to write a test for this, so I'll merge it as is.

Thanks @limonte again for guiding me through the scenario and your contribution 👍

@valdrinkoshi valdrinkoshi merged commit d5ea8e8 into PolymerElements:master Feb 9, 2018
@limonte
Copy link
Contributor Author

limonte commented Feb 10, 2018

Thanks for your prompt review @valdrinkoshi!

Can we expect the patch release of iron-overlay-behavior soon so we can close predixdesignsystem/px-data-grid#331?

@valdrinkoshi
Copy link
Member

right, 2.3.2 released 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants