Skip to content

fix(kb): max depth exceeded chunks page error#3695

Merged
icecrasher321 merged 1 commit intostagingfrom
fix/useEffect-err-kb
Mar 20, 2026
Merged

fix(kb): max depth exceeded chunks page error#3695
icecrasher321 merged 1 commit intostagingfrom
fix/useEffect-err-kb

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Seeing max depth error in chunks loading. This PR fixes that.

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@cursor
Copy link

cursor bot commented Mar 20, 2026

PR Summary

Low Risk
Low risk: small React hook change that only memoizes derived tagDefinitions to stabilize references and reduce unnecessary re-renders.

Overview
Fixes a "max update depth" render loop by memoizing the tagDefinitions array in useKnowledgeBaseTagDefinitions and useTagDefinitions (switching from inline (query.data ?? []) to useMemo).

This keeps the returned array reference stable unless query.data changes, reducing repeated renders in consumers while leaving query invalidation and mutations unchanged.

Written by Cursor Bugbot for commit 59b7834. Configure here.

@vercel
Copy link

vercel bot commented Mar 20, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Mar 20, 2026 8:16pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 20, 2026

Greptile Summary

This PR fixes a "max depth exceeded" error on the chunks page by stabilizing the tagDefinitions array reference in two knowledge-base hooks using useMemo. Previously, (query.data ?? []) as TagDefinition[] was evaluated inline on every render — when query.data was undefined/null, a brand-new [] was produced each call, causing reference instability that could trigger infinite re-render cycles in consumers using the array in useEffect dependencies or as props.

Key changes:

  • use-knowledge-base-tag-definitions.ts: tagDefinitions moved from an inline expression in the return object to a useMemo-stabilized constant.
  • use-tag-definitions.ts: The plain computed variable tagDefinitions is replaced with a useMemo-stabilized equivalent, which also stabilizes the downstream getTagLabel and getTagDefinition callbacks that depend on it.
  • Both hooks are now consistent in how they memoize their query data.

Confidence Score: 5/5

  • This PR is safe to merge — the fix is minimal, correct, and directly addresses the reported infinite render/max depth issue.
  • Both changes are straightforward useMemo additions with correct dependency arrays ([query.data]). The memoization prevents new array references when query.data has not changed, which is exactly the right approach for stabilizing hook return values. No logic is altered; no regressions are expected.
  • No files require special attention.

Important Files Changed

Filename Overview
apps/sim/hooks/kb/use-knowledge-base-tag-definitions.ts Wraps the inline tagDefinitions return value with useMemo to stabilize the array reference across renders, preventing infinite render loops caused by a new [] being created each call.
apps/sim/hooks/kb/use-tag-definitions.ts Converts the plain computed variable tagDefinitions to a useMemo-memoized value; this also stabilizes getTagLabel and getTagDefinition callbacks that depend on it.

Sequence Diagram

sequenceDiagram
    participant C as Consumer Component
    participant H as useKnowledgeBaseTagDefinitions / useTagDefinitions
    participant RQ as React Query (useTagDefinitionsQuery)

    C->>H: call hook (every render)
    H->>RQ: query.data (cached)
    Note over H: useMemo([query.data])<br/>returns same [] ref<br/>if data unchanged
    H-->>C: { tagDefinitions (stable ref), ... }
    Note over C: No referential change →<br/>no extra re-render / useEffect trigger

    Note over C,H: Before fix: (query.data ?? []) evaluated inline<br/>→ new [] every render → unstable ref<br/>→ infinite re-render / max depth exceeded
Loading

Last reviewed commit: "fix(kb): max depth e..."

@icecrasher321 icecrasher321 merged commit e270756 into staging Mar 20, 2026
12 checks passed
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.

1 participant