# anujs-webpack4-ie7-8 **Repository Path**: wader/anujs-webpack4-ie7-8 ## Basic Information - **Project Name**: anujs-webpack4-ie7-8 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-03-05 - **Last Updated**: 2021-03-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # anujs-webpack4-ie7-8 基于 anujs 和 webpack4 兼容 ie7-8 的配置 该 webpack.config 只考虑了对 ie7 ie8 进行配置。 ## 使用方法 ``` // 安装依赖 npm i // 开启 development 模式 npm start // 开启 production 模式 npm run buildPreview // 开启 使用 react库的开发模式 npm run react // 开启 使用 react库的生产模式 npm run reactPreview // 浏览器访问 http://127.0.0.1:8087/production.html ``` ## anujs 1.4.7 发现的一些问题 1. React.createContext 无法通过 Provider  传入数据,这个问题是从 1.4.3 开始的,测试了 1.4.1 和 1.4.2 是可以的。 代码如下 ``` import React from 'react'; import ReactDom from 'react-dom'; const ThemeContext = React.createContext('light'); export default class CreateContext extends React.Component { render() { // Use a Provider to pass the current theme to the tree below. // Any component can read it, no matter how deep it is. // In this example, we're passing "dark" as the current value. return ( ); } } // A component in the middle doesn't have to // pass the theme down explicitly anymore. function Toolbar(props) { return (
); } function ThemedButton(props) { // Use a Consumer to read the current theme context. // React will find the closest theme Provider above and use its value. // In this example, the current theme is "dark". return {theme => {list.map((item, index) => { return (
{item}:0
); })} ); } } ``` 1. 在一个组件渲染完成后,通过 dom 操作在其中插入了 dom 节点,然后再对组件进行更新,dom 的渲染顺序和 react 的渲染结果不符(chrome,ie 都有) 代码如下 ``` import React from 'react'; import ReactDom from 'react-dom'; export default class InsertDom extends React.PureComponent { state = { list: [], }; componentDidMount() { console.log('box componentDidMount trigger'); } renderSpan = () => { const { list } = this.state; const last = list[list.length - 1]; const dom = document.createElement('div'); dom.innerHTML = `insert_${last}`; const div = document.getElementById(`list${last}`); div.parentElement.insertBefore(dom, div); }; clickHandle = () => { this.setState( { list: [...this.state.list, this.state.list.length], }, () => { this.renderSpan(); }, ); }; render() { const { list } = this.state; return (

在列表中插通过dom操作插入数据

{list.map((item, index) => { return (
{item}:0
); })}
); } } ``` ## anujs 1.4.3 发现的一些问题(已经在 1.4.4 修复了) 1. 使用 PureComponent 时,组件两次 setState 值不变并且父组件在此之前也进行过 setState,会导致该组件与其相邻的前面组件的 dom 节点位置互换 (chrom 67, ie7, ie8) 该问题出现需要满足如下几个条件: > 1. 组件使用 PureComponent > 2. 父组件进行过 setState(改不改变值都可以) > 3. 子组件 setState,但是值跟上一次相同 > 4. 子组件前面存在相邻的组件 组件代码如下 ``` // innerBox.jsx import React from 'react'; class InnerBox extends React.PureComponent { state = { current: 0, }; componentDidMount() { console.log('InnerBox render'); setTimeout(() => { console.log('current跟上次不一样,一切正常'); this.setState({ current: 1 }); }, 500); setTimeout(() => { console.log('current跟上次一样,dom位置互换'); this.setState({ current: 1 }); }, 1000); setTimeout(() => { console.log('current跟上次不一样,dom位置复原'); this.setState({ current: 2 }); }, 1500); setTimeout(() => { console.log('current跟上次一样,dom位置互换'); this.setState({ current: 2 }); }, 2000); } render() { console.log('inner render trigger'); return (
内部组件
); } } export default InnerBox; // wrapBox import React from 'react'; import InnerBox from './innerBox'; class WrapBox extends React.PureComponent { state = { value: 1, }; componentDidMount() { console.log('WrapBox render'); // 此处如果在组件创建以后,再次setState,会导致dom位置错误的现象发生 setTimeout(() => { console.log('父容器state值改变'); this.setState({ value: 1, }); }, 700); } /** * 渲染组件 */ render() { console.log('wrap render trigger'); return (
标题区域1
标题区域2
标题区域3
); } } export default WrapBox; ``` ## anujs 1.4.2 发现的一些问题(都已经在 1.4.3 修复了) 1. 在 webpack 的 `production` mode 下面,代码执行有错误,(chrome 66,ie7,ie8) ``` // dist/ReactIE.js 84 function miniCreateClass(ctor, superClass, methods, statics) { var className = ctor.name || String(ctor).match(/^function\s(\w+)/)[1]; var Ctor = Function("superClass", "ctor", "return function " + className + " (props, context) {\n superClass.apply(this, arguments); \n ctor.apply(this, arguments);\n }")(superClass, ctor); Ctor.displayName = className; var fn = inherit(Ctor, superClass); extend(fn, methods); if (statics) { extend(Ctor, statics); } return Ctor; } ``` 2. 在使用 ref 的时候,表现和 react 不一致 ``` export default class DifferentParent extends React.PureComponent { box = React.createRef(); componentDidMount() { console.log('react 的行为是获取的父元素高度是一致的,anujs是不一致的,', this.box.current.parentElement.offsetHeight); setTimeout(() => { console.log('async', this.box.current.parentElement.offsetHeight); }, 100); } render() { return
box
; } } ``` 3. 组件中包含