question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

turbo-frame loading=lazy loads eagerly in Safari

See original GitHub issue

It appears that the IntersectionObserver in Safari fires immediately on custom HTML elements. For some apps using lazy turbo frames, this is effectively graceful degradation (which is great!) but there have been a few blog posts written about using lazy turbo frames for infinite scroll (this one, for example, which links to a couple others).

In this use case, due to this issue in Safari, infinite-scrolling feeds will continue loading forever until the user reaches the bottom of the feed, the server rate-limits them, or their browser crashes.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jgaskinscommented, May 25, 2021

Then I think your question has landed in the wrong place. This issue is about <turbo-frame loading=lazy>.

1reaction
jgaskinscommented, May 25, 2021

@filipemendespi None that I’ve tested, unfortunately. Turbo Frames being implemented in terms of custom elements is a fundamental design decision. As a workaround, you might be able to attach an IntersectionObserver to a standard element with a Stimulus controller and have that observer attach the src attribute to the turbo-frame element. I don’t know if that will work, but the basic idea is this:

On page load:

<turbo-frame id=“my-frame”>
  <div id=“my-frame-observer”></div>
</turbo-frame>

When my-frame-observer hits the viewport:

<turbo-frame id=“my-frame” src=“/my_data”>
</turbo-frame>

I believe this should kick off the request as expected, but I haven’t tested it yet. Note that this is just the HTML part of it and it doesn’t include any Stimulus wiring or even vanilla JS event handlers you’d have to implement. If I can test it out some time this week, I’ll update this thread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lazy-loading content with Turbo Frames and skeleton loader
Additionally, you can set the loading property of the loading to be either “eager” (load right away) or “lazy” (load once the frame...
Read more >
Lazy-loaded frame - Turbo Reference
A reference of everything you can do with Turbo Frames. ... Like an eager-loaded frame, but the content is not loaded from src...
Read more >
Cross Browser Compatibility of Lazy loading via attribute for ...
Lazy loading via attribute for images & iframes is Not Supported on Safari 14, which means that any user who'd be accessing your...
Read more >
#11 Turbo Frames - Load content only when a dropdown is ...
If a page has a turbo frame with lazy loading, the lazy loading will occur only when the frame element becomes not “hidden”....
Read more >
Untitled
#Lazy Hartley's olde english marmalade, O2 one concert retrospect, Brede heupen krijgen, ... Lazy loading eager loading java, Sets and venn diagrams tes!...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found