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

Fix: loadFullSizeImageImageTimeout not clearing when mouse leaves image #1516

Conversation

LiliaDoe
Copy link
Contributor

@LiliaDoe LiliaDoe commented Dec 31, 2024

  • This fixes what Fix: images showing when mouse is off image link #1515 was trying to fix
  • setLoadImage used to set loadHoveredImage within callback so timeout can be set outside of callback. This makes clearTimeout use the correct timeout ID
  • There is probably a smarter way of fixing this, but this works

@LiliaDoe LiliaDoe marked this pull request as ready for review December 31, 2024 04:38
js/hoverzoom.js Outdated
Comment on lines 1085 to 1096
} else if (src) {
chrome.runtime.sendMessage({action:'isImageBanned', url:src}, function (result) {
setLoadImage(false);
if (!result) {
loadFullSizeImageTimeout = setTimeout(loadFullSizeImage, delay);
setLoadImage(true);
}
});
}

// if the action key has been pressed over an image, no delay is applied
const delay = actionKeyDown || explicitCall ? 0 : (isVideoLink(srcDetails.url) ? options.displayDelayVideo : options.displayDelay);
if (loadHoveredImage) loadFullSizeImageTimeout = setTimeout(loadFullSizeImage, delay);
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not quite sure I understand how this works. Isn't chrome.runtime.sendMessage asynchronous? I mean it returns immediately and at some later point invokes a call back function. Which means line 1096 could check loadHoveredImage value before the callback has opportunity to set it.

Copy link
Contributor Author

@LiliaDoe LiliaDoe Dec 31, 2024

Choose a reason for hiding this comment

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

That is true, and that is also why the bug was happening, i think. The timeout id being set by setTimeout wasn't always being cleared by clearTimeout due to it being async. Maybe I'm misunderstanding why the bug was happening, though. I'm sure there is a better way of solving this

Copy link
Owner

Choose a reason for hiding this comment

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

I think it's better to temporarily remove that entire message sending block until a proper solution is found. Right now the value of loadHoveredImage would be reused from the previous image (because the current image would only set it after it was already checked) which is not correct.

Copy link
Contributor Author

@LiliaDoe LiliaDoe Dec 31, 2024

Choose a reason for hiding this comment

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

If it's temporary, I could comment it out for now like

/*
old code
*/

Copy link
Owner

Choose a reason for hiding this comment

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

I'd imagine @GrosPoulet would want to make it work at some point so commenting out seems fine to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

@extesy @LiliaDoe Happy New Year 🎉
I uncommented L1076-1088 and i can not reproduce the issue on Reddit or any other website. I have a 1 second delay before picture display.
My code:

`
// Temporarily removing until a better fix is found: sendMessage is async so it can't be used to set local variables

                        if (audioSrc) {
                            chrome.runtime.sendMessage({action:'isImageBanned', url:audioSrc}, function (result) {
                                if (!result) {
                                    loadFullSizeImageTimeout = setTimeout(loadFullSizeImage, delay);
                                }
                            });
                        } else if (src) {
                            chrome.runtime.sendMessage({action:'isImageBanned', url:src}, function (result) {
                                if (!result) {
                                    loadFullSizeImageTimeout = setTimeout(loadFullSizeImage, delay);
                                }
                            });                               
                        }

                        loading = true;`

Copy link
Owner

Choose a reason for hiding this comment

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

@GrosPoulet I posted an easy repro steps in #1515 (comment) - please take a look. Anyhow, the code as you wrote it couldn't possibly work due to async nature of sendMessage() function.

@extesy extesy merged commit 5671342 into extesy:master Dec 31, 2024
1 check passed
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@LiliaDoe LiliaDoe deleted the Fix-loadFullSizeImageImageTimeout-not-clearing-when-mouse-leaves-image branch January 3, 2025 04:25
GrosPoulet added a commit to GrosPoulet/hoverzoom that referenced this pull request Jan 5, 2025
- when an image (or video & audio track) is banned:
   - url of banned image is stored in background page local storage
   - a message is sent to all tabs with updated list of banned urls
- removal of async call to background page: check for banned image is now performed synchronously in each tab
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.

3 participants