Skip to content
Source
Sign inSign up
TanStack/pacer

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

Closedsimonmeyerrr(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/201/headopened

🎯 Changes

Fixes https://github.com/TanStack/pacer/issues/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.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      📝 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 nameStatusExplanation
      Title check✅ PassedThe 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✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
      Description check✅ PassedThe 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.
    2. 🧹 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 afc958f6d6301127576ba84620b926d157e92b95 and b2e8e24954253e0c87f35aaca7b0d2f794160e2f.

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

      Fixes TanStack/pacer issue #200 by ensuring AsyncQueuer#tick() doesn’t treat falsy queued items as “no item”, so values like 0, "", and false are processed instead of silently skipped.

      Changes:

      • Changed #tick()’s queue-empty check from a falsy check to an explicit undefined sentinel check.
      • Added tests covering processing of falsy items (0, "", false).
      • Added a changeset for a patch release.

      Reviewed changes

      Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

      FileDescription
      packages/pacer/src/async-queuer.tsUpdates #tick() to stop only when the next item is undefined, not when it’s merely falsy.
      packages/pacer/tests/async-queuer.test.tsAdds regression tests ensuring falsy items are processed.
      .changeset/young-planes-clap.mdDeclares a patch release for the falsy-item handling fix.

      💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

    4. 🧹 Nitpick comments (1)

      Skipping null here, because it still blows up in priority handling on add ((item as any).priority), which is a separate issue. 0/""/false already lock the #tick sentinel fix. NaN isn’t needed for this patch.

    5. gave you co-auther credit in a larger PR that fixed this and even more issues at all once

    6. KevinVandy closed this

Sign in to join this conversation.