adobe / adobe/react-webcomponent
DOM content retrieved by @byContent still renders with the react component mounted
- 主要语言
- JavaScript
- 星标
- 104
- 派生
- 20
- PR 合并指标
- 30 天内没有已合并 PR
描述
### Expected Behaviour
As stated in the documentation:
> The DOM content will be moved when the React component is mounted. And, the content will be put back in its original location if the React component is later unmounted.
### Actual Behaviour
After some tests, if the property holding the content (inside the react component) is not used, even if the react component is still mounted, the DOM content is still put back in its original location.
#### Sample Code that illustrates the problem
###### React component:
```javascript
import React from 'react';
import PropTypes from 'prop-types';
const Example = ({
// products,
title,
content,
}) => (
{ title === 'yepe' && content }
{ title !== 'yepe' &&
Not the title I expected
});
Example.propTypes = {
// products: PropTypes.arrayOf(PropTypes.object).isRequired,
title: PropTypes.string,
content: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]).isRequired,
};
Example.defaultProps = {
title: 'no',
};
export default Example;
```
###### React container:
```javascript
import {
DOMModel,
byAttrVal,
byContent,
} from '@adobe/react-webcomponent';
import { connect } from 'react-redux';
import Example from '../example/example';
import { action } from 'actions';
const mapStateToProps = state => ({
products: state.products,
});
const ReduxedExample = connect(
mapStateToProps,
{ action },
)(Example);
class ExampleModel extends DOMModel {
@byAttrVal('title') title;
@byContent('.content') content;
}
// Register web component "example-component"
// using above Model
});
```
###### Html example:
```html
This is the correct title!
```

###### Other html example:
```html
This is the correct title!
```

贡献指南
调研方向
首先跟踪 issue 中描述的 DOMModel 和 @byContent 行为,以使用 ExampleModel 的复现和其 React 组件作为切入点。验证对于两个 title 值,内容何时会被移动或恢复,然后添加一个回归测试,证明即使组件不对其进行条件渲染,已挂载的内容仍会留在原位。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, react
- 领域
- frontend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100