Skip to content

Infinite Loading State in Swap Flow Causing Irrecoverable UI Deadlock With No User-Accessible Reset #50

@aniket866

Description

@aniket866

Location

components/swap/swap-interface.tsx

Description

The swap interface enters an infinite loading state when fetching pools. If the underlying RPC call returns an empty array without throwing an error, the loading loop never terminates. As a result, the UI becomes permanently stuck, with no way for the user to reset or restart the swap flow.

This leads to browser freeze/crash and forces the user to hard refresh the page, resulting in a critical UX failure.

const loadAllPools = async (totalPoolsCount: number) => {
  let currentLoaded = 0;
  let allPools: RowPool[] = [ETH_ROW_POOL];

  while (currentLoaded < totalPoolsCount) {
    const startIndex = currentLoaded;
    const endIndex = Math.min(
      startIndex + ITEMS_PER_PAGE - 1,
      totalPoolsCount - 1
    );

    const newPools = await contractClient.getPools(startIndex, endIndex);

    // BUG: no termination when newPools is empty
    allPools = [...allPools, ...newPools];
    setTokens(allPools);

    // currentLoaded never increases if newPools.length === 0
    currentLoaded += newPools.length;

    await new Promise((resolve) => setTimeout(resolve, 100));
  }

  setTokensInitialized(true);
};
  • getPools() can return []

  • currentLoaded += newPools.length → adds 0

  • while (currentLoaded < totalPoolsCount) never becomes false

  • Loop runs forever → React state updates → browser freezes → hard refresh required

@kaneki003 check this out , Please assign

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions