Skip to content

ContractEventFeed stale closure in polling useEffect fetches wrong contractId #582

Description

@k-deejah

Problem

src/components/ContractEventFeed.tsx defines load as a plain async function inside the component body. The polling useEffect (lines 77–83) references load but its dependency array is [live, pollInterval]load is omitted. This creates a stale closure: the interval callback permanently holds a reference to the load instance captured at the time the effect ran, which closes over the contractId value at that moment.

When the parent re-renders ContractEventFeed with a new contractId prop, the initial fetch useEffect fires correctly for the new ID (line 71), but the polling interval continues calling the old load closure — which still fetches the previous contractId. Events for the new contract never appear until the interval is manually cleared or the component unmounts.

A second related problem: the initial useEffect(() => { load(); }, [contractId]) also omits load from its dependency array, which ESLint react-hooks/exhaustive-deps would flag.

Solution

Memoize load with useCallback and include contractId and limit as its dependencies. Add load to both useEffect dependency arrays:

const load = useCallback(async () => {
  if (!contractId.trim()) return;
  // ... existing fetch logic
}, [contractId, limit]);

Acceptance Criteria

  • load is wrapped in useCallback with [contractId, limit] dependencies
  • Both useEffect hooks include load in their dependency arrays
  • Changing the contractId prop immediately restarts polling for the new contract
  • No react-hooks/exhaustive-deps ESLint warnings on ContractEventFeed
  • Live polling correctly stops and restarts when live is toggled

Note for Contributors: If you're assigned to this issue, write a clear and detailed description for your pull request. Explain what was changed, why it was needed, how it was implemented, and include any relevant testing or screenshots where applicable.

Activity

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

Metadata

Metadata

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't workingfrontendUI, component, or visual layer concern

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions