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

4.0.8 版本的 Taro.options.html 为空 #17083

Open
Jeff-Tian opened this issue Dec 26, 2024 · 1 comment
Open

4.0.8 版本的 Taro.options.html 为空 #17083

Jeff-Tian opened this issue Dec 26, 2024 · 1 comment

Comments

@Jeff-Tian
Copy link
Contributor

Jeff-Tian commented Dec 26, 2024

相关平台

微信小程序

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

复现步骤

  1. 在 3.6.35 版本中执行 yarn dev:weapp,可以打印出 Taro.options.html 为一个对象
  2. 将 3.6.35 升级到 4.0.8
  3. 再次打印 Taro.options.html
  4. 结果为空
  5. 期待和 3.6.35 一样,为一个对象

期望结果

期待和 3.6.35 一样,为一个对象。 __dangerouslySetInnerHTML 设置的 HTML 可以在微信小程序上正常显示。

实际结果

结果为空。导致在 __dangerouslySetInnerHTML 设置的 HTML,在微信小程序上展示不出来。

环境信息

taro info
👽 Taro v4.0.8

  Taro CLI 4.0.8 environment info:
    System:
      OS: macOS 15.2
      Shell: 5.9 - /bin/zsh
    Binaries:
@Jeff-Tian
Copy link
Contributor Author

Jeff-Tian commented Dec 26, 2024

目前发现可以通过在 app.tsx 里手动添加:

if (!Taro.options.html) {
  Taro.options.html = {
    skipElements: new Set(["style", "script"]),
    voidElements: new Set([
      "!doctype",
      "area",
      "base",
      "br",
      "col",
      "command",
      "embed",
      "hr",
      "img",
      "input",
      "keygen",
      "link",
      "meta",
      "param",
      "source",
      "track",
      "wbr",
    ]),
    closingElements: new Set([
      "html",
      "head",
      "body",
      "p",
      "dt",
      "dd",
      "li",
      "option",
      "thead",
      "th",
      "tbody",
      "tr",
      "td",
      "tfoot",
      "colgroup",
    ]),
    renderHTMLTag: false,
  };
}

解决。

不知道有没有通过配置的方式可以来设置 Taro.options.html ?

This was referenced Dec 28, 2024
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

1 participant