Re: [w3c/webcomponents] [templates] Maybe each {{ ~ }} should be its own text node? (#683)

> Normalizing text nodes in that case would result in some weird edge cases like some Text nodes in a node template part not being in the final DOM tree due to them getting merged together, or even some Text nodes end up having extra contents.

lit-html uses comments to demark expressions, then removes the comment nodes from the template. This causes text spans like `a {{b}} c` to produce two adjacent Text nodes, `"a "` and `" c"`. And it's true that normalization of the template or template instance would cause severe problems.

In some research it looked like some versions of IE or Edge (and not other engines) might spontaneously normalize Nodes, but wouldn't merge Text nodes that had outstanding references to them. If that's the case, could that behavior be spec'ed?

> Specifically, if we created two node template parts `a` and `b` for `{{a}} b {{c}}`, should a.replacementNodes[0] be identical to a.replacementNodes[1]

I think that `{{a}} b {{c}}` really needs to create two node template parts because we need to be able to set values to non-text values, especially other TemplateInstances for nested templating.

This is a common way to compose templates in JSX and lit-html:

```js
render() {
  let a = html`<div>${1}</div>`;
  let b = html`<div>${2}</div>`;
  return html`
    <div>${a}${b}</div>
 `;
}
```

This would produce two templates, vaguely like this:

```html
<template id="a"><div>{{}}</div></template>
<template id="b"><div>{{}}</div></template>
<template id="outer"><div>{{}}{{}}</div></template>
```

The node parts in `outer` need to be independently assignable to other Nodes.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/683#issuecomment-341855081

Received on Saturday, 4 November 2017 00:00:57 UTC