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

[BUG] options.html.transformText无效 #10457

Closed
bingtsingw opened this issue Oct 19, 2021 · 3 comments · Fixed by #10641
Closed

[BUG] options.html.transformText无效 #10457

bingtsingw opened this issue Oct 19, 2021 · 3 comments · Fixed by #10641
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Milestone

Comments

@bingtsingw
Copy link
Contributor

相关平台

微信小程序

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

解决方案

taro-runtimehtml-parser中调用transformText的代码返回有问题

  if (child.type === 'text') {
    const text = document.createTextNode(child.content)
    if (isFunction(options.html!.transformText)) {
      return options.html!.transformText(text, child)
    }
    parent?.appendChild(text)
    return text
  }

可以改成

  if (child.type === 'text') {
    let text = document.createTextNode(child.content)
    if (isFunction(options.html!.transformText)) {
      text = options.html!.transformText(text, child)
    }
    parent?.appendChild(text)
    return text
  }

期望结果

正常渲染text

实际结果

无法渲染text

环境信息

👽 Taro v3.3.9


  Taro CLI 3.3.9 environment info:
    System:
      OS: macOS 11.1
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 16.4.2 - ~/.nvs/default/bin/node
      Yarn: 1.22.10 - /usr/local/bin/yarn
      npm: 7.18.1 - ~/.nvs/default/bin/npm
    npmPackages:
      @tarojs/cli: 3.3.9 => 3.3.9 
      @tarojs/components: 3.3.9 => 3.3.9 
      @tarojs/mini-runner: 3.3.9 => 3.3.9 
      @tarojs/react: 3.3.9 => 3.3.9 
      @tarojs/runtime: 3.3.9 => 3.3.9 
      @tarojs/taro: 3.3.9 => 3.3.9 
      @tarojs/webpack-runner: 3.3.9 => 3.3.9 
      babel-preset-taro: 3.3.9 => 3.3.9 
      eslint-config-taro: 3.3.9 => 3.3.9 
      eslint-plugin-taro: 3.3.9 => 3.3.9 
      react: ^17.0.0 => 17.0.2 
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Oct 19, 2021
@bingtsingw bingtsingw changed the title options.html.transformText无效 [BUG] options.html.transformText无效 Oct 19, 2021
@jiaozitang
Copy link
Contributor

Taro 文档 https://taro-docs.jd.com/taro/docs/html/ 有相关介绍:

HTML 转义
由于进行 HTML 转义需要消耗较多的性能和较大的体积,默认而言 Taro 的 HTML 接口只接受转义后的 HTML 字符串,我们推荐直接在服务端返回转义后的 HTML。如果确实需要在客户端转义,开源社区有两个较好的选择:

he: 体积较大,但开源协议更为宽松
entities: 体积较小,但开源协议更为严格
你可能会需要高级选项的 transformText 配合 HTML 转义进行字符串渲染。

@bingtsingw
Copy link
Contributor Author

Taro 文档 https://taro-docs.jd.com/taro/docs/html/ 有相关介绍:

HTML 转义 由于进行 HTML 转义需要消耗较多的性能和较大的体积,默认而言 Taro 的 HTML 接口只接受转义后的 HTML 字符串,我们推荐直接在服务端返回转义后的 HTML。如果确实需要在客户端转义,开源社区有两个较好的选择:

he: 体积较大,但开源协议更为宽松 entities: 体积较小,但开源协议更为严格 你可能会需要高级选项的 transformText 配合 HTML 转义进行字符串渲染。

transformText这个API实现有BUG, 调用是无效的, 我解决方案里面写了相关代码, 可以看一下

@Chen-jj
Copy link
Contributor

Chen-jj commented Nov 12, 2021

3.3.13 修复

@Chen-jj Chen-jj added this to the 3.3.13 milestone Nov 12, 2021
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
None yet
Development

Successfully merging a pull request may close this issue.

3 participants