Chrome上浏览器扩展内容脚本的ReactJS呈现问题

Chrome上浏览器扩展内容脚本的ReactJS呈现问题,reactjs,google-chrome,google-chrome-extension,browser-extension,Reactjs,Google Chrome,Google Chrome Extension,Browser Extension,我做了一个浏览器扩展,它将一个iframe注入到DOM中,DOM中包含一些html。我一直在尝试将React组件渲染到iframe中,但它不会渲染,并且我收到以下错误不变冲突:超出了最大更新深度。当组件在componentWillUpdate或componentDidUpdate内重复调用setState时,可能会发生这种情况。React限制嵌套更新的数量以防止无限循环 我已经尝试通过内容脚本渲染到iframe,甚至直接渲染到DOM,但我仍然遇到同样的问题。我知道正在调用组件的渲染函数,因为我在

我做了一个浏览器扩展,它将一个iframe注入到DOM中,DOM中包含一些html。我一直在尝试将React组件渲染到iframe中,但它不会渲染,并且我收到以下错误不变冲突:超出了最大更新深度。当组件在componentWillUpdate或componentDidUpdate内重复调用setState时,可能会发生这种情况。React限制嵌套更新的数量以防止无限循环

我已经尝试通过内容脚本渲染到iframe,甚至直接渲染到DOM,但我仍然遇到同样的问题。我知道正在调用组件的渲染函数,因为我在其中放置了一个console.log,它会显示消息;我还调试了它,断点在render函数中停止。此外,我添加了生命周期方法componentWillUpdate和componentDidUpdate,它们甚至没有被调用

//Index.jsx
import React from "react";
import ReactDOM from "react-dom";

class Index extends React.Component{
  constructor(props){
    super(props);
  }

  componentWillUpdate(){
    console.log('componentWillUpdate');
  }

  componentDidUpdate(){
    console.log('componentDidUpdate');
  }

  render() {
    console.log('render');
    return <div>Hello!</div>;
  }
}

ReactDOM.render(<Index/>, document.getElementById("g-root"))

// Including this code to show how I was adding the react component to the DOM if it is loaded immediately via manifest.json
// const app = document.createElement('div');
// app.id = "g-root";
// document.body.appendChild(app);
// ReactDOM.render(<Index />, app);


应该注意的是,在我开始尝试向项目中添加React之前,注入iframe和扩展作为一个整体工作得很好。

事实证明,这是一个内部库的问题,它与使用React组件呈现web组件有关

//webpack.config
const path = require('path');

module.exports = (env, args) => {
  return {
    mode,
    devtool,
    entry: {
      react: path.join(__dirname, './Index.jsx')
    },
    module: {
      rules: [{
        test: /\.jsx$/,        
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['env', 'react', 'es2015']
          }
        }
      }]
    },
    output: {
      path: path.join(__dirname, './'),
      filename: 'react.bundle.js'
    }
  }
};
<!--This gets loaded into the iframe-->
<!DOCTYPE html>
<html>
  <head>  
  </head>

  <body>
    <div id="g-root"></div>
    <script src="react/react.bundle.js"></script>
  </body>
</html>
//manifest.json *included just to show that it has the same issue on page load.

{
"content_scripts":
  [{
  "js":["react/react.bundle.js"],
  "run_at": "document_end",
  "matches": ["<all_urls>"]
  }]
}