-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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] hydration improvements #6449
Conversation
@benmccann Does this fix the image flickering issue that you encountered by any chance? This time, I tried to normalize both sides of the equality. |
It didn't help. I can't figure out what's causing it. It stops both if I turn off hydration and if I remove my global stylesheet. I can't find a line of code that's clearly causing it though, so I guess we should just ignore it for now. I'll let you know if I find anything else. I think you could probably revert the double URL normalization from 243c562 since it didn't help because it seems like extra code and CPU time without benefit |
I added the double URL normalization because I couldn't find a proper spec that clearly mentions that reading the .src attribute should always return the full absolute URL. (Maybe I missed it) I saw a mention here https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement |
Makes sense. I suppose I could see it working differently in different browsers in that case |
73c5145
to
4521989
Compare
Is it possible to add tests that would fail without these fixes? |
@dummdidumm I believe |
|
@benmccann Interesting, but I don't understand how this PR would solve a body reordering issue. Does it involve |
Ohh nevermind. I must have messed something up when testing earlier. That one appears to still be broken. Would you be able to take a look at it? |
Normalize src values before checking equality
Set `claim_order` in claim_html_tag
Normalize both sides of the equality to be sure
Use imports
Do not create array from children if not needed
Split an existing text node if we match the prefix
@hbirler it looks like this PR will need to be rebased |
4521989
to
2fbc2f8
Compare
I'm a little concerned about using the URL API. Are there other places in Svelte itself (not in SvelteKit or Sapper) where we're using things that would need to be polyfilled on IE11? (Note that I'm specifically wondering about things that need to be polyfilled, and not things that need to be transpiled.) Is there another way we could do this, like with a shared anchor element outside of the DOM that we set and check the |
@Conduitry do you mean something like the following:
I used the URL API since I assumed it would be faster but I did not actually check whether it is. |
Additionally |
I'm a bit concerned about the potential performance impact of mutating a DOM element everytime we want to do this check. It might be better to just manually construct the string using |
@benmccann It might not be simple to manually canonicalize a URL: |
But, as far as I'm aware, we don't need to fully canonicalize a URL. We just need to prepend the hostname when comparing to an |
Is it not possible that the relative URL looks like |
That still seems doable to handle. Another option might be to just remove that particular optimization if it's getting too complicated. I doubt that setting |
I believe it was causing a visual flicker. |
In a surprising turn of events, using the anchor seems to actually be faster https://jsbench.me/stkqvbw6qj/2 |
Use an anchor element's href attribute to convert relative paths to absolute paths
8efda3b
to
2647bfb
Compare
I can't argue with that! |
This comment has been minimized.
This comment has been minimized.
2cddb12
to
ef025d9
Compare
Has this actually been tested in IE11 ? I remember some weird bug that assigning href with a relative path would not turn it into an absolute url. You had to explicitly assign it again like |
There's not a huge impact if this doesn't work in IE11. They simply won't get the optimization. I don't think anyone would even notice. So I probably wouldn't let it hold up this PR |
@dominikg The polyfill library seems to not need the trick you described for IE8+ https://github.com/Financial-Times/polyfill-library/blob/master/polyfills/URL/polyfill.js#L344 |
maybe. I remember it because it was a very strange thing way back when . Can't find references to it now and as Ben said if the worst thing that happens is IE users missing out on an optimization... |
These have been released in 3.40.0 - thank you! |
This PR tries to address some issues that were not addressed by #6395 and issues pointed out by @benmccann and @ankitstarski
img.src
.<head>
that are not claimed but also not detached should be ignored byinit_hydrate
. These nodes havenode.claim_order === undefined
claim_html_tag
should also setclaim_order
.Edit:
init_hydrate
for when most of the nodes are on the longest increasing subsequence.splitText
to actually only claim the prefix. (Merging text siblings might help further Optimise parsed AST #3766)Edit2:
{@html}
hydration in head duplicates elements #6463Potential issues:
Is it possible thatlocation
is overwritten at a local scope by the compiler? This would cause URL normalization to break.