Skip to content

fix(async-queuer): use nullish check in #tick to handle falsy queue items#201

Open
simonmeyerrr wants to merge 2 commits intoTanStack:mainfrom
simonmeyerrr:fix-async-queuer-falsy-items
Open

fix(async-queuer): use nullish check in #tick to handle falsy queue items#201
simonmeyerrr wants to merge 2 commits intoTanStack:mainfrom
simonmeyerrr:fix-async-queuer-falsy-items

Conversation

@simonmeyerrr
Copy link
Copy Markdown

@simonmeyerrr simonmeyerrr commented Apr 17, 2026

🎯 Changes

Fixes #200

AsyncQueuer#tick() used if (!nextItem) to check whether the queue was empty, which caused falsy items (0, "", false) to be silently skipped. Changed to if (nextItem === undefined) to match the sentinel already used by getNextItem() and execute().

Added tests verifying that items with values 0, "", and false are processed correctly.

The issue is actually deeper than this, but this PR aim to make the minimal fix for this cases. A better fix would be to refactor some methods signature from TValue | undefined to something like { hasItem: false } | { hasItem: true, item: TValue } in order to also allow undefined as a value (as nothing in addItem or TValue prevent having an undefined item), but it would require a major version change.

Note: I didn't add a test for null, because this value makes other part of the code crash (priority computing) which should be fixed in other issues/PRs.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

Bug Fixes

  • Fixed an issue where queued items with falsy values (0, empty string, false) were incorrectly excluded from processing, ensuring they are now properly handled and processed as intended.

Tests

  • Added test coverage for falsy item handling to verify correct processing of items with falsy values.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 17, 2026

📝 Walkthrough

Walkthrough

This pull request fixes AsyncQueuer#tick to properly handle falsy item values. The loop break condition was changed from a generic falsy check to an explicit undefined check, allowing items with values like 0, false, and '' to proceed through processing instead of being silently excluded.

Changes

Cohort / File(s) Summary
Falsy Item Handling Fix
packages/pacer/src/async-queuer.ts, packages/pacer/tests/async-queuer.test.ts
Fixed loop condition to explicitly check for undefined instead of falsy values, and added comprehensive test suite with three cases validating correct handling of 0, '', and false items during queue processing.
Changelog
.changeset/young-planes-clap.md
Documented patch-level fix for @tanstack/pacer addressing falsy item exclusion in AsyncQueuer#tick.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Once falsy values were cast away,
But now they hop and skip and play,
In AsyncQueuer's gentle queue,
Zeros, empties—all ring true! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main change: using a nullish check instead of a falsy check to handle falsy queue items, which is the core fix in this PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description fully addresses all required template sections with clear details, complete checklist, and comprehensive context.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
packages/pacer/tests/async-queuer.test.ts (1)

1099-1163: Good targeted coverage for the fix.

All three JS falsy primitives (0, '', false) are exercised with mixed orderings, and both processed order and successCount are asserted — this locks in the regression well.

Optional: consider also adding null and NaN cases for completeness (both are falsy; null !== undefined so they should also now pass through correctly). Not required for this patch.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/pacer/tests/async-queuer.test.ts` around lines 1099 - 1163, Add
tests to cover the remaining falsy values null and NaN: create new it blocks
that instantiate AsyncQueuer<T> (use AsyncQueuer<any> for NaN/null), push null
and NaN items via addItem in mixed order with truthy values, call start() and
advance timers with vi.advanceTimersByTimeAsync, then assert the processed array
contains the original values in order and asyncQueuer.store.state.successCount
equals the number of items; reference AsyncQueuer, addItem, start,
store.state.successCount and vi.advanceTimersByTimeAsync when locating where to
add these tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/pacer/tests/async-queuer.test.ts`:
- Around line 1099-1163: Add tests to cover the remaining falsy values null and
NaN: create new it blocks that instantiate AsyncQueuer<T> (use AsyncQueuer<any>
for NaN/null), push null and NaN items via addItem in mixed order with truthy
values, call start() and advance timers with vi.advanceTimersByTimeAsync, then
assert the processed array contains the original values in order and
asyncQueuer.store.state.successCount equals the number of items; reference
AsyncQueuer, addItem, start, store.state.successCount and
vi.advanceTimersByTimeAsync when locating where to add these tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4978d571-e33c-4562-a615-b2f695d26dcf

📥 Commits

Reviewing files that changed from the base of the PR and between afc958f and b2e8e24.

📒 Files selected for processing (3)
  • .changeset/young-planes-clap.md
  • packages/pacer/src/async-queuer.ts
  • packages/pacer/tests/async-queuer.test.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AsyncQueuer silently drops falsy queue items (0, "", false, null)

1 participant