Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/ChatButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function VencordChatBarButtons(props: ChatBarProps) {
{Array.from(ChatBarButtonMap)
.filter(([key]) => chatBarButtons[key]?.enabled !== false)
.map(([key, { render: Button }]) => (
<ErrorBoundary noop key={key} onError={e => logger.error(`Failed to render ${key}`, e.error)}>
<ErrorBoundary noop key={key} message={`Failed to render chat button ${key}`}>
<Button {...props} isMainChat={analyticsName === "normal"} isAnyChat={["normal", "sidebar"].includes(analyticsName)} />
</ErrorBoundary>
))}
Expand Down
32 changes: 18 additions & 14 deletions src/api/MessagePopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ export function removeMessagePopoverButton(identifier: string) {
MessagePopoverButtonMap.delete(identifier);
}

function VencordPopoverButton(props: {
Component: React.ComponentType<MessagePopoverButtonItem>;
message: Message;
render: MessagePopoverButtonFactory;
}) {
const { Component, message, render } = props;
const item = render(message);

if (!item) return null;

return <Component {...item} />;
}

function VencordPopoverButtons(props: { Component: React.ComponentType<MessagePopoverButtonItem>, message: Message; }) {
const { Component, message } = props;

Expand All @@ -72,20 +85,11 @@ function VencordPopoverButtons(props: { Component: React.ComponentType<MessagePo
const elements = Array.from(MessagePopoverButtonMap.entries())
.filter(([key]) => messagePopoverButtons[key]?.enabled !== false)
.map(([key, { render }]) => {
try {
// FIXME: this should use proper React to ensure hooks work
const item = render(message);
if (!item) return null;

return (
<ErrorBoundary noop>
<Component key={key} {...item} />
</ErrorBoundary>
);
} catch (err) {
logger.error(`[${key}]`, err);
return null;
}
return (
<ErrorBoundary noop key={key} message={`Failed to render message popover button ${key}`}>
<VencordPopoverButton Component={Component} message={message} render={render} />
</ErrorBoundary>
);
});

return <>{elements}</>;
Expand Down