Skip to content

Conversation

NotDemonix
Copy link

Please check if I've done this correctly and if it will work properly for react and other frameworks.

@NotDemonix NotDemonix requested a review from favna as a code owner May 31, 2025 14:56
Copy link
Member

@favna favna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For starters this is the proper code for Lit element. I strongly recommend you use a proper editor when writing code such as VSCode because there were TypeScript errors in your code before.

As for testing it with React and other frameworks, that's on you as the contributor to do really. You can leverage https://github.com/skyra-project/discord-components-implementations with Yarn Linking to do so. If anything you could at least provide sample React code that I can use for testing since this requires the error case to be triggered and I do not know what edge case you're facing that does so. That said, I suspect it won't work and this has to be followed instead: https://lit.dev/docs/components/lifecycle/#errors-in-the-update-cycle

Comment on lines +120 to +127
@property({ attribute: false })
public onAvatarError?: (imgEl: HTMLImageElement) => void;

private handleAvatarError(event: Event): void {
if (!this.onAvatarError) return;
const img = event.currentTarget as HTMLImageElement;
this.onAvatarError(img);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@property({ attribute: false })
public onAvatarError?: (imgEl: HTMLImageElement) => void;
private handleAvatarError(event: Event): void {
if (!this.onAvatarError) return;
const img = event.currentTarget as HTMLImageElement;
this.onAvatarError(img);
}
@property({ attribute: false })
public accessor onAvatarError: (imgEl: HTMLImageElement) => void;
private handleAvatarError(event: Event): void {
this.onAvatarError?.(event.currentTarget as HTMLImageElement);
}

Comment on lines +81 to +88
@property({ attribute: false })
public onImageError?: (imgEl: HTMLImageElement) => void;

private handleImageError(event: Event): void {
if (!this.onImageError) return;
const img = event.currentTarget as HTMLImageElement;
this.onImageError(img);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@property({ attribute: false })
public onImageError?: (imgEl: HTMLImageElement) => void;
private handleImageError(event: Event): void {
if (!this.onImageError) return;
const img = event.currentTarget as HTMLImageElement;
this.onImageError(img);
}
@property({ attribute: false })
public accessor onImageError: (imgEl: HTMLImageElement) => void;
private handleImageError(event: Event): void {
this.onImageError?.(event.currentTarget as HTMLImageElement);
}

Comment on lines +284 to +291
@property({ attribute: false })
public onAvatarError?: (imgEl: HTMLImageElement) => void;

private handleAvatarError(event: Event): void {
if (!this.onAvatarError) return;
const img = event.currentTarget as HTMLImageElement;
this.onAvatarError(img);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@property({ attribute: false })
public onAvatarError?: (imgEl: HTMLImageElement) => void;
private handleAvatarError(event: Event): void {
if (!this.onAvatarError) return;
const img = event.currentTarget as HTMLImageElement;
this.onAvatarError(img);
}
@property({ attribute: false })
public accessor onAvatarError: (imgEl: HTMLImageElement) => void;
private handleAvatarError(event: Event): void {
this.onAvatarError?.(event.currentTarget as HTMLImageElement);
}

Comment on lines +269 to +276
@property({ attribute: false })
public onAvatarError?: (imgEl: HTMLImageElement) => void;

private handleAvatarError(event: Event): void {
if (!this.onAvatarError) return;
const img = event.currentTarget as HTMLImageElement;
this.onAvatarError(img);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@property({ attribute: false })
public onAvatarError?: (imgEl: HTMLImageElement) => void;
private handleAvatarError(event: Event): void {
if (!this.onAvatarError) return;
const img = event.currentTarget as HTMLImageElement;
this.onAvatarError(img);
}
@property({ attribute: false })
public accessor onAvatarError: (imgEl: HTMLImageElement) => void;
private handleAvatarError(event: Event): void {
this.onAvatarError?.(event.currentTarget as HTMLImageElement);
}

this.compactMode,
() => html`<div class="discord-reply-badge">${CommandIcon()}</div>`,
() => html`<img class="discord-replied-message-avatar" src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" />`
() => html`<img class="discord-replied-message-avatar" src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" @error=${this.handleAvatarError} />`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
() => html`<img class="discord-replied-message-avatar" src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" @error=${this.handleAvatarError} />`
() =>
html`<img
class="discord-replied-message-avatar"
src="${ifDefined(profile.avatar)}"
alt="${ifDefined(profile.author)}"
@error=${this.handleAvatarError}
/>`

() =>
html`<div class="discord-author-avatar">
<img src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" />
<img src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" @error=${this.handleAvatarError} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<img src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" @error=${this.handleAvatarError} />
<img src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" @error=${this.handleAvatarError} />

this.compactMode || this.deleted,
() => html`<div class="discord-reply-badge">${ReplyIcon()}</div>`,
() => html`<img class="discord-replied-message-avatar" src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" />`
() => html`<img class="discord-replied-message-avatar" src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" @error=${this.handleAvatarError} />`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
() => html`<img class="discord-replied-message-avatar" src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" @error=${this.handleAvatarError} />`
() =>
html`<img
class="discord-replied-message-avatar"
src="${ifDefined(profile.avatar)}"
alt="${ifDefined(profile.author)}"
@error=${this.handleAvatarError}
/>`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants