Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

Shadydom enforces capturing phase in IE 11 #289

Closed
1 of 6 tasks
attilapuskas opened this issue Oct 15, 2018 · 2 comments
Closed
1 of 6 tasks

Shadydom enforces capturing phase in IE 11 #289

attilapuskas opened this issue Oct 15, 2018 · 2 comments
Projects

Comments

@attilapuskas
Copy link
Contributor

Description

If the event listeners are added via properties (like in GWT for example) then using shadydom in IE 11 could cause several issues because the events will use the capturing phase logic and not the default/expected bubbling phase.

Live Demo

https://jsbin.com/tojafuvowo/1/edit?html,js,output

Steps to Reproduce

  1. Create "outer" and "inner" element so that inner is a descendant of outer.
  2. Add event listener using properties, for example onmousedown.

Expected Results

Triggering a related event should be dispatched first on the children if that was the target.

Actual Results

The event is dispatched first on parent (capturing phase).

Browsers Affected

  • Chrome
  • Firefox
  • Edge
  • Safari 9
  • Safari 8
  • IE 11

Versions

  • webcomponents/shadydom: v1.1.0 and above (it is not reproducible in 1.0.14)
@attilapuskas
Copy link
Contributor Author

attilapuskas commented Oct 16, 2018

Strange thing but removing the empty object from that line solves the issue. As I've debugged it the optionsOrCapture is handled properly in the patch-events.js but still IE 11 somehow uses capturing phase if it is used.

The following test should be ok for that. I'll create a PR if I found time for that soon.

    test('should use bubbling phase for event listeners added via properties', function () {
      const parent = document.createElement('div');
      parent.id="parent";
      document.body.appendChild(parent);
      const child = document.createElement('div');
      child.id="child";
      parent.appendChild(child);

      const parentMouseDownSpy = sinon.spy();
      const childMouseDownSpy = sinon.spy();

      parent.onmousedown = parentMouseDownSpy;
      child.onmousedown = childMouseDownSpy;

      child.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, composed: true }));

      assert.isTrue(childMouseDownSpy.calledBefore(parentMouseDownSpy), 'Event handler on child should be called first');
    });

@web-padawan
Copy link
Contributor

web-padawan commented Oct 16, 2018

Yeah, that empty object forces capture phase in browsers not supporting event listener options.
Looks like the intervention for passive event listeners strikes again.

@dfreedm dfreedm added this to Inbox in Polyfills Mar 18, 2019
Polyfills automation moved this from Inbox to Done May 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
No open projects
Polyfills
  
Done
Development

No branches or pull requests

2 participants