RocketChat / RocketChat/EmbeddedChat

Bug: Incorrect setTimeout Delay Argument Using Array Instead of Number

Open Beginner friendly
#1,204 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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:
  1. Use the following code:
    setTimeout(() => console.log("Hello"), [15000]);
  2. Observe that it still executes after 15 seconds due to type coercion.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.