Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fiber] use srcset to trigger load even on img mount #30351

Merged
merged 1 commit into from
Jul 25, 2024

Conversation

gnoff
Copy link
Collaborator

@gnoff gnoff commented Jul 16, 2024

In #23316 we fixed a bug where onload events were missed if they happened too early. This update adds support for srcset to retrigger the load event. Firefox unfortunately does not trigger a load even when you assign srcset so this won't work in every browser when you use srcset without src however it does close a gap in chrome at least

Copy link

vercel bot commented Jul 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 25, 2024 10:27pm

@gnoff gnoff requested a review from sophiebits July 16, 2024 15:55
@facebook-github-bot facebook-github-bot added the React Core Team Opened by a member of the React Core Team label Jul 16, 2024
@gnoff gnoff requested a review from eps1lon July 16, 2024 15:55
@@ -694,6 +694,8 @@ export function commitMount(
case 'img': {
if ((newProps: any).src) {
((domElement: any): HTMLImageElement).src = (newProps: any).src;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if srcset is present and this branch is hit, does load trigger? I might have assumed that it would ignore src completely when srcset is present

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So firefox only triggers load when you set src even if there is a srcset. So I prefer src here to trigger the load in FF. Chrome triggers it when either is set so setting src if it exists is good enough but it will fall back if only srcset is set. Safari never triggers a new load so the existing solution doesn't work and this change won't really do anything about that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind adding this as a comment?

@react-sizebot
Copy link

react-sizebot commented Jul 16, 2024

Comparing: 0117239...0971bb4

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB = 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js +0.01% 499.44 kB 499.51 kB +0.01% 89.59 kB 89.60 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.01% 504.26 kB 504.33 kB +0.02% 90.30 kB 90.32 kB
facebook-www/ReactDOM-prod.classic.js +0.01% 599.20 kB 599.27 kB +0.02% 105.80 kB 105.81 kB
facebook-www/ReactDOM-prod.modern.js +0.01% 573.37 kB 573.44 kB +0.02% 101.68 kB 101.70 kB
test_utils/ReactAllWarnings.js Deleted 64.07 kB 0.00 kB Deleted 15.86 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
test_utils/ReactAllWarnings.js Deleted 64.07 kB 0.00 kB Deleted 15.86 kB 0.00 kB

Generated by 🚫 dangerJS against 0971bb4

@@ -694,6 +694,8 @@ export function commitMount(
case 'img': {
if ((newProps: any).src) {
((domElement: any): HTMLImageElement).src = (newProps: any).src;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind adding this as a comment?

In facebook#23316 we fixed a bug where onload events were missed if they happened too early. This update adds support for srcset to retrigger the load event. Firefox unfortunately does not trigger a load even when you assign srcset so this won't work in every browser when you use srcset without src however it does close a gap in chrome at least
@gnoff gnoff merged commit 7f217d1 into facebook:main Jul 25, 2024
202 checks passed
@gnoff gnoff deleted the load-event-srcset branch July 25, 2024 22:46
github-actions bot pushed a commit that referenced this pull request Jul 25, 2024
In #23316 we fixed a bug where
onload events were missed if they happened too early. This update adds
support for srcset to retrigger the load event. Firefox unfortunately
does not trigger a load even when you assign srcset so this won't work
in every browser when you use srcset without src however it does close a
gap in chrome at least

DiffTrain build for [7f217d1](7f217d1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants