feat(plugin): server tag everywhere#4231
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the ServerTagEverywhere plugin, which displays server tags in various UI locations such as tooltips, headers, and the title bar. The review feedback identifies several critical issues: the use of this.props in a patch may cause crashes in functional components, guild.profile is likely to be undefined and should be accessed via a proper store, the variable vcGuild is being assigned without a declaration (polluting the global scope), and injecting a style prop directly may overwrite existing component styles.
| find: ".DISPLAY_NAME_STYLES_COACHMARK)", | ||
| replacement: { | ||
| match: /children:\(0,(\i).jsx\)\((\i).(\i),\{userN(.+?)\}\)/, | ||
| replace: "children:[(0,$1.jsx)($2.$3,{userN$4}),$self.renderUser(this.props.currentUser)]" |
There was a problem hiding this comment.
Using this.props.currentUser assumes that the patched component is a class component. Most modern Discord components have been migrated to functional components, where this is undefined. If this is a functional component, this patch will cause a crash. You should instead capture the user object from the local scope of the component if possible.
| ], | ||
|
|
||
| renderTooltip: ErrorBoundary.wrap((guild) => | ||
| guild.profile && |
There was a problem hiding this comment.
Standard Guild objects in Discord's internal stores typically do not have a profile property. Guild identity data (tags and badges) is usually stored separately or requires a specific fetch. Accessing guild.profile here might result in undefined, causing the tag not to render. You should verify if guild.profile is actually available on the objects you are patching or consider using a store like GuildProfileStore to retrieve this information.
| find: "?\"BACK_FORWARD_NAVIGATION\":", | ||
| replacement: { | ||
| match: /guild_id,(\i)=(.+?)getGuild\((\i)\),\[(\i)\]\),/, | ||
| replace: "$&vcGuild = $1," |
There was a problem hiding this comment.
Assigning to vcGuild without a declaration (var, let, or const) will create a global variable on the window object. This is generally discouraged as it pollutes the global namespace. If you need to share this variable between patches, it's better to explicitly use window.vcGuild or, preferably, find a way to keep it local to the component's scope.
| find: "?\"BACK_FORWARD_NAVIGATION\":", | ||
| replacement: { | ||
| match: /children:(\i)\}\)\]/, | ||
| replace: "style:{display:\"flex\",alignItems:\"center\"},children:[$1, $self.renderTitleBar(vcGuild)]})]" |
There was a problem hiding this comment.
Adding a style property directly to the props object may overwrite any existing style prop that the component already has. It is safer to merge the styles if they exist, although in this specific title bar context, it might be acceptable if you are certain no other styles are being applied to this element.
|
too niche |
Similar to RoleColorEverywhere, this plugin adds a server tag everywhere, specificially to 4 locations: Server Tooltip, Server Header, App Title Bar, and User Name Tag.
There are toggles for each location in plugin settings.