Skip to content

App.js useEffect dependency may cause duplicate downloads #632

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

Open
coderabbitai bot opened this issue May 22, 2025 · 0 comments
Open

App.js useEffect dependency may cause duplicate downloads #632

coderabbitai bot opened this issue May 22, 2025 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 22, 2025

Problem Description

In App.js, there's a potential issue with how downloads are processed. The current implementation uses a useEffect hook that depends on downloadStore.downloads.size, which could trigger multiple download attempts for the same file.

useEffect(() => {
  const downloadFile = async (download) => {
    // Download implementation...
  };

  downloadStore.downloads
    .forEach(download => {
      if (!download.isComplete && !download.isDownloading) {
        downloadFile(download);
      }
    });
}, [ rootStore.deviceId, downloadStore.downloads.size ]);

Any time downloads.size changes, the effect runs again and tries to start a download for every incomplete download. If multiple downloads are added at once, or if the download state changes during processing, this can lead to duplicate download attempts for the same file.

Suggested Solutions

  1. Track active downloads with useRef:

  2. Move download logic to the store:
    Move the download management logic into the downloadStore itself, which can maintain an internal queue and ensure each download is processed exactly once.

This issue was identified during the migration from MobX to Zustand.

@thornbill thornbill added the bug Something isn't working label May 22, 2025
@thornbill thornbill added this to the v1.7.0 milestone May 22, 2025
@thornbill thornbill moved this from Todo to In Progress in Jellyfin Mobile for iOS - Roadmap May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

1 participant