Merge pull request #6135 from matrix-org/t3chguy/fix/17494

ignore hash/fragment when de-duplicating links for url previews
This commit is contained in:
Michael Telatynski 2021-06-02 15:08:41 +01:00 committed by GitHub
commit 4290237bdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -278,15 +278,15 @@ export default class TextualBody extends React.Component {
// pass only the first child which is the event tile otherwise this recurses on edited events // pass only the first child which is the event tile otherwise this recurses on edited events
let links = this.findLinks([this._content.current]); let links = this.findLinks([this._content.current]);
if (links.length) { if (links.length) {
// de-dup the links (but preserve ordering) // de-duplicate the links after stripping hashes as they don't affect the preview
const seen = new Set(); // using a set here maintains the order
links = links.filter((link) => { links = Array.from(new Set(links.map(link => {
if (seen.has(link)) return false; const url = new URL(link);
seen.add(link); url.hash = "";
return true; return url.toString();
}); })));
this.setState({ links: links }); this.setState({ links });
// lazy-load the hidden state of the preview widget from localstorage // lazy-load the hidden state of the preview widget from localstorage
if (global.localStorage) { if (global.localStorage) {