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:
@@ -283,8 +283,10 @@ export function MailPage() {
|
||||
|
||||
// Register toolbar items
|
||||
const { registerItems, unregisterPlugin } = usePluginToolbarStore();
|
||||
const selectedMailId = selectedMail?.id;
|
||||
const selectedMailFlagged = selectedMail?.is_flagged;
|
||||
useEffect(() => {
|
||||
const hasMail = !!selectedMail;
|
||||
const hasMail = !!selectedMailId;
|
||||
registerItems('mail', [
|
||||
{
|
||||
id: 'account-select',
|
||||
@@ -337,7 +339,7 @@ export function MailPage() {
|
||||
label: 'Flagge',
|
||||
group: 'mail-actions',
|
||||
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>,
|
||||
onClick: () => selectedMail && handleToggleFlag(selectedMail),
|
||||
},
|
||||
@@ -368,7 +370,7 @@ export function MailPage() {
|
||||
},
|
||||
]);
|
||||
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) {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user