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

taro vue3 prerender 报错 #12622

Closed
Jackie-5 opened this issue Oct 8, 2022 · 0 comments · Fixed by #12670
Closed

taro vue3 prerender 报错 #12622

Jackie-5 opened this issue Oct 8, 2022 · 0 comments · Fixed by #12670
Assignees
Labels
F-vue3 Framework - Vue 3 T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Milestone

Comments

@Jackie-5
Copy link

Jackie-5 commented Oct 8, 2022

相关平台

微信小程序

复现仓库

https://gitee.com/Jackie-Wu/taro-vue3-prerender-error
小程序基础库: 1.06.2209190
使用框架: Vue 3

复现步骤

打开示例可以看到 vue3在配置了 prerender后编译时会报错
我打印 了这段代码 位置 https://github.com/NervJS/taro/blob/next/packages/taro-webpack5-runner/src/prerender/prerender.ts

renderToData({ path, params }) {
        console.log(path, params);
        return new Promise((resolve, reject) => {
            const dataReceiver = this.vm.run(`
        const page = require('${this.getRealPath(path)}')
        page.route = '${path}'
        module.exports = function (cb) {
          page.onLoad(${JSON.stringify(params || {})}, cb)
        }
      `, this.outputPath);

            dataReceiver((data) => {
                console.log(data, 'data')
                const domTree = data['root.cn.[0]'] || data['root.cn[0]'];
                if (domTree == null) {
                    reject(new Error('初始化渲染没有任何数据。'));
                }
                resolve(domTree);
            });
        });
    }

发现在 vue3 里 输出的结果是

[Object: null prototype] {
  'root.cn': [
    { nn: '5', sid: '_AM', option: {}, cn: [Array] },
    '0': { nn: '5', sid: '_AM', option: {}, cn: [Array] }
  ],
  'root.uid': 'pages/gift/index?$taroTimestamp=1665221258333',
  'root.cl': ''
}

这段的取参方式导致无法拿到对应模板数据

const domTree = data['root.cn.[0]'] || data['root.cn[0]'];

而我使用 data['root.cn'][0] 的参数是可以拿到数据的 但是 模板渲染就会有问题 标签显示错误

<import src="../../base.wxml"/>
<block wx:if="{{root.uid}}">
  <template is="taro_tmpl" data="{{root:root}}" />
</block>
<block wx:else>
<5 id="_AM" option='{}' ><8 ></8></5>
</block>

这个是dist打印出来的模板 标签是错误的

期望结果

正常编译

实际结果

取参错误,编译后模板错误

环境信息

Taro CLI 3.5.6 environment info:
    System:
      OS: macOS 11.6.8
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 16.13.2 - ~/.tnvm/versions/alinode/v7.4.0/bin/node
      Yarn: 1.22.17 - ~/.tnvm/versions/alinode/v7.4.0/bin/yarn
      npm: 8.1.2 - ~/.tnvm/versions/alinode/v7.4.0/bin/npm
    npmPackages:
      @tarojs/cli: 3.5.6 => 3.5.6
      @tarojs/components: 3.5.6 => 3.5.6
      @tarojs/helper: 3.5.6 => 3.5.6
      @tarojs/plugin-framework-vue3: 3.5.6 => 3.5.6
      @tarojs/plugin-platform-alipay: 3.5.6 => 3.5.6
      @tarojs/plugin-platform-jd: 3.5.6 => 3.5.6
      @tarojs/plugin-platform-qq: 3.5.6 => 3.5.6
      @tarojs/plugin-platform-swan: 3.5.6 => 3.5.6
      @tarojs/plugin-platform-tt: 3.5.6 => 3.5.6
      @tarojs/plugin-platform-weapp: 3.5.6 => 3.5.6
      @tarojs/router: 3.5.6 => 3.5.6
      @tarojs/runtime: 3.5.6 => 3.5.6
      @tarojs/shared: 3.5.6 => 3.5.6
      @tarojs/taro: 3.5.6 => 3.5.6
      @tarojs/taro-h5: 3.5.6 => 3.5.6
      @tarojs/webpack5-runner: 3.5.6 => 3.5.6
      babel-preset-taro: 3.5.6 => 3.5.6
      eslint-config-taro: 3.5.6 => 3.5.6
@taro-bot2 taro-bot2 bot added F-vue3 Framework - Vue 3 T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Oct 8, 2022
@Chen-jj Chen-jj self-assigned this Oct 9, 2022
@Chen-jj Chen-jj added this to the 3.5.7 milestone Oct 17, 2022
Chen-jj added a commit that referenced this issue Oct 18, 2022
* fix(webpack5): 修复 prerender 报错,fix #12622

* Update prerender.ts

Co-authored-by: Zakary <zakarycode@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-vue3 Framework - Vue 3 T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants