diff --git a/front/packages/primitives/src/image/blurhash.web.tsx b/front/packages/primitives/src/image/blurhash.web.tsx index dc8bc80e..b1cf4ed6 100644 --- a/front/packages/primitives/src/image/blurhash.web.tsx +++ b/front/packages/primitives/src/image/blurhash.web.tsx @@ -276,6 +276,18 @@ const BlurhashDiv = forwardRef< ); }); +export const useRenderType = () => { + const [renderType, setRenderType] = useState<"ssr" | "hydratation" | "client">( + typeof window === "undefined" ? "ssr" : "hydratation", + ); + + useLayoutEffect(() => { + setRenderType("client"); + }, []); + + return renderType; +}; + export const BlurhashContainer = ({ blurhash, children, @@ -285,15 +297,7 @@ export const BlurhashContainer = ({ children?: ReactElement | ReactElement[]; }) => { const { css } = useYoshiki(); - const ref = useRef(null); - const [renderType, setRenderType] = useState<"ssr" | "hydratation" | "client">( - typeof window === "undefined" ? "ssr" : "hydratation", - ); - - useLayoutEffect(() => { - // If the html is empty, it was not SSRed. - if (ref.current?.innerHTML === "") setRenderType("client"); - }, []); + const renderType = useRenderType(); return (
- {renderType === "ssr" && } - {renderType === "client" && } + {renderType === "ssr" && } + {renderType === "client" && } {renderType === "hydratation" && ( -
+
)} {children}
diff --git a/front/packages/primitives/src/image/image.web.tsx b/front/packages/primitives/src/image/image.web.tsx index 77fb650b..9f26e178 100644 --- a/front/packages/primitives/src/image/image.web.tsx +++ b/front/packages/primitives/src/image/image.web.tsx @@ -25,7 +25,7 @@ import { useYoshiki } from "yoshiki/native"; import { imageBorderRadius } from "../constants"; import { Skeleton } from "../skeleton"; import type { ImageLayout, Props } from "./base-image"; -import { BlurhashContainer } from "./blurhash.web"; +import { BlurhashContainer, useRenderType } from "./blurhash.web"; export const Image = ({ src, @@ -54,18 +54,25 @@ export const Image = ({ return ( - setState("finished")} onError={() => setState("errored")} suppressHydrationWarning