fix: SSR bug on pages with no SSR handler

This commit is contained in:
Valerio Ageno
2024-05-23 22:44:57 +02:00
parent 5a30f36eb0
commit cfdd59f5fb
3 changed files with 6 additions and 4 deletions
-2
View File
@@ -22,8 +22,6 @@ use axum::{routing::get, Router};
use tower_http::services::ServeDir;
use tuono_lib::{ssr, Ssr};
const MODE: &'static = "prod";
// MODULE_IMPORTS
#[tokio::main]
@@ -21,6 +21,8 @@ export const RouteMatch = ({
if (!route.isRoot) {
return route.options.getParentRoute().component({
children: route.options.component({ data, isLoading }),
data,
isLoading,
})
}
@@ -7,6 +7,7 @@ interface UseServerSidePropsReturn {
data: any
isLoading: boolean
}
/*
* Use the props provided by the SSR and dehydrate the
* props for client side usage.
@@ -15,6 +16,7 @@ interface UseServerSidePropsReturn {
*/
export function useServerSideProps(
route: Route,
// User defined props
serverSideProps: any,
): UseServerSidePropsReturn {
const isFirstRendering = useRef<boolean>(true)
@@ -27,8 +29,8 @@ export function useServerSideProps(
!isFirstRendering.current,
)
const [data, setData] = useState(
serverSideProps || window.__TUONO_SSR_PROPS__.props,
const [data, setData] = useState<any>(
serverSideProps ?? window.__TUONO_SSR_PROPS__?.props,
)
useEffect(() => {