Skip to content

Commit

Permalink
Update DocumentLayout.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Nov 22, 2024
1 parent b4f2248 commit f2b0b81
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
useElementRect,
} from '@sanity/ui'
import {isHotkey} from 'is-hotkey-esm'
import {type ReactNode, useCallback, useMemo, useState} from 'react'
import {memo, type ReactNode, useCallback, useMemo, useState} from 'react'
import {useTranslation} from 'react-i18next'
import {
ChangeConnectorRoot,
Expand Down Expand Up @@ -64,7 +64,7 @@ const StyledChangeConnectorRoot = styled(ChangeConnectorRoot)`
min-width: 0;
`

export function DocumentLayout() {
export const DocumentLayout = memo(function DocumentLayout() {
const {
changesOpen,
documentId,
Expand Down Expand Up @@ -159,6 +159,12 @@ export function DocumentLayout() {
[onPathOpen, onFocus],
)

// Memoize 'portalElements' to prevent unnecessary re-renders of PortalProvider
const portalElements = useMemo(
() => ({[DOCUMENT_PANEL_PORTAL_ELEMENT]: documentPanelPortalElement}),
[documentPanelPortalElement],
)

if (!schemaType) {
return (
<DocumentLayoutError
Expand Down Expand Up @@ -240,9 +246,7 @@ export function DocumentLayout() {

{/* These providers are added because we want the dialogs in `DocumentStatusBar` to be scoped to the document pane. */}
{/* The portal element comes from `DocumentPanel`. */}
<PortalProvider
__unstable_elements={{[DOCUMENT_PANEL_PORTAL_ELEMENT]: documentPanelPortalElement}}
>
<PortalProvider __unstable_elements={portalElements}>
<DialogProvider position={DIALOG_PROVIDER_POSITION} zOffset={zOffsets.portal}>
<PaneFooter ref={setFooterElement}>
<TooltipDelayGroupProvider>
Expand All @@ -259,7 +263,7 @@ export function DocumentLayout() {
</FieldActionsProvider>
</GetFormValueProvider>
)
}
})

/**
* Prevents whatever is inside of it from rendering when the pane is collapsed.
Expand Down

0 comments on commit f2b0b81

Please sign in to comment.