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

san fragment 标签 ssr 反解问题 #98

Open
zhuguoxi opened this issue Apr 8, 2021 · 1 comment
Open

san fragment 标签 ssr 反解问题 #98

zhuguoxi opened this issue Apr 8, 2021 · 1 comment

Comments

@zhuguoxi
Copy link
Member

zhuguoxi commented Apr 8, 2021

<!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
@harttle
Copy link
Member

harttle commented Apr 8, 2021

如果根元素是 fragment,是不能反解的。fragment 主要解决是多层组件嵌套中,可能带来较多不必要的标签。但是通常根组件只有一个。所以,根组件就别 fragment 了。

考虑在 san-ssr 里对这样的 case 报 warning 出来。有明确且合理的需求的情况,请重新打开本 issue。

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

No branches or pull requests

2 participants