From 2b7c75d26c8d9c8c321ca0bfc052339d75a86d55 Mon Sep 17 00:00:00 2001 From: Soxasora Date: Sun, 28 Sep 2025 12:19:04 +0200 Subject: [PATCH 1/3] refactor: a component for each embed; remove iframeRef dep that caused flashes --- components/embed.js | 188 ++++++++++++++++++++++---------------------- 1 file changed, 94 insertions(+), 94 deletions(-) diff --git a/components/embed.js b/components/embed.js index b336fc81ea..cada9fa959 100644 --- a/components/embed.js +++ b/components/embed.js @@ -6,7 +6,7 @@ import { Button } from 'react-bootstrap' import { TwitterTweetEmbed } from 'react-twitter-embed' import YouTube from 'react-youtube' -function TweetSkeleton ({ className }) { +const TweetSkeleton = ({ className }) => { return (
@@ -21,9 +21,46 @@ function TweetSkeleton ({ className }) { ) } -export const NostrEmbed = memo(function NostrEmbed ({ src, className, topLevel, darkMode, id }) { +const TwitterEmbed = ({ id, className, topLevel }) => { + const [darkMode] = useDarkMode() + const [overflowing, setOverflowing] = useState(true) const [show, setShow] = useState(false) + + return ( +
+ } + onLoad={() => setOverflowing(true)} + /> + {overflowing && !show && + } +
+ ) +} + +const YouTubeEmbed = ({ id, className, start }) => { + return ( +
+ +
+ ) +} + +const NostrEmbed = ({ className, topLevel, id }) => { const iframeRef = useRef(null) + const [darkMode] = useDarkMode() + const [show, setShow] = useState(false) useEffect(() => { if (!iframeRef.current) return @@ -52,7 +89,7 @@ export const NostrEmbed = memo(function NostrEmbed ({ src, className, topLevel, window?.removeEventListener('message', setHeightFromIframe) iframeRef.current?.removeEventListener('load', handleIframeLoad) } - }, [iframeRef.current, darkMode]) + }, [id, darkMode]) return (
@@ -72,11 +109,10 @@ export const NostrEmbed = memo(function NostrEmbed ({ src, className, topLevel, }
) -}) +} const SpotifyEmbed = function SpotifyEmbed ({ src, className }) { const iframeRef = useRef(null) - // https://open.spotify.com/track/1KFxcj3MZrpBGiGA8ZWriv?si=f024c3aa52294aa1 // Remove any additional path segments const url = new URL(src) @@ -97,7 +133,7 @@ const SpotifyEmbed = function SpotifyEmbed ({ src, className }) { } return () => { window.onSpotifyIframeApiReady = null } - }, [iframeRef.current, url.pathname]) + }, [url.pathname]) return (
@@ -117,101 +153,65 @@ const SpotifyEmbed = function SpotifyEmbed ({ src, className }) { ) } -const Embed = memo(function Embed ({ src, provider, id, meta, className, topLevel, onError }) { - const [darkMode] = useDarkMode() - const [overflowing, setOverflowing] = useState(true) - const [show, setShow] = useState(false) - - // This Twitter embed could use similar logic to the video embeds below - if (provider === 'twitter') { - return ( - <> -
- } - onLoad={() => setOverflowing(true)} - /> - {overflowing && !show && - } -
- - ) - } - - if (provider === 'nostr') { - return ( - - ) - } +const WavlakeEmbed = ({ id, className }) => { + return ( +
+