From 3a3b7c1dd1014a2c5fdf8e5b485c6769a3455a9e Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sun, 29 Dec 2024 14:21:01 +0100 Subject: [PATCH 1/3] [NoSsr] Reduce bundle size --- packages/react/src/unstable-no-ssr/NoSsr.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react/src/unstable-no-ssr/NoSsr.tsx b/packages/react/src/unstable-no-ssr/NoSsr.tsx index 4c8f5db4b5..09b14b2846 100644 --- a/packages/react/src/unstable-no-ssr/NoSsr.tsx +++ b/packages/react/src/unstable-no-ssr/NoSsr.tsx @@ -33,8 +33,8 @@ function NoSsr(props: NoSsrProps): React.JSX.Element { } }, [defer]); - // We need the Fragment here to force react-docgen to recognise NoSsr as a component. - return {mountedState ? children : fallback}; + // TODO casting won't be needed at one point https://github.com/DefinitelyTyped/DefinitelyTyped/pull/65135 + return (mountedState ? children : fallback) as React.JSX.Element; } NoSsr.propTypes /* remove-proptypes */ = { From 886961343782f7f8672948c85b63f73762d5f6d6 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sun, 29 Dec 2024 19:42:28 +0100 Subject: [PATCH 2/3] I guess it's simpler --- packages/react/src/unstable-no-ssr/NoSsr.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/react/src/unstable-no-ssr/NoSsr.tsx b/packages/react/src/unstable-no-ssr/NoSsr.tsx index 09b14b2846..3597340914 100644 --- a/packages/react/src/unstable-no-ssr/NoSsr.tsx +++ b/packages/react/src/unstable-no-ssr/NoSsr.tsx @@ -17,7 +17,7 @@ import { NoSsrProps } from './NoSsr.types'; * * Documentation: [Base UI Unstable No Ssr](https://base-ui.com/react/components/unstable-no-ssr) */ -function NoSsr(props: NoSsrProps): React.JSX.Element { +function NoSsr(props: NoSsrProps): React.ReactNode { const { children, defer = false, fallback = null } = props; const [mountedState, setMountedState] = React.useState(false); @@ -33,8 +33,7 @@ function NoSsr(props: NoSsrProps): React.JSX.Element { } }, [defer]); - // TODO casting won't be needed at one point https://github.com/DefinitelyTyped/DefinitelyTyped/pull/65135 - return (mountedState ? children : fallback) as React.JSX.Element; + return mountedState ? children : fallback; } NoSsr.propTypes /* remove-proptypes */ = { From 07de69fbdd4eefb175c42401ac28db9df7695979 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sun, 29 Dec 2024 19:48:29 +0100 Subject: [PATCH 3/3] safer --- packages/react/src/unstable-no-ssr/NoSsr.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/react/src/unstable-no-ssr/NoSsr.tsx b/packages/react/src/unstable-no-ssr/NoSsr.tsx index 3597340914..621fe83009 100644 --- a/packages/react/src/unstable-no-ssr/NoSsr.tsx +++ b/packages/react/src/unstable-no-ssr/NoSsr.tsx @@ -17,7 +17,7 @@ import { NoSsrProps } from './NoSsr.types'; * * Documentation: [Base UI Unstable No Ssr](https://base-ui.com/react/components/unstable-no-ssr) */ -function NoSsr(props: NoSsrProps): React.ReactNode { +function NoSsr(props: NoSsrProps): React.JSX.Element { const { children, defer = false, fallback = null } = props; const [mountedState, setMountedState] = React.useState(false); @@ -33,7 +33,10 @@ function NoSsr(props: NoSsrProps): React.ReactNode { } }, [defer]); - return mountedState ? children : fallback; + // TODO casting won't be needed at one point https://github.com/DefinitelyTyped/DefinitelyTyped/pull/65135 + // We could replace React.JSX.Element with React.ReactNode. + // But first, we need to bump min typescript support to version to 5.1 and enough people to adopt the above change. + return (mountedState ? children : fallback) as React.JSX.Element; } NoSsr.propTypes /* remove-proptypes */ = {