From 674c99a05dd8018584b36f9c336e55abd95b0bf8 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Thu, 21 Sep 2023 13:02:40 +0800 Subject: [PATCH] Fix Lemmy post links not working Because it's self-referential --- src/components/status.jsx | 7 ++++++- src/utils/handle-content-links.js | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/status.jsx b/src/components/status.jsx index ef7944db..7c69274e 100644 --- a/src/components/status.jsx +++ b/src/components/status.jsx @@ -1128,7 +1128,12 @@ function Status({ lang={language} dir="auto" class="inner-content" - onClick={handleContentLinks({ mentions, instance, previewMode })} + onClick={handleContentLinks({ + mentions, + instance, + previewMode, + statusURL: url, + })} dangerouslySetInnerHTML={{ __html: enhanceContent(content, { emojis, diff --git a/src/utils/handle-content-links.js b/src/utils/handle-content-links.js index 9f0623fe..f401acde 100644 --- a/src/utils/handle-content-links.js +++ b/src/utils/handle-content-links.js @@ -1,7 +1,7 @@ import states from './states'; function handleContentLinks(opts) { - const { mentions = [], instance, previewMode } = opts || {}; + const { mentions = [], instance, previewMode, statusURL } = opts || {}; return (e) => { let { target } = e; target = target.closest('a'); @@ -50,7 +50,11 @@ function handleContentLinks(opts) { const hashURL = instance ? `#/${instance}/t/${tag}` : `#/t/${tag}`; console.log({ hashURL }); location.hash = hashURL; - } else if (states.unfurledLinks[target.href]?.url) { + } else if ( + states.unfurledLinks[target.href]?.url && + statusURL !== target.href + ) { + // If unfurled AND not self-referential e.preventDefault(); e.stopPropagation(); states.prevLocation = {