fix: move useEffect hooks before early return in ChatProfiles#2888
Closed
EyalAmitay wants to merge 1 commit intoChainlit:mainfrom
Closed
fix: move useEffect hooks before early return in ChatProfiles#2888EyalAmitay wants to merge 1 commit intoChainlit:mainfrom
EyalAmitay wants to merge 1 commit intoChainlit:mainfrom
Conversation
The two useEffect hooks were placed after an early return, violating React's Rules of Hooks. When config loads asynchronously (undefined → populated), the hook count changes between renders (8 → 10), causing React to throw "Rendered more hooks than during the previous render". Move the early return below both useEffects and add optional chaining guards so they no-op when config.chatProfiles is missing.
d190937 to
ecbf275
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ChatProfiles.tsxwhere twouseEffecthooks were placed after an early returnconfigloads asynchronously (undefined→ populated), the hook count changes between renders (8 → 10), causing React to throw "Rendered more hooks than during the previous render"useEffectcalls and add optional chaining guards so they no-op whenconfig.chatProfilesis missingTest plan
pnpm type-checkpassespnpm lintpassespnpm test(frontend unit tests) — 32/32 passSummary by cubic
Fixes a React Rules of Hooks violation in
ChatProfilesby moving bothuseEffecthooks above the early return so hook order stays stable asconfigloads. Prevents the "Rendered more hooks than during the previous render" error and keeps the component idle unless there are at least 2 profiles.useEffecthooks to stabilize hook count.config.chatProfilesis missing or has 0–1 items.Written for commit ecbf275. Summary will update on new commits.