-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
Revisiting globalThis
as an EventTarget
#51372
Comments
I'm a +1 and I have a PR that implementes this already #45993 |
Yep, I was previously -1 on that change because I do think it would introduce some confusion but I've reconsidered my point of view and I think I'm +0 on it... that is, I'm open to it but I still have a number of reservations. |
I’m -1 as I think it would add more confusion. None of those mechanisms are correct for library authors. Most libraries should not touch global objects, because they can conflict in behaviors. For library authors, the problem is that more often you want to “execute something only if OBJ was not GCed” to avoid memory leaks on global objects. This is currently hacky, widespread and problematic with the use of FinalizationRegistry. Application builders should use these events, not library authors. Application builders target a specific runtime, so there is not much of a compatibility issue to discuss. |
I disagree. We have application builders targeting multiple runtimes that have explicitly raised these kinds of compat issues. Also, "libraries should not touch global objects" is obviously incorrect when it comes to other kinds of globals ( |
What is an "application builder"? There are plenty of full-stack frameworks that explicitly target multiple runtimes, like SvelteKit has adapters to run in Node or Cloudflare etc. I'm sure the SvelteKit authors would appreciate as much similarity between those targets as possible. |
Supporting |
Most of those do not allow changing configuration that alter how the process work or is set up. The problem I'm describing happens when installing custom behavior. Most libraries out there would not install an |
A developer that creates an application, vs one that creates a library to be installed.
I've done a quick skim of SvelteKit repo and I haven't found an "uncaughtException" event handler for example. Could you point me to a real-world examples of the complexities of handling this case for those libraries. |
This is an interesting use case, and I never tried to build one. Could you make an example of the compatibility problems? |
I think we should only implement the events that are exposed to Worker/global scopes in https://html.spec.whatwg.org/multipage/indices.html#events-2 . |
In browsers, deno, bun, workers and other runtimes,
globalThis
implements the Web platform standardEventTarget
API. While there are differences in the specific events emitted at the global scope, theunhandledrejection
andrejectionhandled
events are common to all of these runtimes. In Node.js ourglobalThis
, of course, does not implementEventTarget
and implements unhandled rejection events usingEventEmitter
instead. This ends up causing some interop headaches for library authors who have to special case handling of these events across runtimes.We've discussed this before but I'd like to re-open the discussion for consideration around the questions:
globalThis
implementEventTarget
unhandledrejection
andrejectionhandled
events onglobalThis
and either (a) deprecate or (b) mark as legacy the equivalent events onprocess
?globalThis
including:beforeunload
(equivalent toprocess
'beforeExit
event)error
(equivalent toprocess
'uncaughtException
eventload
message
(equivalent toprocess
'message
event)messageerror
@nodejs/tsc @nodejs/web-standards
Context: this came up in a WinterCG discussion around whether interoperable/consistent handling of unhandled errors and rejections should be covered by the WinterCG common minimum API spec.
The text was updated successfully, but these errors were encountered: