Skip to content

Conversation

@appflowy
Copy link
Contributor

@appflowy appflowy commented Dec 5, 2025

Description


Checklist

General

  • I've included relevant documentation or comments for the changes introduced.
  • I've tested the changes in multiple environments (e.g., different browsers, operating systems).

Testing

  • I've added or updated tests to validate the changes introduced for AppFlowy Web.

Feature-Specific

  • For feature additions, I've added a preview (video, screenshot, or demo) in the "Feature Preview" section.
  • I've verified that this feature integrates seamlessly with existing functionality.

Summary by Sourcery

Ensure page icons load via authenticated image URLs and clean up associated blob URLs to prevent memory leaks.

Enhancements:

  • Improve PageIcon to resolve icon URLs through the authenticated image helper and revoke blob URLs on unmount or icon change.
  • Expand documentation for authenticated image blob URL cleanup to clarify its purpose, memory impact, and recommended usage pattern.

@sourcery-ai
Copy link

sourcery-ai bot commented Dec 5, 2025

Reviewer's Guide

Implements authenticated loading and proper cleanup of page icon images by using getImageUrl/revokeBlobUrl in PageIcon and documenting blob URL cleanup to avoid memory leaks.

Sequence diagram for authenticated page icon image loading and cleanup

sequenceDiagram
  participant PageIcon
  participant getImageUrl
  participant revokeBlobUrl
  participant BrowserMemory

  PageIcon->>PageIcon: mount or icon changes
  PageIcon->>getImageUrl: getImageUrl(iconUrl)
  getImageUrl-->>PageIcon: blobUrl
  PageIcon->>PageIcon: setImgSrc(blobUrl)
  PageIcon->>BrowserMemory: render img src=blobUrl

  PageIcon->>PageIcon: icon changes or unmount
  PageIcon->>revokeBlobUrl: revokeBlobUrl(blobUrl)
  revokeBlobUrl->>BrowserMemory: URL.revokeObjectURL(blobUrl)
  BrowserMemory-->>BrowserMemory: release blob data
Loading

Updated class diagram for PageIcon and authenticated image utilities

classDiagram
  class PageIcon {
    +view View
    +className string
    +iconSize number
    -iconContent string
    -imgSrc string
    +PageIcon(props) ReactElement
  }

  class authenticated_image {
    +getImageUrl(url string) Promise~string~
    +revokeBlobUrl(url string) void
  }

  PageIcon ..> authenticated_image : uses
Loading

File-Level Changes

Change Details Files
Ensure PageIcon loads authenticated image URLs and revokes blob URLs on unmount or icon change to prevent memory leaks.
  • Add React state to track resolved image source separate from view.icon.value
  • Use useEffect to call getImageUrl for URL-type icons, store the returned blob URL, and update state
  • Clean up the previous blob URL in the useEffect cleanup via revokeBlobUrl when the component unmounts or the icon changes
  • Update image rendering to rely on the resolved imgSrc and memoize based on that state instead of the raw view.icon
src/components/_shared/view-icon/PageIcon.tsx
Improve documentation and safety of blob URL cleanup helper for authenticated image fetching.
  • Expand JSDoc for revokeBlobUrl to explain why blob URLs must be revoked and provide a usage example with React useEffect
  • Clarify that revokeBlobUrl is safe to call with non-blob URLs and that it is a no-op in those cases
src/utils/authenticated-image.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • The async getImageUrl call in the useEffect can race with prop changes/unmounts, so consider tracking an isMounted/requestId flag to avoid calling setImgSrc or revokeBlobUrl for a stale view.icon after the component has updated or unmounted.
  • The useEffect currently depends on view.icon; if view is frequently re-created, this will trigger more fetches than necessary—consider narrowing the dependency to view.icon?.value (and type) to avoid redundant calls to getImageUrl.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The async `getImageUrl` call in the `useEffect` can race with prop changes/unmounts, so consider tracking an `isMounted`/`requestId` flag to avoid calling `setImgSrc` or `revokeBlobUrl` for a stale `view.icon` after the component has updated or unmounted.
- The `useEffect` currently depends on `view.icon`; if `view` is frequently re-created, this will trigger more fetches than necessary—consider narrowing the dependency to `view.icon?.value` (and type) to avoid redundant calls to `getImageUrl`.

## Individual Comments

### Comment 1
<location> `src/components/_shared/view-icon/PageIcon.tsx:38-42` </location>
<code_context>
   }, [view]);

-  const img = useMemo(() => {
+  useEffect(() => {
+    let currentBlobUrl: string | undefined;
+
     if (view.icon && view.icon.ty === ViewIconType.URL && view.icon.value) {
+      void getImageUrl(view.icon.value).then((url) => {
+        currentBlobUrl = url;
+        setImgSrc(url);
</code_context>

<issue_to_address>
**issue (bug_risk):** Guard against stale async responses to avoid showing/referencing the wrong image and leaking blob URLs.

Because `getImageUrl` is async and `view.icon` can change, an earlier request can resolve after a later one. That older `then` will still call `setImgSrc` with a stale URL, and its blob URL may never be revoked because the cleanup for the newer effect has already run.

To avoid this, track whether the effect is still current and bail out if it isn’t, revoking any blob URL created by an outdated request. For example, use an `isCurrent` flag in the effect, set it to `false` in the cleanup, and check it before calling `setImgSrc` (revoking the URL immediately when `!isCurrent`).
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@appflowy appflowy merged commit bb21045 into main Dec 5, 2025
11 of 12 checks passed
@appflowy appflowy deleted the fix_page_icon_auth branch December 5, 2025 05:53
josue693 pushed a commit to josue693/AppFlowy-Web that referenced this pull request Dec 21, 2025
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