-
Notifications
You must be signed in to change notification settings - Fork 0
Guard React Doctor and clean focused diagnostics #57
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
Changes from 6 commits
675ebe4
19e91f8
7a33843
9cbda69
b062772
56bb5c6
081e904
11e4c1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,22 +86,46 @@ export function ProjectSidebarIcon({ | |
| className = "size-4", | ||
| }: ProjectSidebarIconProps) { | ||
| const faviconSrc = resolveProjectFaviconUrl(cwd); | ||
| const shouldUseFavicon = iconMetadata === null; | ||
| const FolderGlyph = expanded ? HiOutlineFolderOpen : FolderClosed; | ||
|
|
||
| if (iconMetadata) { | ||
| const artwork = PROJECT_ICON_ARTWORK[iconMetadata.iconId]; | ||
| const Icon = artwork.icon; | ||
|
|
||
| return ( | ||
| <span | ||
| aria-label={`${iconMetadata.label} project icon`} | ||
| className={`${className} inline-flex shrink-0 items-center justify-center`} | ||
| data-project-icon-id={iconMetadata.iconId} | ||
| style={{ color: artwork.color }} | ||
| title={iconMetadata.label} | ||
| > | ||
| <Icon aria-hidden="true" className="size-[94%]" focusable="false" /> | ||
| </span> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <ProjectFolderIcon className={className} faviconSrc={faviconSrc} FolderGlyph={FolderGlyph} /> | ||
| ); | ||
| } | ||
|
|
||
| function ProjectFolderIcon({ | ||
| className, | ||
| faviconSrc, | ||
| FolderGlyph, | ||
| }: { | ||
| className: string; | ||
| faviconSrc: string; | ||
| FolderGlyph: typeof HiOutlineFolderOpen; | ||
| }) { | ||
| const [hasFavicon, setHasFavicon] = useState<boolean>( | ||
| () => shouldUseFavicon && projectFaviconPresence.get(faviconSrc) === true, | ||
| () => projectFaviconPresence.get(faviconSrc) === true, | ||
| ); | ||
| const FolderGlyph = expanded ? HiOutlineFolderOpen : FolderClosed; | ||
|
|
||
| // Probe with Image() so Electron/file-origin behaves like the actual visible <img>. | ||
| useEffect(() => { | ||
| if (!shouldUseFavicon) { | ||
| setHasFavicon(false); | ||
| return; | ||
| } | ||
|
|
||
| const cached = projectFaviconPresence.get(faviconSrc); | ||
| if (cached !== undefined) { | ||
| setHasFavicon(cached); | ||
| if (projectFaviconPresence.has(faviconSrc)) { | ||
| return; | ||
|
Comment on lines
127
to
134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sync
Suggested fix const [hasFavicon, setHasFavicon] = useState<boolean>(
() => projectFaviconPresence.get(faviconSrc) === true,
);
// Probe with Image() so Electron/file-origin behaves like the actual visible <img>.
useEffect(() => {
- if (projectFaviconPresence.has(faviconSrc)) {
+ const cachedPresence = projectFaviconPresence.get(faviconSrc);
+ if (cachedPresence !== undefined) {
+ setHasFavicon(cachedPresence);
return;
}
+
+ setHasFavicon(false);
let cancelled = false;
const image = new Image();Also applies to: 157-157 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
|
|
@@ -130,28 +154,10 @@ export function ProjectSidebarIcon({ | |
| image.removeEventListener("load", handleLoad); | ||
| image.removeEventListener("error", handleError); | ||
| }; | ||
| }, [faviconSrc, shouldUseFavicon]); | ||
|
|
||
| if (iconMetadata) { | ||
| const artwork = PROJECT_ICON_ARTWORK[iconMetadata.iconId]; | ||
| const Icon = artwork.icon; | ||
|
|
||
| return ( | ||
| <span | ||
| aria-label={`${iconMetadata.label} project icon`} | ||
| className={`${className} inline-flex shrink-0 items-center justify-center`} | ||
| data-project-icon-id={iconMetadata.iconId} | ||
| role="img" | ||
| style={{ color: artwork.color }} | ||
| title={iconMetadata.label} | ||
| > | ||
| <Icon aria-hidden="true" className="size-[94%]" focusable="false" /> | ||
| </span> | ||
| ); | ||
| } | ||
| }, [faviconSrc]); | ||
|
|
||
| return ( | ||
| <> | ||
| <span className="relative inline-flex shrink-0 items-center justify-center"> | ||
| <FolderGlyph aria-hidden="true" focusable="false" className={className} /> | ||
| {hasFavicon ? ( | ||
| <img | ||
|
|
@@ -165,6 +171,6 @@ export function ProjectSidebarIcon({ | |
| }} | ||
| /> | ||
| ) : null} | ||
| </> | ||
| </span> | ||
| ); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.