Skip to content

fix(hooks): guard campaign query keys against NaN and zero ids - #886

Open
Rafiat30 wants to merge 2 commits into
Iris-IV:mainfrom
Rafiat30:fix/campaign-query-nan-guard
Open

fix(hooks): guard campaign query keys against NaN and zero ids#886
Rafiat30 wants to merge 2 commits into
Iris-IV:mainfrom
Rafiat30:fix/campaign-query-nan-guard

Conversation

@Rafiat30

Copy link
Copy Markdown

Closes #553

Summary

NaN query keys cause identity-check failures in React Query, leading to redundant cache entries and RPC calls. useContribution and useRevenueSharing already guarded against NaN via !isNaN(id), but the accompanying !!campaignId check is fragile: it evaluates to false for a legitimate campaign id of 0, disabling the query unnecessarily.

Changes

  • Modified: src/hooks/useContribution.tsenabled now uses !!userAddress && Number.isFinite(id).
  • Modified: src/hooks/useRevenueSharing.tsenabled now uses enabled && Number.isFinite(id).

Number.isFinite correctly excludes NaN (and Infinity) while treating 0 as a valid, enabled id — a strict improvement over !!campaignId && !isNaN(id).

How to test

  1. npm run typecheck
  2. npm test -- useContribution useRevenueSharing
  3. Manually: navigate to a campaign detail page with an invalid /causes/abc id and confirm no repeated RPC calls fire in the network tab.

Replace the fragile !!campaignId && !isNaN(id) enabled checks in
useContribution and useRevenueSharing with Number.isFinite(id), which
correctly excludes NaN without also disabling the query for a falsy
(zero) campaign id.

Refs Iris-IV#553
@drips-wave

drips-wave Bot commented Jul 30, 2026

Copy link
Copy Markdown

@Rafiat30 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@sshdopey

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

…ueSharing

Adds regression coverage for the enabled-guard fix in this branch: confirms
queries stay disabled for NaN campaign ids (e.g. parseInt("abc")), confirms
they still fire for a legitimate campaign id of 0 (the bug the previous
!!campaignId check introduced), and confirms string ids are parsed correctly
before querying.

Refs Iris-IV#553
@sshdopey

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

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.

[Bug] useCampaign parseInt(campaignId) returns NaN for invalid IDs — infinite React Query cache churn

2 participants