Skip to content

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

Closed

Description

@gyst

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:

Activity

  1. cornae commented on Dec 21, 2021

    @cornae
    Member

    I felt this one coming ;)

  2. cornae commented on Dec 21, 2021

    @cornae
    Member

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

  3. gyst commented on Dec 21, 2021

    @gyst
    ContributorAuthor

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

  4. thet commented on Dec 21, 2021

    @thet
    Member

    @cornae does this need a definition phase?

  5. cornae commented on Dec 21, 2021

    @cornae
    Member

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

  6. thet commented on Dec 21, 2021

    @thet
    Member

    @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?

  7. cornae commented on Dec 21, 2021

    @cornae
    Member

    Yes. I'll IM you.

  8. thet commented on Dec 21, 2021

    @thet
    Member

    tnx

  9. thet commented on Dec 21, 2021

    @thet
    Member

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

  10. thet commented on Dec 22, 2021

    @thet
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions