-
Notifications
You must be signed in to change notification settings - Fork 393
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
(engine-restrictions) Lift restrictions on addEventListener's options param for host element #1824
Comments
FYI, this is probably just moving the following block: lwc/packages/@lwc/engine/src/framework/restrictions.ts Lines 338 to 370 in 9e19ce5
to
|
This issue has been linked to a new work item: W-7446526 |
I'd have to dig in a little more but giving users the ability to subscribe to the capture phase of |
Looks like we only restrict this for the host element: |
When introducing support for options, we'll also need to update the existing logic to prevent multiple listeners for the same event since we currently only consider the identity of the listener function. Some points to consider when determining whether a listener is "identical":
|
Hello, there. I'm also seeing this behavior in our project. I am using LWCs as web components in my app and would like to use the third optional parameter when binding event listeners to them. When running in development mode the LWC runtime throws an error for each usage. @pmdartus |
Updated repro using StackBlitz for posterity FWIW it seems to log an error, not throw an error. |
I just ran into this issue when trying to use LWC in Storybook 7, which requires |
@fafnirical Is the issue just that it's logging an error? Or is there an actual functional difference? |
@nolanlawson There's an actual functional difference. In addition to the logged error (
The source of the error is https://github.com/salesforce/lwc/blob/v2.43.0/packages/@lwc/synthetic-shadow/src/faux-shadow/events.ts#L210-L214 And the code for the story: /// myLwcComponent.stories.ts
import { html } from 'lit-html';
const handleEvent = (e: CustomEvent) => console.log(e);
export const example = () => html`<my-lwc-component @changesegment=${handleEvent}></my-lwc-component>`; |
I see, so this is a synthetic shadow issue. Synthetic shadow is deprecated, and we had not planned to make any changes to it. But I can understand if you cannot remove synthetic shadow from your storybook testing. |
Ah, I also just noticed that this error is only thrown in non-prod mode. Maybe we should tie this into #3245 then. lwc/packages/@lwc/synthetic-shadow/src/faux-shadow/events.ts Lines 208 to 216 in 3770a62
|
@fafnirical Actually, I don't understand how you're hitting this error. Your error message is:
How is the second argument to |
Nevermind, I get it. The second argument can be an object with a |
This issue only logs a warning, it doesn't throw an error. Adding to our trust backlog. |
This issue has been linked to a new work item: W-15704155 |
Description
Adding an event listener on the custom element with a third
options
argument logs an error.This restriction should be on the component instance and not on the host element. From the outside world, a DOM element should behave per spec when
addEventListener
is invoked with the options param, regardless of whether the element is a standard html element or a native custom element or an LWC host element.Steps to Reproduce
https://playground.lwcjs.org/projects/d1fzv_d_h/3/edit
Reference: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
The text was updated successfully, but these errors were encountered: