Skip to content

[Bug]: dangerouslySetInnerHTML 无法渲染 span 标签 #17747

@sealye09

Description

@sealye09

请先搜索是否存在类似提交

  • 我确定这个提交不是重复的

相关平台

  • 所有小程序
  • 微信小程序
  • 支付宝小程序
  • 百度小程序
  • 字节跳动小程序
  • QQ 轻应用
  • 京东小程序
  • 快应用平台(QuickApp)
  • Web 平台(H5)
  • 移动端(React-Native)
  • 鸿蒙(harmony)

小程序基础库版本

3.8.5

使用框架

React

问题描述

使用dangerouslySetInnerHTML,__html中包含 span,无法渲染span及其内容。
微信小程序平台异常,h5正常渲染。

import { View } from "@tarojs/components";

export default function Index() {
  return (
    <View className='index'>
      <View>dangerouslySetInnerHTML test</View>

      <View
        dangerouslySetInnerHTML={{ __html: `<span> span text </span>` }}
      ></View>

      <View
        dangerouslySetInnerHTML={{ __html: `<div> div text </div>` }}
      ></View>

      <View dangerouslySetInnerHTML={{ __html: `<p> p text </p>` }}></View>
    </View>
  );
}

Image

复现链接

复现步骤

初始化项目后默认配置,使用dangerouslySetInnerHTML,__html中包含 span

环境信息

👽 Taro v3.6.34                                                                                                                      
                                                                                                                                     
(node:23828) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

  Taro CLI 3.6.34 environment info:
    System:
      OS: Windows 11 10.0.26100
    Binaries:
      Node: 22.13.0 - ~\AppData\Local\fnm_multishells\16392_1747755820799\node.EXE
      npm: 11.0.0 - ~\AppData\Local\fnm_multishells\16392_1747755820799\npm.CMD
    npmPackages:
      @tarojs/cli: 3.6.34 => 3.6.34
      @tarojs/components: 3.6.34 => 3.6.34
      @tarojs/helper: 3.6.34 => 3.6.34
      @tarojs/plugin-framework-react: 3.6.34 => 3.6.34
      @tarojs/plugin-platform-alipay: 3.6.34 => 3.6.34
      @tarojs/plugin-platform-h5: 3.6.34 => 3.6.34
      @tarojs/plugin-platform-jd: 3.6.34 => 3.6.34
      @tarojs/plugin-platform-qq: 3.6.34 => 3.6.34
      @tarojs/plugin-platform-swan: 3.6.34 => 3.6.34
      @tarojs/plugin-platform-tt: 3.6.34 => 3.6.34
      @tarojs/plugin-platform-weapp: 3.6.34 => 3.6.34
      @tarojs/react: 3.6.34 => 3.6.34
      @tarojs/runtime: 3.6.34 => 3.6.34
      @tarojs/shared: 3.6.34 => 3.6.34
      @tarojs/taro: 3.6.34 => 3.6.34
      @tarojs/taro-loader: 3.6.34 => 3.6.34
      @tarojs/webpack5-runner: 3.6.34 => 3.6.34
      babel-preset-taro: 3.6.34 => 3.6.34
      eslint-config-taro: 3.6.34 => 3.6.34
      react: ^18.0.0 => 18.3.1

贡献代码

  • 我愿意修复这个错误

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions