san-ssr
san-ssr copied to clipboard
san fragment 标签 ssr 反解问题
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="root">
<!--s-frag-->
<div>123</div>
<!--/s-frag-->
</div>
<script src="https://unpkg.com/san@latest"></script>
<script>
var MyApp = san.defineComponent({
computed: {
name: function () {
const f = this.data.get('firstName')
const l = this.data.get('lastName')
return `${f} ${l}`
}
},
template: `<fragment>
<div>123</div>
</fragment>
`
});
var myApp = new MyApp({el: document.getElementById('root').firstElementChild});
myApp.attach(document.getElementById('root'));
</script>
</body>
</html>
错误信息:
san@latest:1 Uncaught Error: [SAN REVERSE ERROR] Element not found.
Paths: component[root] > div
at new le (san@latest:1)
at me (san@latest:1)
at ye (san@latest:1)
at i.Ue (san@latest:1)
at new i (san@latest:1)
at (index):29
如果根元素是 fragment,是不能反解的。fragment 主要解决是多层组件嵌套中,可能带来较多不必要的标签。但是通常根组件只有一个。所以,根组件就别 fragment 了。
考虑在 san-ssr 里对这样的 case 报 warning 出来。有明确且合理的需求的情况,请重新打开本 issue。