-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
More aggressive innerHTML optimization detection #2374
Comments
That's a good idea. I don't think we can do ul = element('ul');
ul.innerHTML = `<li>one</li><li>two</li>`;
li = element('li');
li.textContent = name;
li.insertAdjacentHTML('afterEnd', `'<li>four</li><li>five</li>`); In this case, where we already know that ul = element('ul');
ul.innerHTML = `<li>one</li><li>two</li><li>${name}</li><li>four</li><li>five</li>`; A minifier ought to be able to turn that into a static string. It's also true that in some cases we could do this sort of thing, if we did need references: ul = element('ul');
ul.innerHTML = `<li>one</li><li>two</li><li>${ctx.name}</li><li>four</li><li>five</li>`;
t = ul.children[2].childNodes[0]; |
This seems potentially quite similar to #3898 |
@Rich-Harris I was dinging into this stuff because I noticed that static elements are just appended in dom with |
Note that this does particularly poorly when |
closing since Svelte 5 uses a completely different mechanism that essentially gives us this optimization for free |
Svelte will fallback to using
innerHTML
if a block of markup is entirely static. This results in much less generated code. I noticed that if a single item in that block is dynamic, regardless of its position, the output is deopt'd and it falls back to just usingelement
andappend
for everything.Here is an example of having a single dynamic element in a list. This can potentially result in a lot more generated code, creating local variables in
create_fragment
that don't really need to exist.Instead of falling back to the imperative DOM APIs could svelte detect if using a combination of both would be beneficial? In this example you could still use
innerHTML
to define then - 1
list elements and then useelement
/append
for the one dynamic tag. This seems like it would be easiest when the dynamic element is the first or last child, but I imagine you could also do this withelement.innerHTML += "..."
The text was updated successfully, but these errors were encountered: