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(engine): forcing composed: true for focusout events #465

Merged
merged 5 commits into from
Jul 5, 2018

Conversation

davidturissini
Copy link
Contributor

Details

Fixes issue in firefox where native focusout events are not composed: true

Does this PR introduce a breaking change?

  • Yes
  • No

@caridy
Copy link
Contributor

caridy commented Jul 3, 2018

This is definitely a breaking change since existing events might be crossing the boundary today, and after this PR is merged, some of them might not cross it anymore.

get(this: FocusEvent) {
const { type, isTrusted } = this;
const composed = originalComposedGetter.call(this);
if (isTrusted && type === 'focusout' && composed === false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what about focusin?

@davidturissini
Copy link
Contributor Author

@caridy This branch is based on #462, which has the breaking changes. I had to base this off of that branch because I needed the getter in Event.prototype

// for `focusout` events
// This is defined here because we are guaranteed
// to have the composed polyfill applied to Event.
const originalComposedGetter = Object.getOwnPropertyDescriptor(Event.prototype, 'composed')!.get!;
Copy link
Contributor

Choose a reason for hiding this comment

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

we should definitely link to firefox issue, so we can remove this once they fix it.

// This is defined here because we are guaranteed
// to have the composed polyfill applied to Event.
// https://bugzilla.mozilla.org/show_bug.cgi?id=1472887
const originalComposedGetter = Object.getOwnPropertyDescriptor(Event.prototype, 'composed')!.get!;
Copy link
Member

Choose a reason for hiding this comment

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

What about adding the code to the existing polyfill or in another one?
I feel this code should not be part of the engine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The polyfill and this code are not solving the same problem. This code runs in environments where the polyfill isn’t needed.

Copy link
Member

Choose a reason for hiding this comment

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

Can we create another polyfill then? The same way we have the Safari Proxy fix?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I didn't realized that this code was here in def.ts. We should definitely move this to the outer folder in polyfill

get(this: FocusEvent) {
const { type, isTrusted } = this;
const composed = originalComposedGetter.call(this);
if (isTrusted && (type === 'focusout' || type === 'focusin') && composed === false) {
Copy link
Member

Choose a reason for hiding this comment

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

The focus should be applied to the all the events implementing the FocusEvent interface, not only focusin and focusout.

https://www.w3.org/TR/uievents/#events-focus-types

Copy link
Contributor Author

Choose a reason for hiding this comment

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

focus and blur events behave correctly

Copy link
Member

Choose a reason for hiding this comment

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

By not checking the type we can avoid the performance overhead of the branching.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to remove string comparisons!

}

handleButtonClick() {
this.template.querySelector('.custom-focus-out').dispatchEvent(new CustomEvent('focusout', { bubbles: true, composed: false }));
Copy link
Member

Choose a reason for hiding this comment

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

Can we also add a test for new FocusEvent('focusout')?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not supported in IE11, so I don’t think we support this

this.customEventNotComposed = evt.composed === false;
}

handleButtonClick() {
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if it's valuable to keep multiple tests since all the FocusEvents are composed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to ensure that users can still define a custom focus event with composed: false

@@ -355,6 +355,7 @@ export function getComponentDef(Ctor: ComponentConstructor): ComponentDef {
// Initialization Routines
import "../polyfills/proxy-concat/main";
import "../polyfills/event-composed/main";
import "../polyfills/focuse-event-composed/main";
Copy link
Member

Choose a reason for hiding this comment

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

focuse -> focus

@@ -0,0 +1,23 @@
// This must be run AFTER our event-composed polyfill
export default function () {
// Fix for FF not respecting spec'd composed flat
Copy link
Member

Choose a reason for hiding this comment

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

We should add a README.md explaining the issue with the link to FF bug like the other polyfill.

@@ -0,0 +1,3 @@
export default function () {
return true;
Copy link
Member

Choose a reason for hiding this comment

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

Why adding this polyfill by default, this should only be applied to Firefox. We should conditionally execute the polyfill for unsupported browsers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have no real way to detect this behavior.

Copy link
Member

Choose a reason for hiding this comment

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

I guess you are right, haven't found a way to test that out. In this case, I would also add a comment explaining why we can't gate the polyfill injection.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, once they fix this in FE, we can remove this. No worries.

@davidturissini davidturissini force-pushed the dturissini/ff-focus-out-composed branch from 3304eed to c95dde7 Compare July 3, 2018 23:44
@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 312bed0 | Target commit: 46367d2

lwc-engine-benchmark

table-append-1k metric base(312bed0) target(46367d2) trend
benchmark-table/append/1k duration 154.30 (± 5.60 ms) 153.10 (± 5.20 ms) 0.78% 👌
table-clear-1k metric base(312bed0) target(46367d2) trend
benchmark-table/clear/1k duration 12.40 (± 0.70 ms) 12.10 (± 0.50 ms) 2.42% 👌
table-create-10k metric base(312bed0) target(46367d2) trend
benchmark-table/create/10k duration 893.40 (± 5.70 ms) 869.20 (± 5.70 ms) 2.71% 👍
table-create-1k metric base(312bed0) target(46367d2) trend
benchmark-table/create/1k duration 103.30 (± 2.40 ms) 104.10 (± 1.70 ms) -0.77% 👌
table-update-10th-1k metric base(312bed0) target(46367d2) trend
benchmark-table/update-10th/1k duration 84.90 (± 4.70 ms) 87.50 (± 5.20 ms) -3.06% 👌
tablecmp-append-1k metric base(312bed0) target(46367d2) trend
benchmark-table-component/append/1k duration 222.70 (± 3.85 ms) 231.00 (± 4.30 ms) -3.73% 👎
tablecmp-clear-1k metric base(312bed0) target(46367d2) trend
benchmark-table-component/clear/1k duration 35.20 (± 2.20 ms) 36.90 (± 2.00 ms) -4.83% 👎
tablecmp-create-10k metric base(312bed0) target(46367d2) trend
benchmark-table-component/create/10k duration 1597.30 (± 9.20 ms) 1618.40 (± 12.45 ms) -1.32% 👎
tablecmp-create-1k metric base(312bed0) target(46367d2) trend
benchmark-table-component/create/1k duration 175.00 (± 3.10 ms) 175.20 (± 4.80 ms) -0.11% 👌
tablecmp-update-10th-1k metric base(312bed0) target(46367d2) trend
benchmark-table-component/update-10th/1k duration 79.70 (± 3.50 ms) 79.60 (± 4.80 ms) 0.13% 👌
wc-append-1k metric base(312bed0) target(46367d2) trend
benchmark-table-wc/append/1k duration 263.70 (± 12.80 ms) 275.00 (± 8.50 ms) -4.29% 👎
wc-clear-1k metric base(312bed0) target(46367d2) trend
benchmark-table-wc/clear/1k duration 37.40 (± 1.30 ms) 36.70 (± 1.20 ms) 1.87% 👌
wc-create-10k metric base(312bed0) target(46367d2) trend
benchmark-table-wc/create/10k duration 2066.50 (± 10.00 ms) 2137.50 (± 9.60 ms) -3.44% 👎
wc-create-1k metric base(312bed0) target(46367d2) trend
benchmark-table-wc/create/1k duration 216.50 (± 4.80 ms) 223.40 (± 4.20 ms) -3.19% 👎
wc-update-10th-1k metric base(312bed0) target(46367d2) trend
benchmark-table-wc/update-10th/1k duration 74.80 (± 5.00 ms) 79.10 (± 3.90 ms) -5.75% 👎

@davidturissini davidturissini merged commit 3c0a6cb into master Jul 5, 2018
@davidturissini davidturissini deleted the dturissini/ff-focus-out-composed branch July 5, 2018 17:24
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.

4 participants