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

Pagescroll bug fix #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pavel1992
Copy link

When using angular sticky directive in project, found the bug with page scrolling at new element on page adding. It was because throttledResize function triggered even if window not actually resized. This pull request fixes that bug with comparing width before and after resize event.

@harm-less
Copy link
Owner

Hello,

Thanks for the pr. I notice it doesn't pass the unit tests, can you take a look at that?
I've posted some code-review comments in your changes

@pavel1992
Copy link
Author

pavel1992 commented Aug 9, 2017

Hello, it seems test fails because it throws resize event with no width actually changing, so after my fix it doesnt triggers resize function. I don't know at this moment is this expected behaviour or not, but IMHO you shouldnt trigger resize when it was no really resizing.

'window.dispatchEvent(new Event('resize'));' <- thats why test fails.

@harm-less
Copy link
Owner

I don't remember exactly, but I'm pretty sure it's their for a reason. I think it will automatically be resolved if you fix the review comment I gave because than there's something to flush.

@pavel1992
Copy link
Author

Hm i m sorry, but i cant find where did u post review comments. And here i can see 'no reviews' in reviewers list.

@harm-less
Copy link
Owner

I posted it over here:
image

@pavel1992
Copy link
Author

pavel1992 commented Aug 9, 2017

I couldnt see your comments because it seems you didnt finish your review. By the way, i ll think, how to do fixes you wrote about.

@@ -474,7 +475,15 @@ angular.module('hl.sticky', [])
}

// bind events
throttledResize = throttle(resize, $stickyElement.defaults.checkDelay, {leading: false});
throttledResize = function(event) {
Copy link
Owner

Choose a reason for hiding this comment

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

The throttledResize method isn't throttled anymore. The throttling is also recreated everytime the window resizes, so that can't be good. I think that needs to be reverted so it makes sense again by wrapping the resize method inside another method with your changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's already triggering all the time on scroll. Resize events are significantly more rare, so what's the purpose of even throttling?

To prevent too many timers, can just put:

$timeout.cancel(timeout);

right before the $timeout and set delay to like 10-20ms, and add a call directly to resize() inside the init method too.


var newWidth = window.innerWidth;

if (windowWidth != newWidth) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually only checking this will cause a bug. If someone changes the height, and the element was near the start/end of where it was sticky, that could change and this would cause it to not be updated

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