Skip to content

fix: clear existing idle timeout in Collector.resetTimer#11460

Open
Sim-hu wants to merge 2 commits intodiscordjs:mainfrom
Sim-hu:fix/collector-reset-timer
Open

fix: clear existing idle timeout in Collector.resetTimer#11460
Sim-hu wants to merge 2 commits intodiscordjs:mainfrom
Sim-hu:fix/collector-reset-timer

Conversation

@Sim-hu
Copy link

@Sim-hu Sim-hu commented Mar 20, 2026

Summary

  • Fix Collector.resetTimer({ idle: newValue }) not properly resetting the idle timer
  • The old code only reset the idle timeout when this._idletimeout already existed, and kept the clear and set coupled inside the same conditional
  • Now the existing idle timeout is always cleared first, then a new one is created if an idle value is provided (either via the argument or from the original options)

Test plan

  • Call resetTimer({ idle: 5000 }) on a collector that was created with a different idle value and verify the new idle duration takes effect
  • Call resetTimer({ idle: 5000 }) on a collector that was created without an idle option and verify an idle timeout is now active
  • Call resetTimer() with no arguments on a collector with an existing idle timeout and verify it resets to the original idle value

@vercel
Copy link

vercel bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
discord-js Skipped Skipped Mar 24, 2026 6:38am
discord-js-guide Skipped Skipped Mar 24, 2026 6:38am

Request Review

@vercel vercel bot temporarily deployed to Preview – discord-js March 20, 2026 13:15 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js-guide March 20, 2026 13:15 Inactive
@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

📝 Walkthrough

Walkthrough

The Collector.resetTimer() method was updated to conditionally schedule idle timeouts only when the resolved idle duration is truthy, preventing unnecessary timeout creation when idle is falsy or undefined.

Changes

Cohort / File(s) Summary
Idle-Timer Conditional Guard
packages/discord.js/src/structures/interfaces/Collector.js
Modified resetTimer() to only schedule idle timeout when idle ?? this.options.idle resolves to a truthy value; prevents timeout creation when idle is undefined or falsy.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing the idle timeout clearing behavior in Collector.resetTimer, which is the primary focus of the changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem, the fix, and providing a test plan that aligns with the code changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can generate a title for your PR based on the changes.

Add @coderabbitai placeholder anywhere in the title of your PR and CodeRabbit will replace it with a title based on the changes in the PR. You can change the placeholder by changing the reviews.auto_title_placeholder setting.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/discord.js/src/structures/interfaces/Collector.js`:
- Around line 280-286: In the method that clears/restarts the idle timer (the
block using this._idletimeout and setTimeout — e.g., resetTimer), after
clearTimeout(this._idletimeout) explicitly set this._idletimeout = null to avoid
keeping a stale truthy reference; when you later create a new timer assign the
return of setTimeout to this._idletimeout (and call .unref() as before). This
mirrors the stop() behavior and prevents handleCollect from mis-detecting an
active timer and re-enabling this.options.idle when idle was set to 0.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 31743e62-1a34-459c-9704-51b7f3beffa1

📥 Commits

Reviewing files that changed from the base of the PR and between 2a06721 and de242f0.

📒 Files selected for processing (1)
  • packages/discord.js/src/structures/interfaces/Collector.js

@vercel vercel bot temporarily deployed to Preview – discord-js March 24, 2026 06:38 Inactive
@vercel vercel bot temporarily deployed to Preview – discord-js-guide March 24, 2026 06:38 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant