-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
fix: src
and loading
in lazy loaded images returns right value immediately
#15141
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: a7c49f6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
I'm really not sure about this. How common is it that someone will imperatively try and access these in an effect straight after? I've been thinking that maybe in FF we just always use |
I stumbled across this because a client was having problems...the problem is not exactly if the user access it but if it uses the element with some library that then access them. And I think it would actually be decently common to mount "audio widgets" and such. Regardless I think it's a pretty weird behavior and we should fix it. I'm fine if this is not the fix 😁 |
// of setting the attribute in the setter | ||
define_property(element, 'src', { | ||
get() { | ||
return src; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't correct? It doesn't take into account relative pathing AFAIK which differs from the attribute value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log(img.getAttribute("src")); // "images/foo.png"
console.log(img.src); // "http://example.com/path/images/foo.png"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh...I knew something was gonna bit me 😁 I'll check it I can find a fix
return src; | ||
}, | ||
set(new_src) { | ||
element.setAttribute('src', new_src); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the same issue with relative paths applies here too
Yeah I don't think this is the right approach. I'm sure there's something else we can do, or maybe we cover it by adding a temporary getter on the element in DEV for FF that says to do this in a rAF? |
Well if we want to add it we should add it regardless of the browser. Maybe we should try to use |
should we just change this to svelte/packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js Lines 60 to 68 in 64f86ee
|
That won't fix it. The parent templates need to have been cloned with |
But apparently |
What about for WebKit/Safari? |
Didn't check but we can just check what's faster and use that no? The bug for lazy should only be there for Firefox |
Because of a weird Firefox+
cloneNode
bug nowadays if there's a lazy loaded image we remove theloading
andsrc
attributes and we reinstate them in the next animation frame (this will trick Firefox in doing it's job).However this is problematic if the user access those attributes on mount or in an action. For example a case like this
because as you can see from the logs the values are completely unexpected.
I found a solution to this problem but it might have other implications that i'm not aware of...basically when we
handle_lazy_img
after removing the attributes i also define two properties on the element to handleloading
andsrc
"manually" (the same is true forgetAttribute
). This keeps the attribute "not there" for Firefox while also allowing the user to access it in JS if needed.Do you think it's a reasonable solution?
P.s. i was not able to add a test for this because jsdom acts a bit weird with
loading
and it's alwaysundefined
so it never actually enters in the if insidehandle_lazy_img
.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.packages/svelte/src
, add a changeset (npx changeset
).Tests and linting
pnpm test
and lint the project withpnpm lint