From 9113b8e0955c8d417b5f6a7a54fa92db908ffd71 Mon Sep 17 00:00:00 2001 From: p-sw Date: Sat, 20 Jul 2024 02:32:34 +0900 Subject: [PATCH] fix: make ssrFallback take callback as children --- packages/react/lib/ssrFallback.tsx | 6 ++++-- packages/react/lib/withSSD.tsx | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/react/lib/ssrFallback.tsx b/packages/react/lib/ssrFallback.tsx index abaff35..f252c9f 100644 --- a/packages/react/lib/ssrFallback.tsx +++ b/packages/react/lib/ssrFallback.tsx @@ -4,7 +4,9 @@ import { type ReactNode, useEffect, useState } from "react"; * This component allows components to use `document` as like they're always in the client side. * Return null if there is no `document` (which represents it's server side) or initial render(to avoid hydration error). */ -function ServerSideDocumentFallback({ children }: { children: ReactNode }) { +function ServerSideDocumentFallback({ + children, +}: { children: () => ReactNode }) { const [initialRender, setInitialRender] = useState(true); useEffect(() => { @@ -14,7 +16,7 @@ function ServerSideDocumentFallback({ children }: { children: ReactNode }) { if (typeof document === "undefined" /* server side */ || initialRender) return null; - return children; + return children(); } export { ServerSideDocumentFallback }; diff --git a/packages/react/lib/withSSD.tsx b/packages/react/lib/withSSD.tsx index ae1e293..13a402a 100644 --- a/packages/react/lib/withSSD.tsx +++ b/packages/react/lib/withSSD.tsx @@ -7,7 +7,7 @@ function withServerSideDocument

( const SSDocumentFallbackWrapper = (props: P) => { return ( - + {() => } ); };