Prevent image flicker and reloading by checking attribute before setting it#3579
Prevent image flicker and reloading by checking attribute before setting it#3579Rich-Harris merged 1 commit intosveltejs:masterfrom tcrowe:set-attribute-only-if-different
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3579 +/- ##
=======================================
Coverage 50.25% 50.25%
=======================================
Files 1 1
Lines 197 197
=======================================
Hits 99 99
Misses 98 98Continue to review full report at Codecov.
|
|
If you wish to reproduce it I've made this and updated it for this case: |
|
Thank you. Man, that's horrendous — I somehow hadn't encountered that behaviour before. Browsers 🙃 A silver lining here is that if we need to check the current attribute value for correctness anyway, we don't need to bother keeping the current value in memory (which happens for complex attribute values) — in other words we can simplify the generated code a bit. I'll address that in a follow-up |


What does it do?
Before setting an attribute it checks if the value is different.
Why?
If you look at the network log in the developer console you will notice that if you render SSR, then hydrate, it will reset the
srcattribute, and then re-download the image.Usually the image is cached so the time to load it is very fast. However it still flickers when doing this.
I think the merits of this approach should be debated but it's useful in my project and the tests still pass.
Before submitting the PR, please make sure you do the following
npm run lint!)I'm not sure how to check for image re-downloads in the tests. Sorry!
Tests
npm testoryarn test)