Skip to content
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

Web: Fix 'Download' not triggering until second attempt #4721

Merged
merged 1 commit into from
Sep 4, 2020

Conversation

infinite-persistence
Copy link
Contributor

Issue

Closes #4669: Download doesn't trigger on web until 2nd attempt

The issue only happens when Autoplay is disabled in the User Settings and the video hasn't been loaded when Download is clicked.

The following code:
if (didClickDownloadButton && streamingUrl)
didn't triggered because:

  1. streamingUrl has not resolved yet when the Effect ran.
  2. When it did resolve, the parent component was also notified and unmounted things, causing didClickDownloadButton to reset.

Approach

  • Change the state to the persisted version to deal with the unmounting.
  • As a secondary precaution against any unexpected mismatch from the mounting/unmounting, the state was changed from boolean to string, with the compared value being the current uri when the Download button was clicked.

@neb-b
Copy link

neb-b commented Sep 1, 2020

I think a potentially better fix would be to make sure this doesn't get removed from the page when while streamingUrl is being fetched. Then we don't need a new persisted value for every download you click.

If that's not possible, we should create a new effect useSessionState which is the same as usePersistedState except it uses sessionStorage instead of localStorage so the value dies when you leave the page.

## Issue
4669: `Download doesn't trigger on web until 2nd attempt`

The issue only happens when _Autoplay_ is disabled in the User Settings and the video hasn't been loaded when _Download_ is clicked.

The following code:
   `if (didClickDownloadButton && streamingUrl)`
didn't triggered because:
1. `streamingUrl` has not resolved yet when the Effect ran.
2. When it did resolve, the parent component was also notified and unmounted things, causing `didClickDownloadButton` to reset.

## Approach
Avoid the unnecessary unmounting by not using a conditional section wrapper within a return statement. React probably couldn't do the diffs when the conditional is at a section level.
@infinite-persistence
Copy link
Contributor Author

Rework
Avoid the unnecessary unmounting by not using a conditional section wrapper within a return statement. React probably couldn't do the diffs when the conditional is at a section level.

@neb-b neb-b merged commit 202269e into master Sep 4, 2020
@neb-b neb-b deleted the ip-web-download-4669 branch September 4, 2020 15:52
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.

Download doesn't trigger on web until 2nd attempt
2 participants