Skip to content

fix(hooks): resolve infinite loop in useFormChangeDetection#1345

Open
thisisharsh7 wants to merge 1 commit intorhesis-ai:mainfrom
thisisharsh7:fix/useFormChangeDetection-infinite-loop
Open

fix(hooks): resolve infinite loop in useFormChangeDetection#1345
thisisharsh7 wants to merge 1 commit intorhesis-ai:mainfrom
thisisharsh7:fix/useFormChangeDetection-infinite-loop

Conversation

@thisisharsh7
Copy link
Contributor

Fix infinite re-renders in useFormChangeDetection

This PR fixes a regression introduced in #1235.

The useEffect inside useFormChangeDetection had redundant dependencies (initialData and initialDataString), causing unnecessary executions and in some cases infinite re-renders when initialData was recreated by reference.

@thisisharsh7 thisisharsh7 marked this pull request as ready for review February 14, 2026 18:20
Copy link

@peqy peqy bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix makes sense: effect now keys off initialDataString so recreating initialData by reference won’t retrigger/reset state.

Found 1 issue (0 critical, 1 improvement).

useEffect(() => {
setTrackedInitialData(initialData);
}, [initialDataString, initialData]);
}, [initialDataString]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improvement: Consider adding a short comment (or an exhaustive-deps disable w/ explanation, if that rule is enabled) explaining why initialData is intentionally omitted from the deps here.

Fix: e.g. // Depend on serialized value to avoid reruns when initialData is recreated by reference (regression #1235)

@harry-rhesis
Copy link
Contributor

@thisisharsh7, thanks for the fix; this behavior was also flagged during development of another feature. We fixed it in another branch. Thank you for checking, though!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants