chore: fixed sync state update in useEffect#447
Conversation
Summary by CodeRabbit
WalkthroughReplaces a direct state update inside a useEffect with a memoized event handler created via useEffectEvent. The handler computes a safe default tab ID (using Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant UI as Tabs Component
participant Evt as useEffectEvent:updateSelected
participant Eff as useEffect (watcher)
participant State as setSelected
rect `#f3f9ff`
UI->>Eff: mount / selectedId or tabList change
Eff->>Evt: invoke updateSelected()
end
rect `#eef7ea`
Evt->>Evt: compute firstTabId = tabList[0]?.props.id
Evt->>State: setSelected(selectedId || firstTabId)
end
State-->>UI: selected state updated
UI->>UI: re-render with new selected tab
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5-10 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (2)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/webui/designsystem/components/tabs/Tabs.tsx (1)
17-17: Initialize state with the correct first tab ID.The initial state defaults to an empty string when
selectedIdis undefined, which may not correspond to a valid tab. This creates a momentary inconsistent state before the effect runs.Apply this diff to compute the initial value correctly:
- const [selected, setSelected] = useState<string>(selectedId ?? ''); + const [selected, setSelected] = useState<string>(() => selectedId ?? (Array.isArray(children) ? children[0]?.props.id : children.props.id) ?? '');Or, more cleanly, derive
tabListearlier and use it:const tabList = useMemo(() => { return Array.isArray(children) ? children : [children]; }, [children]); const [selected, setSelected] = useState<string>(() => selectedId ?? tabList[0]?.props.id ?? '');Note: The second approach requires moving the
tabListmemo before theuseStatecall.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
src/webui/designsystem/components/tabs/Tabs.tsx(2 hunks)
🔇 Additional comments (1)
src/webui/designsystem/components/tabs/Tabs.tsx (1)
3-3: LGTM: useEffectEvent import is correct for React 19.2.The import is valid for the React version in use (19.2.0).
|



Fixes #446
Changes proposed in this pull request:
@MaskingTechnology/comify