Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regression: UserAvatar should always render BaseAvatar #34061

Open
wants to merge 3 commits into
base: release-7.1.0
Choose a base branch
from
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 apps/meteor/client/providers/AvatarUrlProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const AvatarUrlProvider = ({ children }: AvatarUrlProviderProps) => {
const contextValue = useMemo(() => {
function getUserPathAvatar(username: string, etag?: string): string;
function getUserPathAvatar({ userId, etag }: { userId: string; etag?: string }): string;
function getUserPathAvatar({ username, etag }: { username: string; etag?: string }): string;
function getUserPathAvatar({ username, etag }: { username?: string; etag?: string }): string;
function getUserPathAvatar(...args: any): string {
if (typeof args[0] === 'string') {
const [username, etag] = args;
Expand Down
8 changes: 3 additions & 5 deletions packages/ui-avatar/src/components/UserAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type UserIdProp = {
userId: string;
username?: never;
};

type UserAvatarProps = Omit<BaseAvatarProps, 'url' | 'title'> & {
etag?: string;
url?: string;
Expand All @@ -26,12 +27,9 @@ const UserAvatar = ({ username, userId, etag, ...rest }: UserAvatarProps) => {
const { url = getUserAvatarPath({ userId, etag }), ...props } = rest;
return <BaseAvatar url={url} {...props} />;
}
if (username) {
const { url = getUserAvatarPath({ username, etag }), ...props } = rest;
return <BaseAvatar url={url} data-username={username} title={username} {...props} />;
}

throw new Error('ui-avatar(UserAvatar) - Either username or userId must be provided');
const { url = getUserAvatarPath({ username, etag }), ...props } = rest;
return <BaseAvatar url={url} data-username={username} title={username} {...props} />;
};

export default memo(UserAvatar);
2 changes: 1 addition & 1 deletion packages/ui-contexts/src/AvatarUrlContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type AvatarUrlContextValue = {
getUserPathAvatar: {
(username: string, etag?: string): string;
(params: { userId: string; etag?: string }): string;
(params: { username: string; etag?: string }): string;
(params: { username?: string; etag?: string }): string;
Copy link
Member

Choose a reason for hiding this comment

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

how is this possible? a function that accepts an empty object will return something?

Copy link
Member Author

Choose a reason for hiding this comment

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

@ggazzo did you checked the function?

Copy link
Member

Choose a reason for hiding this comment

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

sure and still makes no sense rendering something if you have no info about thats why this params are wrong

you are trying to fix a different problem with a "naive" solution

your problem is the /invite @something breaking right ?

for a small fraction the autocomplete uses one render type for a different item list thats why username is undefined there. but this is the real problema.

even this change solves the issue, I think you are covering the wrong place

};
getRoomPathAvatar: (...args: any) => string;
};
Expand Down
4 changes: 2 additions & 2 deletions packages/ui-contexts/src/hooks/useUserAvatarPath.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext } from 'react';

import { AvatarUrlContext, type AvatarUrlContextValue } from '../AvatarUrlContext';
import { AvatarUrlContext } from '../AvatarUrlContext';

export const useUserAvatarPath = (): AvatarUrlContextValue['getUserPathAvatar'] => useContext(AvatarUrlContext).getUserPathAvatar;
export const useUserAvatarPath = () => useContext(AvatarUrlContext).getUserPathAvatar;
Loading