File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
app/components/primer/open_project Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ export class AvatarFallbackElement extends HTMLElement {
66 @attr altText = ''
77
88 connectedCallback ( ) {
9+ // If either uniqueId or altText is missing, skip color customization so the SVG
10+ // keeps its default gray fill defined in the source and no color override is applied.
911 if ( ! this . uniqueId || ! this . altText ) return
1012
1113 const img = this . querySelector ( 'img[src^="data:image/svg+xml"]' )
@@ -34,10 +36,14 @@ export class AvatarFallbackElement extends HTMLElement {
3436 private updateSvgColor ( img : HTMLImageElement , color : string ) {
3537 const dataUri = img . src
3638 const base64 = dataUri . replace ( 'data:image/svg+xml;base64,' , '' )
37- const svg = atob ( base64 )
3839
39- const updatedSvg = svg . replace ( / f i l l = " h s l \( [ ^ " ] + \) " / , `fill="${ color } "` )
40-
41- img . src = `data:image/svg+xml;base64,${ btoa ( updatedSvg ) } `
40+ try {
41+ const svg = atob ( base64 )
42+ const updatedSvg = svg . replace ( / f i l l = " h s l \( [ ^ " ] + \) " / , `fill="${ color } "` )
43+ img . src = `data:image/svg+xml;base64,${ btoa ( updatedSvg ) } `
44+ } catch ( _error ) {
45+ // If the SVG data is malformed or not valid base64, skip updating the color
46+ // to avoid breaking the component.
47+ }
4248 }
4349}
You can’t perform that action at this time.
0 commit comments