RocketChat / RocketChat/EmbeddedChat
Bug: Incorrect setTimeout Delay Argument Using Array Instead of Number
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 165
- Forks
- 381
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 1
Description
Description:
While reviewing the code, I noticed that setTimeout is being called with an array as the delay value instead of a number.
timerRef.current = setTimeout(() => {
typingRef.current = false;
}, [15000]);
Even though this currently works because JavaScript coerces [15000] into 15000, it relies on implicit type conversion and may be confusing for readers. If the array were to contain more than one value (e.g. [15000, 20000]), it would result in NaN and the timeout would not behave as expected.
It would be clearer and safer to pass the delay as a number directly:
timerRef.current = setTimeout(() => {
typingRef.current = false;
}, 15000);
Updating this would make the intent clearer and align with the expected setTimeout(callback, delay) API usage.
File:
- packages/react/src/views/ChatInput/ChatInput.js
Steps to reproduce:
- Use the following code:
setTimeout(() => console.log("Hello"), [15000]); - Observe that it still executes after 15 seconds due to type coercion.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open packages/react/src/views/ChatInput/ChatInput.js and locate the setTimeout call shown in the issue. Review the surrounding typing-state behavior, then run the project's existing frontend checks; done means the delay is represented as a number while the timeout behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100