mirror of
https://github.com/element-hq/element-web.git
synced 2024-11-30 23:31:28 +03:00
Merge pull request #1189 from matrix-org/rav/fix_duplicate_preview_key
Fix a React duplicate key error
This commit is contained in:
commit
c29863362f
1 changed files with 11 additions and 4 deletions
|
@ -143,9 +143,15 @@ module.exports = React.createClass({
|
|||
if (this.props.showUrlPreview && !this.state.links.length) {
|
||||
var links = this.findLinks(this.refs.content.children);
|
||||
if (links.length) {
|
||||
this.setState({ links: links.map((link)=>{
|
||||
return link.getAttribute("href");
|
||||
})});
|
||||
// de-dup the links (but preserve ordering)
|
||||
const seen = new Set();
|
||||
links = links.filter((link) => {
|
||||
if (seen.has(link)) return false;
|
||||
seen.add(link);
|
||||
return true;
|
||||
});
|
||||
|
||||
this.setState({ links: links });
|
||||
|
||||
// lazy-load the hidden state of the preview widget from localstorage
|
||||
if (global.localStorage) {
|
||||
|
@ -158,12 +164,13 @@ module.exports = React.createClass({
|
|||
|
||||
findLinks: function(nodes) {
|
||||
var links = [];
|
||||
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var node = nodes[i];
|
||||
if (node.tagName === "A" && node.getAttribute("href"))
|
||||
{
|
||||
if (this.isLinkPreviewable(node)) {
|
||||
links.push(node);
|
||||
links.push(node.getAttribute("href"));
|
||||
}
|
||||
}
|
||||
else if (node.tagName === "PRE" || node.tagName === "CODE" ||
|
||||
|
|
Loading…
Reference in a new issue