Skip to content

autoload-visible should not trigger injection for page elements above visible page top #939

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

Closed
gyst opened this issue Dec 21, 2021 · 10 comments · Fixed by #941 or #942
Closed

autoload-visible should not trigger injection for page elements above visible page top #939

gyst opened this issue Dec 21, 2021 · 10 comments · Fixed by #941 or #942
Assignees

Comments

@gyst
Copy link
Contributor

gyst commented Dec 21, 2021

doTrigger = reltop <= $scrollable.innerHeight();

Scenario: I have a document with 100 previews, each of which has a trigger: autoload-visible. It also has a comment sentinel with a page fragment url that takes me directly to the bottom of the page. Jumping to the bottom of the page should only trigger the injection of the last page preview image; pages 2-99 do not need to be loaded since they are in "flyover country".

As a complication, when I then move away from this page via injection, this does not work, or rather it waits for a long time for all the 98 spurious preview injections to complete, before I can navigate away.

References:

@cornae
Copy link
Member

cornae commented Dec 21, 2021

I felt this one coming ;)

@cornae
Copy link
Member

cornae commented Dec 21, 2021

I see it's on @thet's name but I think it should be on my name.

@gyst
Copy link
Contributor Author

gyst commented Dec 21, 2021

I don't see how you can fix this in markup. IMO it needs a javascript change on the line I quoted.

@thet
Copy link
Member

thet commented Dec 21, 2021

@cornae does this need a definition phase?

@cornae
Copy link
Member

cornae commented Dec 21, 2021

@gyst I can't currently fix this in markup. @thet Yes.

@thet
Copy link
Member

thet commented Dec 21, 2021

@cornae I'd like to work on that this evening. Can you give this feature a thought this afternoon?
Although, currently I think this is just a "bugfix". If something isn't visible above the fold, it shouldn't be loaded, right?

@cornae
Copy link
Member

cornae commented Dec 21, 2021

Yes. I'll IM you.

@thet
Copy link
Member

thet commented Dec 21, 2021

tnx

@thet
Copy link
Member

thet commented Dec 21, 2021

I'm off this afternoon and will check my mails/messages later

@thet
Copy link
Member

thet commented Dec 22, 2021

First attempt to fix this issue: #941
Second attempt to fix this issue: #942

The idea would be:

  • Use an intersection observer to check if an element is in the viewport. Trigger the loading then.
  • If an element is out of the viewport cancel a previous trigger.

The canceling would be done by aborting the jquery ajax call or by sending an abortsignal for fetch. for that to work we would need access to the ajax request object and that would need a refactoring of pat-inject use patternslib base class and proper scoping/encapsulation. pat ajax would return the ajax request object and pat inject could store it on the pattern instance. work has begun here: #943
During this effort we could switch from jQuery ajax to fetch and use async/await which would give us the possibility to await for an pat-inject call to be finished.
However, that needs a little more time.

Instead the PR #941 uses an intersection observer and a window timeout to schedule the triggering which can be cleared if the element is moved out of the viewport.
The delay is something we normally want to avoid, but it was already there with the original implementation, so this would be acceptable.

Status: the PR #941 needs more fine tuning and testing, currently it doesn't behave as it should.

@thet thet closed this as completed in #942 Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants