Skip to content
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

Vue.js mustach not correctly rendered only after indenting root element #8103

Closed
DanielSharkov opened this issue Apr 29, 2018 · 4 comments
Closed

Comments

@DanielSharkov
Copy link

@DanielSharkov DanielSharkov commented Apr 29, 2018

Version

2.5.16

Reproduction link

https://codesandbox.io/s/6jnlpno3lw

Steps to reproduce

This issue happens, when the root element is not indented and the mustache is split into several lines.

<template>
<div>
	<p>{{
		myVar
	}}</p>
</div>
</template>

Only when the root element is indented, the mustache gets rendered correctly.

<template>
	<div>
		<p>{{
			myVar
		}}</p>
	</div>
</template>

What also works, is when mustache is put into a single line and the root element is not indented.

<template>
<div>
	<p>{{ myVar }}</p>
</div>
</template>

What is expected?

The mustache should bind data

What is actually happening?

The mustache gets rendered plain text


Only wanted to prettify my code, so I split the mustache into several lines and removed the indent of the root element.

@Alexander-Taran
Copy link

@Alexander-Taran Alexander-Taran commented May 4, 2018

does work with a single space between <template> and root element:

<template> <p>{{
  myVar
}}</p></template>

does not with no space between them:

<template><p>{{ 
  myVar
}}</p></template>

@syntacticsolutions
Copy link

@syntacticsolutions syntacticsolutions commented May 8, 2018

Why would anyone write their code that way?

@DanielSharkov
Copy link
Author

@DanielSharkov DanielSharkov commented May 8, 2018

@syntacticsolutions This doesn't matter, fact is it's a bug, right?

@defcc
Copy link
Member

@defcc defcc commented May 9, 2018

Thanks @DanielSharkov , it should be a bug.

The root cause of different behavior with indent is bellow: https://github.com/yyx990803/de-indent/blob/master/index.js#L17-L24

    if (c === ' ' || c === '\t') {
      type = c
      cur = count(line, type)
      if (cur < min) {
        min = cur
      }
    } else {
      return str

Maybe we should add \r? pattern in the text interpolation regexp:

const defaultTagRE = /\{\{((?:.|\n)+?)\}\}/g
const regexEscapeRE = /[-.*+?^${}()|[\]\/\\]/g
const buildRegex = cached(delimiters => {
const open = delimiters[0].replace(regexEscapeRE, '\\$&')
const close = delimiters[1].replace(regexEscapeRE, '\\$&')
return new RegExp(open + '((?:.|\\n)+?)' + close, 'g')
})

@defcc defcc added the bug label May 9, 2018
@vuejs vuejs deleted a comment from lingchenzheng Jun 1, 2018
@sodatea sodatea added the has PR label Jun 25, 2018
@yyx990803 yyx990803 closed this in 8f04135 Oct 24, 2018
f2009 pushed a commit to f2009/vue that referenced this issue Jan 25, 2019
erdong-fe pushed a commit to erdong-fe/vue that referenced this issue May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants