Skip to content

useAppForm causes infinite re-render loop when formId changes to undefined #2407

Description

@JohnnyOu

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

  1. Visit the provided CodeSandbox link, which starts the app with undefined formId
  2. Click on the button in the rendered preview to change formId to a string, seeing no issues that occur
  3. 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.

Activity

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

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