diff --git a/shared/editor/components/Image.tsx b/shared/editor/components/Image.tsx
index 3da470e19b..8a8a74c1e0 100644
--- a/shared/editor/components/Image.tsx
+++ b/shared/editor/components/Image.tsx
@@ -11,6 +11,7 @@ import { ResizeLeft, ResizeRight } from "./ResizeHandle";
import useDragResize from "./hooks/useDragResize";
import { useTranslation } from "react-i18next";
import some from "lodash/some";
+import find from "lodash/find";
type Props = ComponentProps & {
/** Callback triggered when the image is clicked */
@@ -71,6 +72,9 @@ const Image = (props: Props) => {
const sanitizedSrc = sanitizeUrl(src);
const hasLink = some(node.attrs.marks ?? [], (mark) => mark.type === "link");
+ const imgLink =
+ find(node.attrs.marks ?? [], (mark) => mark.type === "link")?.attrs.href ??
+ "";
const handleOpen = React.useCallback(() => {
window.open(sanitizedSrc, "_blank");
@@ -135,14 +139,19 @@ const Image = (props: Props) => {
Image failed to load
- ) : (
- <>
+ ) : imgLink && !props.isSelected ? (
+
{
onClick={handleImageClick}
onTouchStart={handleImageTouchStart}
/>
- {!loaded && width && height && (
-
- )}
- >
+
+ ) : (
+
{
+ setError(true);
+ setLoaded(true);
+ }}
+ onLoad={(ev: React.SyntheticEvent) => {
+ // For some SVG's Firefox does not provide the naturalWidth, in this
+ // rare case we need to provide a default so that the image can be
+ // seen and is not sized to 0px
+ const nw = (ev.target as HTMLImageElement).naturalWidth || 300;
+ const nh = (ev.target as HTMLImageElement).naturalHeight;
+ setNaturalWidth(nw);
+ setNaturalHeight(nh);
+ setLoaded(true);
+
+ if (!node.attrs.width) {
+ setSize((state) => ({
+ ...state,
+ width: nw,
+ }));
+ }
+ }}
+ onClick={handleImageClick}
+ onTouchStart={handleImageTouchStart}
+ />
+ )}
+ {!loaded && width && height && (
+
)}
{isEditable && !isFullWidth && isResizable && (
<>