adobe / adobe/react-webcomponent
DOM content retrieved by @byContent still renders with the react component mounted
- Ngôn ngữ chính
- JavaScript
- Star
- 104
- Fork
- 20
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
### 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!
```

Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu bằng cách lần theo hành vi của DOMModel và @byContent được mô tả trong issue, sử dụng bản tái hiện với ExampleModel và component React của nó làm điểm bắt đầu. Xác minh thời điểm nội dung được di chuyển hoặc khôi phục đối với cả hai giá trị title, sau đó thêm một regression test cho thấy nội dung đã mount vẫn ở nguyên vị trí ngay cả khi component không render nội dung đó một cách có điều kiện.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, react
- Lĩnh vực
- frontend
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100