Describe the bug
In useAppForm hook, if formId is set to a state that can be undefined, changing its value from a defined string to undefined causes infinite re-render, with the following error:
Too many re-renders. React limits the number of renders to prevent an infinite loop.
Note that if formId starts with being undefined, then this issue does not occur. It only occurs if formId changes from defined to undefined.
Your minimal, reproducible example
https://codesandbox.io/p/sandbox/lucid-satoshi-k9kj7j
Steps to reproduce
- Visit the provided CodeSandbox link, which starts the app with undefined formId
- Click on the button in the rendered preview to change formId to a string, seeing no issues that occur
- Click on the button again to change formId back to undefined, now seeing error:
Too many re-renders. React limits the number of renders to prevent an infinite loop.
Expected behavior
Switching formId back to undefined should not cause infinite re-rendering error. It should instead behave as if there were no formId passed into the hook in the first place.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Chrome
- Version: 1.33.5
TanStack Form adapter
react-form
TanStack Form version
1.33.5
TypeScript version
5.9.3
Additional context
Current mitigation: pass formId: formId ?? "" instead. Even though this fully mitigates the issue, having this error is not a pleasant developing experience.
Describe the bug
In
useAppFormhook, ifformIdis set to a state that can be undefined, changing its value from a defined string to undefined causes infinite re-render, with the following error:Note that if formId starts with being undefined, then this issue does not occur. It only occurs if formId changes from defined to undefined.
Your minimal, reproducible example
https://codesandbox.io/p/sandbox/lucid-satoshi-k9kj7j
Steps to reproduce
Too many re-renders. React limits the number of renders to prevent an infinite loop.Expected behavior
Switching formId back to undefined should not cause infinite re-rendering error. It should instead behave as if there were no formId passed into the hook in the first place.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
TanStack Form adapter
react-form
TanStack Form version
1.33.5
TypeScript version
5.9.3
Additional context
Current mitigation: pass
formId: formId ?? ""instead. Even though this fully mitigates the issue, having this error is not a pleasant developing experience.