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
5 changes: 5 additions & 0 deletions components/common/SandboxedExternalIframe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ interface SandboxedExternalIframeProps {
readonly onError?:
| React.IframeHTMLAttributes<HTMLIFrameElement>["onError"]
| undefined;
/** Fires once when the container scrolls into view and the iframe is about to render. */
readonly onVisible?: (() => void) | undefined;
}

/**
Expand All @@ -39,6 +41,7 @@ const SandboxedExternalIframe: React.FC<SandboxedExternalIframeProps> = ({
containerClassName,
onLoad,
onError,
onVisible,
}) => {
const containerRef = useRef<HTMLDivElement | null>(null);
const [isVisible, setIsVisible] = useState(false);
Expand Down Expand Up @@ -71,6 +74,7 @@ const SandboxedExternalIframe: React.FC<SandboxedExternalIframeProps> = ({

if (typeof window === "undefined" || !("IntersectionObserver" in window)) {
setIsVisible(true);
onVisible?.();
return;
}

Expand All @@ -79,6 +83,7 @@ const SandboxedExternalIframe: React.FC<SandboxedExternalIframeProps> = ({
const isIntersecting = entries.some((entry) => entry.isIntersecting);
if (isIntersecting) {
setIsVisible(true);
onVisible?.();
observerInstance.disconnect();
}
},
Expand Down
8 changes: 7 additions & 1 deletion components/drops/view/item/content/media/MediaDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function InteractiveHtmlMediaDisplay({
);
const [activeIndex, setActiveIndex] = useState(0);
const [didLoadCurrentUrl, setDidLoadCurrentUrl] = useState(false);
const [isIframeVisible, setIsIframeVisible] = useState(false);
const activeUrl = urls[activeIndex];

useEffect(() => {
Expand All @@ -61,6 +62,7 @@ function InteractiveHtmlMediaDisplay({
useEffect(() => {
setActiveIndex(0);
setDidLoadCurrentUrl(false);
setIsIframeVisible(false);
}, [urls]);

useEffect(() => {
Expand All @@ -70,6 +72,7 @@ function InteractiveHtmlMediaDisplay({
useEffect(() => {
if (
!activeUrl ||
!isIframeVisible ||
didLoadCurrentUrl ||
activeIndex + 1 >= urls.length ||
!shouldUseIframeFallbackTimeout(activeUrl)
Expand All @@ -88,7 +91,7 @@ function InteractiveHtmlMediaDisplay({
return () => {
globalThis.clearTimeout(timeoutId);
};
}, [activeIndex, activeUrl, didLoadCurrentUrl, urls.length]);
}, [activeIndex, activeUrl, didLoadCurrentUrl, isIframeVisible, urls.length]);

const advanceToNextUrl = () => {
setActiveIndex((current) =>
Expand Down Expand Up @@ -121,6 +124,9 @@ function InteractiveHtmlMediaDisplay({
setDidLoadCurrentUrl(true);
}}
onError={advanceToNextUrl}
onVisible={() => {
setIsIframeVisible(true);
}}
/>
);
}
Expand Down
6 changes: 5 additions & 1 deletion lib/media/arweave-gateways.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const ARWEAVE_GATEWAY_HOSTS = [
"gateway.ar.io",
] as const;

// gateway.ar.io redirects interactive content to <txid>.ar.io (not
// <txid>.gateway.ar.io), so CSP / remote-pattern lists must also allow ar.io.
const ADDITIONAL_CSP_HOSTS = ["ar.io"] as const;
Comment thread
simo6529 marked this conversation as resolved.

const dedupe = (values: readonly string[]): string[] =>
Array.from(new Set(values));

Expand All @@ -26,7 +30,7 @@ const ARWEAVE_GATEWAY_EXACT_HOSTS = dedupe(ARWEAVE_GATEWAY_HOSTS);
const ARWEAVE_GATEWAY_WILDCARD_BASE_HOSTS = dedupe(ARWEAVE_GATEWAY_HOSTS);

export const ARWEAVE_GATEWAY_CSP_SOURCES = dedupe(
ARWEAVE_GATEWAY_HOSTS.flatMap((hostname) => [
[...ARWEAVE_GATEWAY_HOSTS, ...ADDITIONAL_CSP_HOSTS].flatMap((hostname) => [
`https://${hostname}`,
`https://*.${hostname}`,
])
Expand Down