Skip to content

fix(ui): remove setSearchParams from useEffect deps to break infinite render loop#2860

Merged
adityathebe merged 1 commit intomainfrom
fix/formik-filterform-url-sync-guard
Feb 16, 2026
Merged

fix(ui): remove setSearchParams from useEffect deps to break infinite render loop#2860
adityathebe merged 1 commit intomainfrom
fix/formik-filterform-url-sync-guard

Conversation

@adityathebe
Copy link
Member

@adityathebe adityathebe commented Feb 16, 2026

React Router's setSearchParams is not referentially stable — it
depends on searchParams in its useCallback deps, so it's recreated
on every URL change

resolves: #2859

Reverts: 3cbeafb#diff-cc88bafad38be29277f5b003d393d46464e4e547f6effda1ba28978ff8d3f0b8L33-L36

… render loop

React Router's setSearchParams is not referentially stable — it
depends on searchParams in its useCallback deps, so it's recreated
on every URL change (remix-run/react-router#9991).

This caused the values→url sync effect to fire on every URL change
(not just when form values changed), writing stale Formik values
back to the URL before the url→values effect could sync them,
creating an infinite ping-pong cycle.

The fix excludes setSearchParams from the dependency array since it
doesn't need to be a reactive trigger — only value changes should
drive form→URL writes.
@vercel
Copy link

vercel bot commented Feb 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
aws-preview Ready Ready Preview Feb 16, 2026 1:50pm
flanksource-ui Ready Ready Preview Feb 16, 2026 1:50pm

Request Review

@coderabbitai
Copy link

coderabbitai bot commented Feb 16, 2026

Walkthrough

Removed setSearchParams from the dependency array of a React effect in FormikFilterForm to prevent unnecessary re-runs, accompanied by an eslint-disable comment to suppress the exhaustive-deps lint rule.

Changes

Cohort / File(s) Summary
Dependency Array Cleanup
src/components/Forms/FormikFilterForm.tsx
Removed setSearchParams from the effect dependency array of FormikChangesListener and added eslint-disable-next-line react-hooks/exhaustive-deps comment to prevent unintended re-runs when the dependency changes.
🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: removing setSearchParams from useEffect dependencies to fix an infinite render loop caused by unstable reference equality.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/formik-filterform-url-sync-guard

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/components/Forms/FormikFilterForm.tsx (1)

101-102: Good fix — consider a brief rationale comment for future maintainers.

The removal of setSearchParams from the dependency array is correct. Since the effect uses the functional updater form (setSearchParams((currentParams) => …)), it always receives the latest params and doesn't close over a stale reference. This cleanly breaks the infinite loop caused by React Router's referentially unstable setSearchParams.

A short comment explaining why the dep is omitted (beyond just silencing the lint) would help future readers who might be tempted to "fix" the suppression:

Suggested comment
-    // eslint-disable-next-line react-hooks/exhaustive-deps
-  }, [filterFields, paramsToReset, values]);
+    // setSearchParams is intentionally omitted: it is not referentially stable
+    // (react-router#9991) and the functional updater form already provides the
+    // latest params, so including it would cause an infinite render loop.
+    // eslint-disable-next-line react-hooks/exhaustive-deps
+  }, [filterFields, paramsToReset, values]);

@adityathebe adityathebe merged commit 668551b into main Feb 16, 2026
14 of 16 checks passed
@adityathebe adityathebe deleted the fix/formik-filterform-url-sync-guard branch February 16, 2026 14:21
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.

infinite navigation loop when clicking on a config type

1 participant