svelte-lazy icon indicating copy to clipboard operation
svelte-lazy copied to clipboard

Lazy not working with Sapper

Open rawoke083 opened this issue 5 years ago • 8 comments

HI, this is a great plugin ! It works well if I "browse" to a page(client fetch) but if I refresh the page (preload /ssr) then the image doesn't appear - only when I start moving the mouse. Not sure what the SEO impact will be ? I'm guessing the goolge-bot doesn't move a cursor ?

I've installed with -D and my package.json file looks like this:

 "devDependencies": {
...
"svelte-lazy": "^0.1.11",
...

rawoke083 avatar Jun 02 '20 15:06 rawoke083

Hi, thanks for your time. I'm not quite sure why the image only appears by moving the mouse after refreshing. This plugin only listens to scroll and size events. So I guess it might be a browser-related image rendering issue. Could you please try something to check

  • Any error in devtools Console or Elements about the image?
  • Does text appear normally inside <Lazy>?
  • Does the image appear normally outside <Lazy>?
  • Or the OS and browser versions so I can try to reproduce it.

leafOfTree avatar Jun 03 '20 06:06 leafOfTree

I'm having the same issue in chrome. I have a lazy-loaded image that is at the top of a page. when the page loads, the image doesn't load until a scroll event occurs.

clockelliptic avatar Jul 03 '20 21:07 clockelliptic

Hi, thanks for the information. I've created a new sapper project and add a lazy-loaded image at the top of the index page. But I couldn't reproduce it. Could you please check if there is any error in console? Or a minimal example might be helpful.

leafOfTree avatar Jul 07 '20 03:07 leafOfTree

I think this issue is similar to #17. Please try the latest version if you'd like to.

leafOfTree avatar Jan 14 '22 10:01 leafOfTree

Hi, I have the same issue in my application. There is a list of items on page and filter that can user use to filter list. In many times happen, that instead of item, only "Loading..." text is shown and content loads properly on page scroll. Usually no issue, but when you limit list to only several items that fits to screen, it is not possible to scroll and content is newer shown.

I've made a quick and dirty example that demonstrates the issue: https://svelte.dev/repl/41837854830d442285f20ac2cea4e86a?version=3.42.6

Try to search different characters, the results are inconsistent.

obrazek

Hope it will help and issue will be fixed.

mkyral avatar Feb 08 '23 10:02 mkyral

So after some investigation the issue is that filtered elements are shown on screen directly, without triggering scroll or resize event. So the function loadHandler() is not called and element is not loaded. If I first scroll trough whole list and load all items, filtering works correctly.

mkyral avatar Feb 08 '23 13:02 mkyral

Hi, thanks for providing the example, which is very helpful. You're right the function would not be called at all if the element was shown not by resize or scroll.

I found IntersectionObserver: https://devdocs.io/dom/intersectionobserver fits the scenario very well. The change is published. Please update and see if it works. Verified on https://svelte.dev/repl/41837854830d442285f20ac2cea4e86a?version=3.42.6

leafOfTree avatar Feb 09 '23 10:02 leafOfTree

Thanks, I can confirm that new version works. I don't need workaround with triggering "resize" event anymore.

mkyral avatar Feb 22 '23 13:02 mkyral