-
Notifications
You must be signed in to change notification settings - Fork 392
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
Conversation
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about focusin?
// 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!; |
There was a problem hiding this comment.
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!; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 })); |
There was a problem hiding this comment.
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')
?
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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 FocusEvent
s are composed.
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
3304eed
to
c95dde7
Compare
Benchmark resultsBase commit: lwc-engine-benchmark
|
Details
Fixes issue in firefox where native
focusout
events are notcomposed: true
Does this PR introduce a breaking change?