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

分享函数onShareAppMessage异步问题 #14853

Open
LLL632648043 opened this issue Nov 20, 2023 · 5 comments
Open

分享函数onShareAppMessage异步问题 #14853

LLL632648043 opened this issue Nov 20, 2023 · 5 comments
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@LLL632648043
Copy link

相关平台

微信小程序

小程序基础库: 3.2.1
使用框架: React

复现步骤

分享函数onShareAppMessage无法使用promise对象或async/await语法

以下两种写法将导致onShareAppMessage分享函数失效,分享时图片和标题都是默认的并非onShareAppMessage所返回的对象。相同写法在原生的小程序是成功的。

import React, { Component } from 'react'
export default class Test extends Component {
  onShareAppMessage() {
    const promise = new Promise(resolve => setTimeout(() => resolve({ title: '异步标题'}), 2000))
    console.log('promise', promise)
    return {
      promise
    }
  }
  render() {
    return (
      <>test</>
    )
  }
}

import React, { Component } from 'react'
export default class Test extends Component {
  async onShareAppMessage() {
    const promise = await new Promise(resolve => setTimeout(() => resolve({ title: '异步标题'}), 2000))
    console.log('promise', promise)
    return {
      title: promise.title,
    
    }
  }
  render() {
    return (
      <>test</>
    )
  }
}

期望结果

onShareAppMessage支持异步,分享时标题图片为onShareAppMessage返回值内容

实际结果

(1)onShareAppMessage函数返回值不支持promise键值对
(2)async/await语法使得onShareAppMessage函数失效

环境信息

👽 Taro v3.6.16


  Taro CLI 3.6.16 environment info:
    System:
      OS: macOS 13.3.1
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 14.21.3 - ~/.nvm/versions/node/v14.21.3/bin/node
      npm: 6.14.18 - ~/.nvm/versions/node/v14.21.3/bin/npm
    npmPackages:
      @tarojs/cli: 3.6.19 => 3.6.19 
      @tarojs/components: 3.6.19 => 3.6.19 
      @tarojs/helper: 3.6.19 => 3.6.19 
      @tarojs/mini-runner: 3.6.19 => 3.6.19 
      @tarojs/plugin-framework-react: 3.6.19 => 3.6.19 
      @tarojs/plugin-platform-alipay: 3.6.19 => 3.6.19 
      @tarojs/plugin-platform-h5: 3.6.19 => 3.6.19 
      @tarojs/plugin-platform-jd: 3.6.19 => 3.6.19 
      @tarojs/plugin-platform-qq: 3.6.19 => 3.6.19 
      @tarojs/plugin-platform-swan: 3.6.19 => 3.6.19 
      @tarojs/plugin-platform-tt: 3.6.19 => 3.6.19 
      @tarojs/plugin-platform-weapp: 3.6.19 => 3.6.19 
      @tarojs/react: 3.6.19 => 3.6.19 
      @tarojs/runtime: 3.6.19 => 3.6.19 
      @tarojs/shared: 3.6.19 => 3.6.19 
      @tarojs/taro: 3.6.19 => 3.6.19 
      @tarojs/webpack-runner: 3.6.19 => 3.6.19 
      babel-preset-taro: 3.6.19 => 3.6.19 
      eslint-config-taro: 3.6.19 => 3.6.19 
      react: ^18.0.0 => 18.2.0 
      taro-ui: 3.1.0-beta.3 => 3.1.0-beta.3 
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Nov 20, 2023
@TheKonka
Copy link
Member

TheKonka commented Nov 23, 2023

image

没有复现,我测试转发的标题都是 异步标题

@LLL632648043
Copy link
Author

image

没有复现,我测试转发的标题都是 异步标题

请问下你taro版本是多少呢。我目前版本为3.6.10

@TheKonka
Copy link
Member

taro 最新版,不过应该跟taro 版本关系不大,我试了你说的 3.6.10 也是正常的

@LLL632648043
Copy link
Author

taro 最新版,不过应该跟taro 版本关系不大,我试了你说的 3.6.10 也是正常的

我重新创建了个taro项目,的确是可以。看来是代码问题。感谢回复哈

@whyer11
Copy link

whyer11 commented Jan 30, 2024

taro 最新版,不过应该跟taro 版本关系不大,我试了你说的 3.6.10 也是正常的

我重新创建了个taro项目,的确是可以。看来是代码问题。感谢回复哈

后来有找到具体啥问题不?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
Status: Todo
Development

No branches or pull requests

3 participants