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

在s-else的div里使用动态组件在ssr时会出现TypeError: Cannot destructure property 'id' of 'undefined' as it is undefined. #130

Closed
binbinecust opened this issue Sep 10, 2021 · 2 comments

Comments

@binbinecust
Copy link

描述

import san from 'san';
import aaa from './a';
import bbb from './b';

export default san.defineComponent({
    template: `<div>
        <div s-if="{{random}}">
            hahaha
        </div>
        <div s-else>
            <div s-is="mycomponent"></div>
        </div>
    </div>`,
    components: {
        aaa,
        bbb
    },
    computed: {
        random() {
            return Math.random() > 0.5
        }
    }
})

其中mycomponent为服务端注入的数据。值可以为aaa或者bbb

结果

当random为false时,会出现如下错误提示

TypeError: Cannot destructure property 'id' of 'undefined' as it is undefined.
    at Object.getRenderer (node_modules/san-ssr/src/runtime/resolver.ts:32:34)
    at eval (eval at createRenderer (node_modules/san-ssr/src/target-js/index.ts:92:60), <anonymous>:31:32)
    at node_modules/san-ssr/src/target-js/index.ts:76:20

推断

经测试,只有在s-else 里面有动态组件的情况下才会报错,可能是模版解析时导致的。

初步解决方案

可以用s-if替代s-else/s-else-if

@meixg meixg closed this as completed in 462c62b Sep 13, 2021
github-actions bot pushed a commit that referenced this issue Sep 13, 2021
## [4.9.1](v4.9.0...v4.9.1) (2021-09-13)

### Bug Fixes

* [#130](#130) ([462c62b](462c62b))
@github-actions
Copy link

🎉 This issue has been resolved in version 4.9.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This issue has been resolved in version 4.9.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

1 participant