Skip to content

Collapse consecutive text nodes #14

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

Closed
Rich-Harris opened this issue Nov 21, 2016 · 4 comments
Closed

Collapse consecutive text nodes #14

Rich-Harris opened this issue Nov 21, 2016 · 4 comments
Labels
compiler Changes relating to the compiler perf

Comments

@Rich-Harris
Copy link
Member

The parser generates text nodes either side of comments – they should be concatenated

@evs-chris
Copy link
Contributor

If this is what I think it is, the comments could actually be useful for progressive enhancement. See ractivejs/ractive#2664

Basically, merged text nodes mean that there's no way not to replace consecutive text content (e.g. text in a section surrounded by other text and interpolators) without touching the DOM in ways that most people find surprising.

@Rich-Harris
Copy link
Member Author

Ah, interesting. In cases like this...

<p>hello world!</p>

<!-- corresponds to -->
<p>hello {{world}}!</p>

– Svelte generates three text nodes where there was previously only one. I think it's better if we don't assume that the server-rendered HTML came from a particular source, so we can't rely on comments being present in those cases. We definitely could generate a single text node, I'm not sure what the difference is performance-wise between granular updates versus replacing a large chunk of text if only a small part of it has changed.

How problematic is it if during enhancement hello world! changes to hello and gets followed by new text nodes for world and !? It seems like there are always going to be annoying mismatches (comments, inter-element whitespace) between HTML and template, and ideally the enhancer would work around them – but I say that rather glibly, having not been in the trenches during that particular war.

@evs-chris
Copy link
Contributor

I think the general assumption on progressive enhancement is that watching the 'Elements' tab in devtools will not show any flashes while the page is loading. I think google dings you on "render blocking javascript" if the DOM is changed by loading scripts, but I'm not positive. My opinion falls on the side of a few text nodes updating during initial render not being an issue, which is why I still haven't resolved that issue 😄.

@Swatinem Swatinem mentioned this issue Mar 14, 2017
@tanhauhau tanhauhau mentioned this issue Oct 22, 2019
1 task
@benmccann benmccann added the perf label May 10, 2021
@pngwn pngwn added compiler Changes relating to the compiler temp-stale and removed internals labels Jun 26, 2021
@Rich-Harris
Copy link
Member Author

Fixed in Svelte 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler Changes relating to the compiler perf
Projects
None yet
Development

No branches or pull requests

5 participants