Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,20 @@ describe("createLinkRenderer", () => {
expect(isSmartLink("https://example.org/post")).toBe(false);
});

it("renders fallback anchor instead of YouTube preview when hideLinkPreviews is true", () => {
const { renderAnchor } = createLinkRenderer({
onQuoteClick,
hideLinkPreviews: true,
});
const element = renderAnchor({
href: "https://youtu.be/video123",
children: "YouTube link",
} as any);
const { container } = render(<>{element}</>);
expect(screen.queryByTestId("youtube-preview")).toBeNull();
expect(container.querySelector('a[href="https://youtu.be/video123"]')).not.toBeNull();
});

it("renders normal preview when hideLinkPreviews is false", () => {
const { renderAnchor } = createLinkRenderer({
onQuoteClick,
Expand Down
13 changes: 6 additions & 7 deletions components/drops/view/part/dropPartMarkdown/linkHandlers.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type {
AnchorHTMLAttributes,
ClassAttributes,
ImgHTMLAttributes} from "react";
import {
type ReactElement,
ImgHTMLAttributes,
ReactElement,
} from "react";
import { ErrorBoundary } from "react-error-boundary";
import type { ExtraProps } from "react-markdown";
Expand Down Expand Up @@ -89,10 +88,6 @@ export const createLinkRenderer = ({
renderExternalOrInternalLink(stableHref, anchorProps);
const matchSeize = findMatch(seizeHandlers, stableHref);
const renderOpenGraph = () => {
if (hideLinkPreviews) {
return renderFallbackAnchor();
}

if (!shouldUseOpenGraphPreview(stableHref, parsedUrl)) {
return renderFallbackAnchor();
}
Expand Down Expand Up @@ -148,6 +143,10 @@ export const createLinkRenderer = ({
}
};

if (hideLinkPreviews) {
return renderFallbackAnchor();
}

if (matchSeize) {
const rendered = renderFromHandler(matchSeize);
if (rendered) {
Expand Down