From 0f2cf841bb3d3ae475f6903501703548a3927ca3 Mon Sep 17 00:00:00 2001 From: Snorre Eskeland Brekke Date: Thu, 12 Dec 2024 09:34:42 +0100 Subject: [PATCH] fix: delays rendering the Start in Create banner until document is ready --- .../sanity/src/core/create/components/StartInCreateBanner.tsx | 3 ++- packages/sanity/src/core/create/types.ts | 1 + .../panes/document/document-layout/DocumentLayout.tsx | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/sanity/src/core/create/components/StartInCreateBanner.tsx b/packages/sanity/src/core/create/components/StartInCreateBanner.tsx index 54521640f65..9b8dbd93595 100644 --- a/packages/sanity/src/core/create/components/StartInCreateBanner.tsx +++ b/packages/sanity/src/core/create/components/StartInCreateBanner.tsx @@ -55,7 +55,8 @@ export function StartInCreateBanner(props: StartInCreateBannerProps) { function StartInCreateBannerInner(props: StartInCreateBannerProps & {appIdCache: AppIdCache}) { const {studioApp} = useStudioAppIdStore(props.appIdCache) - if (!studioApp) { + // we check documentReady here and not in the top wrapper, to allow the cache code to run while the document is loading + if (!studioApp || !props.documentReady) { return null } return diff --git a/packages/sanity/src/core/create/types.ts b/packages/sanity/src/core/create/types.ts index 83fdcb868ad..acdf9bd76c7 100644 --- a/packages/sanity/src/core/create/types.ts +++ b/packages/sanity/src/core/create/types.ts @@ -38,5 +38,6 @@ export interface StartInCreateBannerProps { documentType: ObjectSchemaType document: SanityDocumentLike isInitialValueLoading: boolean + documentReady: boolean panelPortalElementId: string } diff --git a/packages/sanity/src/structure/panes/document/document-layout/DocumentLayout.tsx b/packages/sanity/src/structure/panes/document/document-layout/DocumentLayout.tsx index acc23139fc3..54654bbf08a 100644 --- a/packages/sanity/src/structure/panes/document/document-layout/DocumentLayout.tsx +++ b/packages/sanity/src/structure/panes/document/document-layout/DocumentLayout.tsx @@ -82,6 +82,7 @@ export function DocumentLayout() { schemaType, value, isInitialValueLoading, + ready, } = useDocumentPane() const {params: paneParams} = usePaneRouter() const {features} = useStructureTool() @@ -259,6 +260,7 @@ export function DocumentLayout() { document={value} documentId={documentId} documentType={schemaType} + documentReady={ready} isInitialValueLoading={!!isInitialValueLoading} panelPortalElementId={DOCUMENT_PANEL_PORTAL_ELEMENT} />