From 0ff9e6fdc3f46693cd23e804583dc4d37585ecdc Mon Sep 17 00:00:00 2001 From: Aarnav Tale Date: Wed, 17 Apr 2024 17:42:44 -0400 Subject: [PATCH] feat: implement better ssr fallbacks --- app/routes/_data.acls._index/editor.tsx | 69 +++++++++++++---------- app/routes/_data.acls._index/fallback.tsx | 51 +++++++++++++++++ app/routes/_data.acls._index/route.tsx | 7 ++- tailwind.config.ts | 6 +- 4 files changed, 100 insertions(+), 33 deletions(-) create mode 100644 app/routes/_data.acls._index/fallback.tsx diff --git a/app/routes/_data.acls._index/editor.tsx b/app/routes/_data.acls._index/editor.tsx index bc779c5..b7b22c7 100644 --- a/app/routes/_data.acls._index/editor.tsx +++ b/app/routes/_data.acls._index/editor.tsx @@ -11,6 +11,8 @@ import { toast } from 'react-hot-toast/headless' import Button from '~/components/Button' import Spinner from '~/components/Spinner' +import Fallback from './fallback' + type EditorProperties = { readonly acl: string; readonly setAcl: (acl: string) => void; @@ -25,6 +27,8 @@ type EditorProperties = { export default function Editor({ data, acl, setAcl, mode }: EditorProperties) { const [light, setLight] = useState(false) + const [loading, setLoading] = useState(true) + const fetcher = useFetcher() const aclType = useMemo(() => data.aclType === 'json' ? json() : yaml(), [data.aclType]) @@ -35,6 +39,9 @@ export default function Editor({ data, acl, setAcl, mode }: EditorProperties) { theme.addEventListener('change', theme => { setLight(theme.matches) }) + + // Prevents the FOUC + setLoading(false) }, []) return ( @@ -44,38 +51,42 @@ export default function Editor({ data, acl, setAcl, mode }: EditorProperties) { 'rounded-b-lg rounded-tr-lg mb-2 overflow-hidden' )} > - {mode === 'edit' ? ( - { - setAcl(value) - }} - /> + {loading ? ( + ) : ( -
- { + setAcl(value) + }} + /> + ) : ( +
- - - -
+ + + + +
+ ) )} diff --git a/app/routes/_data.acls._index/fallback.tsx b/app/routes/_data.acls._index/fallback.tsx new file mode 100644 index 0000000..de07fd5 --- /dev/null +++ b/app/routes/_data.acls._index/fallback.tsx @@ -0,0 +1,51 @@ +import clsx from 'clsx' + +import Button from '~/components/Button' + +type FallbackProperties = { + readonly acl: string; + readonly where: 'client' | 'server'; +} + +export default function Fallback({ acl, where }: FallbackProperties) { + return ( + <> +
+