Virtual Slides in react with asynchronously added content? #7608
Unanswered
justinhelmer
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Context
I have a Swiper with a ton of slides and very large images (tens of thousands of px).
This results in two performance bottlenecks:
To mitigate (1), I am using the strategy outlined here. I have a user action that enables opening the full size image in a new tab, so I want to avoid having to generate smaller versions of the images just for the purpose of rendering in the Swiper. Instead, the strategy of using an image load event and drawing a canvas works very well.
To mitigate (2), ideally I would be able to just use
loading="lazy"
. However, the strategy in (1) means that there are no images being rendered to the DOM; instead, a canvas element is being injected asynchronously.For this reason, the "virtual slides" approach seems like a good one.
Problem
When using virtual slides with react, and dynamically injecting the content, transitioning between slides can create some race conditions related to the timing of image loads. Even when the critical race conditions are mitigated, it still can cause "flicker" as well as redundant fetches.
Example
When using images, virtual columns works like a charm, as well as lazy loading. Its just this dynamically injected canvas that is an issue.
Here is an example. The issue becomes most noticeable when opening the replit in a new tab and using keyboard controls.
Any help would be greatly appreciated.
It might be considered a bug, but wanted to try the community first.
Beta Was this translation helpful? Give feedback.
All reactions