fix: React infinite loop - use primitive deps for toolbar registration

- Replace selectedMail object with selectedMailId and selectedMailFlagged primitives
- Prevents useEffect infinite re-render loop
This commit is contained in:
Agent Zero
2026-07-15 13:03:36 +02:00
parent d82ca27fdc
commit 1f01f2182a
+5 -3
View File
@@ -283,8 +283,10 @@ export function MailPage() {
// Register toolbar items // Register toolbar items
const { registerItems, unregisterPlugin } = usePluginToolbarStore(); const { registerItems, unregisterPlugin } = usePluginToolbarStore();
const selectedMailId = selectedMail?.id;
const selectedMailFlagged = selectedMail?.is_flagged;
useEffect(() => { useEffect(() => {
const hasMail = !!selectedMail; const hasMail = !!selectedMailId;
registerItems('mail', [ registerItems('mail', [
{ {
id: 'account-select', id: 'account-select',
@@ -337,7 +339,7 @@ export function MailPage() {
label: 'Flagge', label: 'Flagge',
group: 'mail-actions', group: 'mail-actions',
disabled: !hasMail, disabled: !hasMail,
active: selectedMail?.is_flagged, active: selectedMailFlagged,
icon: <svg className="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 21v-4m0 0V5a2 2 0 012-2h6.5l1 1H21l-3 6 3 6h-8.5l-1-1H5a2 2 0 00-2 2zm9-13.5V9" /></svg>, icon: <svg className="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 21v-4m0 0V5a2 2 0 012-2h6.5l1 1H21l-3 6 3 6h-8.5l-1-1H5a2 2 0 00-2 2zm9-13.5V9" /></svg>,
onClick: () => selectedMail && handleToggleFlag(selectedMail), onClick: () => selectedMail && handleToggleFlag(selectedMail),
}, },
@@ -368,7 +370,7 @@ export function MailPage() {
}, },
]); ]);
return () => unregisterPlugin('mail'); return () => unregisterPlugin('mail');
}, [registerItems, unregisterPlugin, accounts, selectedAccountId, selectedMail, handleAccountSwitch, handleSearch, handleCompose, handleReply, handleForward, handleToggleFlag, handleCreateEvent]); }, [registerItems, unregisterPlugin, accounts, selectedAccountId, selectedMailId, selectedMailFlagged, handleAccountSwitch, handleSearch, handleCompose, handleReply, handleForward, handleToggleFlag, handleCreateEvent]);
if (loadingAccounts) { if (loadingAccounts) {
return ( return (