ractivejs / ractive

Next-generation DOM manipulation
http://ractive.js.org
MIT License
5.94k stars 396 forks source link

Whitespace in templates removed under certain conditions #3239

Closed LeJared closed 6 years ago

LeJared commented 6 years ago

Description:

See example below in jsfiddle. The leading whitespace in the first condition in the first paragraph is removed. It does not happen in the second paragraph. This seems to be trigger by the presence of the second condition in the first paragraph.

Versions affected:

at least 0.9.13 to 0.10.3

Reproduction:

https://jsfiddle.net/lejared/zaafvw7o/4/

dagnelies commented 6 years ago

...what a strange bug!

Here is a slightly simplified version covering one more case: https://jsfiddle.net/zaafvw7o/8/

<p>a{{#if 1}} b{{/if}}</p>
<p>{{#if 1}}d {{/if}}e</p>
<p>a{{#if 1}} b{{/if}}  /  {{#if 1}}d {{/if}}e</p>
<p>a{{#if 1}} b{{/if}}  /  {{#if 1}}d {{/if}}e / a{{#if 1}} b{{/if}}</p>
evs-chris commented 6 years ago

This is weird. I haven't really messed with the whitespace munging code in the parser before, so until I can poke at it some, preserveWhitespace: true should be a workaround. I'm guessing that whitespace stripping is pulling any whitespace inside of a block (element, section) when it should only be merging the space or removing from the first newline. Whitespace handling in HTML is already pretty weird too...

evs-chris commented 6 years ago

I'm pretty sure I've got this fixed, though the whitespace handling still isn't 100% ideal. For some reason, npm cli isn't showing the latest published versions, so Travis isn't able to publish. Once that's resolved, this should be fixed in edge and v0.10-dev. Thanks!