primefaces / primereact

The Most Complete React UI Component Library
https://primereact.org
MIT License
6.74k stars 1.03k forks source link

InputNumber: Infinite Loop When Unmount Component #7323

Closed tnowad closed 2 hours ago

tnowad commented 4 hours ago

Describe the bug

The InputNumber component from PrimeReact triggers an infinite loop of calls to the onChange and onValueChange handlers when the value is decremented to 0. This behavior results in the following issues:

This issue appears to be related to the unmounting of the component and may involve improper cleanup of internal state or effects when the value reaches 0.

Reproducer

https://stackblitz.com/edit/vitejs-vite-zhutef

System Information

System:
    OS: Linux 6.10 Gentoo Linux
    CPU: (12) x64 AMD Ryzen 5 5500U with Radeon Graphics
    Memory: 8.15 GB / 18.91 GB
    Container: Yes
    Shell: 3.7.1 - /bin/fish
  Binaries:
    Node: 22.3.0 - ~/.local/share/nvm/v22.3.0/bin/node
    npm: 10.8.1 - ~/.local/share/nvm/v22.3.0/bin/npm
    pnpm: 9.12.0 - ~/.local/share/pnpm/pnpm
  npmPackages:
    primereact: ^10.8.4 => 10.8.4
    react: ^18.3.1 => 18.3.1

Steps to reproduce the behavior

  1. Render the InputNumber component with an initial value of 2.
  2. Click the decrement button until the value reaches 0.
  3. Observe the console logs:
    • On Desktop: onChange functions correctly, but onValueChange enters an infinite loop.
    • On Mobile: Both onChange and onValueChange enter an infinite loop.

Expected behavior

melloware commented 4 hours ago

Excellent analysis, PR is welcome?

tnowad commented 3 hours ago

Thank you! I will take a look at it and create a pull request.