Skip to content

Commit

Permalink
[Fiber] Ensure srcset and src are assigned last on img instances (
Browse files Browse the repository at this point in the history
facebook#30340)

Safari has a behavior (bug) where when you consturct an Image in
javascript if you set srcset before properties for `sizes` the brwoser
will download the largest image size because it starts to load before
you communicate the sizes information.


https://x.com/OliverJAsh/status/1812408504444989588?t=CVHPqBaUiF5-6DBPGERTDA

There are likely other combinations or property order assignment that
can cause problems such as setting crossorigin after assigning src or
srcset. Conceptually we should withold the src and srcSet from the Image
instance until last so all relevant other properties can be assigned
before actually initiating any network activity.

This is an unforunate amount of code for what is realistically a bug in
Browsers but it should allow us to avoid weird regressions depending on
prop object order.

I didn't change the preload prop order because I don't believe preload
links have the same issue (they are not fetched as eagerly I believe).

One nice benefit of this change though is the img case can move higher
in the switch which is likely optimal given it's a relatively common
tag. Previously it was as low as it was because it was part of the void
element set so it couldn't be elevated without elevating less common
tags

---------

Co-authored-by: Jan Kassens <jan@kassens.net>
  • Loading branch information
felixshiftellecon and kassens committed Jul 24, 2024
1 parent 0117239 commit 150b560
Show file tree
Hide file tree
Showing 2 changed files with 581 additions and 540 deletions.
Loading

0 comments on commit 150b560

Please sign in to comment.