-
Notifications
You must be signed in to change notification settings - Fork 313
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
Issue a devtool warning if WorkerGlobalScope#addEventListener is called after intial execution #195
Comments
We've definitely seen developers shoot themselves in the foot this way with Chrome event pages, so +1 to making this restriction. You could imagine that the UA might skip starting a SW if it hasn't registered a listener for a particular event, and that the SW's author might try to optimize that startup process by registering listeners conditionally depending on how the user has configured them. Given SW's lack of synchronous storage APIs, there's no way to do that during the initial execution, so by banning this, I think we'd be giving up on that possible optimization. I think that's worth it, at least until the need becomes compelling. |
@jakearchibald Naive question: I could not understand why this is marked as an enhancement... Wouldn't we break folks who relied on the non throwing behavior or the optimization that jyasskin highlights? Background: I'm going over the remaining opened issue to assess potential impact on our current implementation. |
If we are defining something completely different from events, we should name these things somewhat differently imo. |
Maybe the wrong label. Removed it.
We're only in Canary at the moment. I don't know if anyone is relying on the non-throwing behaviour, but we're changing lots of APIs day-to-day, I don't think it's a problem.
Given how serviceworkers can be terminated at any time and spun up just in time to fire an event, I can't see how async listening would be a performance benefit.
They're not completely different. You use subscribe to a thing that happens and get the opportunity to react, in some cases alter the default action. Due to the way serviceworker can terminate and start up at will, a listener attached after the initial execution is going to get lost. |
I think they are different enough. What you are defining here requires all kinds of special casing for which there are no hooks in the basic eventing system. |
@jakearchibald here is how I personally see the enhancement label: it's something we could do in a follow-up without negatively affecting the core functionality. My simple test: regardless of having something that actually shipped, if X is gonna break expectations about the core functionality (minimal viable product; i.e. non enhancement bits) then it's not an enhancement. Ideally, we can ignore the enhancements and focus on resolving issues affecting the MVP. |
Works for me |
I am still concerned (like @annevk) that this is being considered. If it is desired functionality, we should not use events, which is a change that needs to be made ASAP. If events are the desired model, we should work to align with them. In particular this should be viewed from the point of view of special-casing, as he says. E.g. if addEventListener throws sometimes, then you surely aren't using EventTarget.prototype.addEventListener, which is bad. |
See also #225 btw. If we can do something better here than event abuse that'd be great. |
#256 seems to be about a better API. |
We decided to drop the throwing requirement in favour of warning via devtools |
Note that if you during a fetch event you invoke addEventListener to add an additional listener for fetch, that'd be perfectly fine. |
Updated summary to reflect the latest decision as I understand it. *: I hope you don't mind but I think cross-linking implementation bugs and spec bugs will helps us keep things in sync. |
Works for me. Good to keep track of browser progress. |
For example, if listeners are added inside an
oninstall
listener, that's going to be lost at the next teardown. Is there any case where this is desirable?The text was updated successfully, but these errors were encountered: