Uh oh!
There was an error while loading. Please reload this page.
doc: deprecate NaN or negative number as delay to setTimeout and setInterval - #53005
doc: deprecate NaN or negative number as delay to setTimeout and setInterval#53005jakecastelli wants to merge 4 commits into
Conversation
9bc39b4 to
7603d2eCompare
aduh95
left a comment
There was a problem hiding this comment.
You'd need to add an entry in deprecations.md
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
The
notable-change Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. Otherwise, the commit will be placed in the Other Notable Changes section. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
aduh95
commented
May 15, 2024
/cc @nodejs/web-standards |
benjamingr
left a comment
There was a problem hiding this comment.
Thanks for the contribution! These are stable APIs and this breaks web compatibility so I am -1 on this change as it causes setTimeout in browsers to behave more differently than Node's
I am in favor of doing the suggested change in #46596 with a CITGM run though (changing the coerced to value)
aduh95
commented
May 15, 2024
It does not, us doc-deprecating it does not mean folks can not use it, only that our documentation recommends against doing it. |
jakecastelli
commented
May 16, 2024
Hi @benjamingr, I understand your concern. In my opinion the current behaviour in the browser isn't ideal either. According to MDM documentation on
The change is trying to encourage or inform developers not to use We had a bug at work where one of the delay is accidentally set to I also like the suggestion to do:
I will consider doing it in a separate PR. |
UlisesGascon
left a comment
There was a problem hiding this comment.
As this is a documentation change only, I am in favor. Otherwise, it might require a deeper discussion due to compatibility discrepancies based on previous comments.
benjamingr
commented
May 16, 2024
So the plan is to doc deprecate it but never ever runtime deprecate it? |
aduh95
commented
May 16, 2024
Obviously, there’s no plan, it’s OSS after all :) |
benjamingr
commented
May 19, 2024
Then I am -1 on this unless it is clear we don't runtime deprecate and make it harder to write universal code |
jakecastelli
commented
May 19, 2024
I think we only emit run time warning instead of throwing an error and preventing the user from passing NaN or negative numbers. Would you mind elaborating why it makes it harder to write universal code? |
benjamingr
commented
May 19, 2024
Users would use libraries that work in Node.js and browsers, those libraries would start emitting a warning the user has no control over leading to frustration. The benefit itself is marginal and can be solved with a wrapper. Contrast this with today's "confusing but consistent" behavior which isn't great but allows writing universal code (Node timers and web timers are different but are "close enough" to facilitate this) I would be comfortable with this change in timers/promises though |
jakecastelli
commented
May 19, 2024
Appreciate your explanation @benjamingr 🙏 I am a bit mixed on your opinion. Please let me explain a few of my thoughts here:
|
As a platform, changing the 10+ year long behavior or timers API to deviate further from the Web Timers spec and WebIDL is just not something I think we should do. I am fine with changing the behavior in APIs people don't use between Node and timers but I just don't think we should break APIs like this - even if it's code that can be rewritten better on the application side as a platform we can't break our users like that. I will concede a (non deprecation) warning (since that wouldn't deviate further from the web timers spec) after a CITGM run showing its impact on users isn't high - which I suspect it might be. |
aduh95
commented
May 19, 2024
Why is it important to you that the warning is not a deprecation? How would it be different from a deprecation? In both cases a runtime warning is emitted when the API is used with a specific input, I think we should stick with the usual process (i.e. I’m -1 on introducing a runtime warning without an associated deprecation ID). |
jakecastelli
commented
May 25, 2024
I think this is a fair take, would add some explanations might mitigate your concern? @benjamingr
Would be happy to see the impact of this if someone could run it for me please 🙏 |
jakecastelli
commented
Jun 1, 2024
Hi @benjamingr would you mind taking another look 👀 when you have some time |
benjamingr
commented
Jun 1, 2024
You mean we doc deprecate it but never runtime deprecate it in this case? In that point why call it a deprecation in the first place? Deprecation implies (from a user's point of view) that a feature may eventually be removed. |
benjamingr
commented
Jun 3, 2024
I feel like I'm blocking this needlessly and causing frustration which I hate doing (since making progress is hard as is) and we should discuss this further or in the TSC agenda. I think this is strategic:
My personal feelings are that we should align with browsers in APIs we both deliver when it's feasible or we already do and we should not change APIs like I also acknowledge that most/all cases of this are likely programmer errors and a warning is a good step to address it if it's a common concern, just not a deprecation warning which implies (IMO) eventual removal. If everyone but me feels strongly we should a) deprecate this and b) it should be through a deprecation warning I ask we test the waters with a CITGM and land it in an odd-numbered version so it can be reverted quickly if the breakage I suspect will happen happens. |
benjamingr
commented
Jun 6, 2024
To not stall-block this, I've added tsc-agenda and messaged the TSC about this. If we reach consensus before the meeting I'll remove the TSC agenda label. What I believe is strategic and want to answer is the following: What should Node.js do about "obvious" programmer errors* in Node.js (like negative/NaN to setTimeout):
|
jasnell
commented
Jun 7, 2024
My preference would be to just emit a warning to the console if this happens but still allow it to continue working. |
benjamingr
commented
Jun 9, 2024
Do you have a preference to the type of warning? (deprecation warning vs "regular" warning) |
benjamingr
commented
Jun 10, 2024
The TSC has not reached consensus and internal discussions made the point:
Opinions ranged from "err" to "warn" to "nothing" and it looks like we aren't in consensus. It is in the agenda for the next meeting so we may be able to discuss it then and progress. I think the next step is for someone to write a quick explainer with research or convince the TSC. We can also take it to a vote but I honestly personally think a tactical decision here vs. a strategic one (for web APIs) would be a mistake in coherency. |
There was a problem hiding this comment.
General -1 on a "deprecation" warning on Web APIs without relevant standard involvement. This kind of implication of eventual removal should seek for consensus on the WHATWG as well to reduce further deviation.
+1 on "regular" warning since it doesn't indicate the behavior will be eventually removed or changed.
jakecastelli
commented
Jun 18, 2024
Hi guys, thanks for all your participation and input! I have been thinking about this one. And I would like to write my findings (there is no doubt I will be making mistakes - as always - very happy to be corrected). First let's answer Benjaming's question:
I have spent some time reading the Living Standard (WHATWG) and in timers section 4. it says:
If we see MDN, it says - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number:
So I guess the browser just treat Second, let's talk about the difference between browser and nodejs in terms of max number for delay. In browser, I am using chrome (125.0.6422.113 (Official Build) (arm64)) at the time writing, please let me know if it behaves differently in other browsers or JS runtimes. If we do the following: setTimeout(()=>console.log('hello world'),2**32+5000)In node we would see it prints "hello world" instantly (on the next tick more precisely) with a warning message:
Where in chrome - if you give it a little bit of patient (around I think this is because In summary, I agree node should behave close to the browser as much as possible, in reality there cloud always be inevitably small differences due to the implementation limitation and historical reasons etc that need to be discussed from time to time. For this one, my proposal would be "doc depreciate it with a runtime warning but not runtime depreciate it" As we can see MDN also suggest:
it is not encouraged as it would lead to error or unexpected behaviour but still available to use, a runtime warning would leave room for future spec related changes (if any). Whether you agree or disagree with me, I would appreciate your time reading this and your feedback. Off topic - when I first submitted the PR to change this about a year ago, I didn't know what |
benjamingr
commented
Jun 19, 2024
Hey, not my question it was raised by another TSC member :) The relevant places for where these conversions happen isn't the timers spec it's WebIDL. The fact we treat it as 1 and not 0 is probably just a historical mistake. As for this whole process. I want to apologize profusely for being stuck in a month long process where feedback is hard to get. You are being extremely patient with the project and our processes and this in particular is a hard change to impact since it's strategic and not just tactical IMO (we should be consistent across web APIs). |
tniessen
commented
Jun 20, 2024
Marking as semver-major because emitting a warning is not a documentation-only deprecation. |
jakecastelli
commented
Jun 20, 2024
Hi @tniessen, when I first opened this PR I didn't know what depreciation cycle means, so my PR desc was not accurate, sorry for that. This PR specifically is only a doc depreciation, the (ref 46678) is the actual PR that emits the warning, and based on the discussion, we highly likely not going to move it to a runtime depreciation but just a regular warning. Hope it clears the confusion. |
tniessen
commented
Jun 20, 2024
Thanks for clarifying. Removing the label based on the updated description. |
benjamingr
commented
Jun 22, 2024
It looks like we are amending the process to allow this (so the runtime warning PR should eventually land and not this one): #53513 48h have passed and it has 2 TSC LGTMs so I can land it but if that's ok I'll wait another day or two to make sure there are no late objectors. I've also checked with WHATWG (and forgot to link here): whatwg/html#10419 (comment) it seems like there are no objections to emitting a warning here from their PoV |
This is a
Documentation-only deprecation, the aim is to encourage developers not usingNaNor negative number for delay insetTimeoutandsetInterval.This is my first doc-only deprecation PR, please let me know if anything I need to fix 🙏
Refs: #46678