From 00757391663a176a78c92e7cc5c15bb578eaaebf Mon Sep 17 00:00:00 2001 From: pedrobonamin Date: Tue, 5 Nov 2024 10:09:50 +0100 Subject: [PATCH] chore(router): remove perspective state from router --- packages/sanity/src/router/RouterProvider.tsx | 13 ------------- packages/sanity/src/router/types.ts | 8 -------- .../src/structure/components/paneItem/PaneItem.tsx | 4 ---- .../components/paneItem/PaneItemPreview.tsx | 5 ++--- 4 files changed, 2 insertions(+), 28 deletions(-) diff --git a/packages/sanity/src/router/RouterProvider.tsx b/packages/sanity/src/router/RouterProvider.tsx index 866c57d650a..2b80bbfcd56 100644 --- a/packages/sanity/src/router/RouterProvider.tsx +++ b/packages/sanity/src/router/RouterProvider.tsx @@ -177,17 +177,6 @@ export function RouterProvider(props: RouterProviderProps): ReactElement { const stickyParamsByName = useMemo(() => Object.fromEntries(stickyParams || []), [stickyParams]) - // Storing perspective state in a dedicated, stable, object allows it to be used for memoization - // separately to the entire router context object, which changes more frequently than the relevant - // sticky parameters. - // - const perspectiveState = useMemo(() => { - return { - perspective: stickyParamsByName.perspective, - excludedPerspectives: stickyParamsByName.excludedPerspectives, - } - }, [stickyParamsByName.excludedPerspectives, stickyParamsByName.perspective]) - const router: RouterContextValue = useMemo( () => ({ navigate, @@ -198,14 +187,12 @@ export function RouterProvider(props: RouterProviderProps): ReactElement { resolvePathFromState, state: routerState, stickyParams: stickyParamsByName, - perspectiveState, }), [ handleNavigateStickyParams, navigate, navigateIntent, onNavigate, - perspectiveState, resolveIntentLink, resolvePathFromState, routerState, diff --git a/packages/sanity/src/router/types.ts b/packages/sanity/src/router/types.ts index c097a14f755..b142f50b921 100644 --- a/packages/sanity/src/router/types.ts +++ b/packages/sanity/src/router/types.ts @@ -293,12 +293,4 @@ export interface RouterContextValue { * The current router state. See {@link RouterState} */ stickyParams: Record - - /** - * Values pertaining to the active perspective. - */ - perspectiveState: { - perspective: string | undefined - excludedPerspectives: string | undefined - } } diff --git a/packages/sanity/src/structure/components/paneItem/PaneItem.tsx b/packages/sanity/src/structure/components/paneItem/PaneItem.tsx index 52e6c262039..6195c896b8b 100644 --- a/packages/sanity/src/structure/components/paneItem/PaneItem.tsx +++ b/packages/sanity/src/structure/components/paneItem/PaneItem.tsx @@ -24,7 +24,6 @@ import { useDocumentPreviewStore, useSchema, } from 'sanity' -import {useRouter} from 'sanity/router' import {MissingSchemaType} from '../MissingSchemaType' import {usePaneRouter} from '../paneRouter' @@ -77,7 +76,6 @@ export function PaneItem(props: PaneItemProps) { const schema = useSchema() const documentPreviewStore = useDocumentPreviewStore() const {ChildLink} = usePaneRouter() - const {perspective} = useRouter().perspectiveState const documentPresence = useDocumentPresence(id) const hasSchemaType = Boolean(schemaType && schemaType.name && schema.get(schemaType.name)) const [clicked, setClicked] = useState(false) @@ -90,7 +88,6 @@ export function PaneItem(props: PaneItemProps) { return ( `. */ export function PaneItemPreview(props: PaneItemPreviewProps) { - const {icon, layout, perspective, presence, schemaType, value} = props + const {icon, layout, presence, schemaType, value} = props const title = (isRecord(value.title) && isValidElement(value.title)) || isString(value.title) || @@ -47,7 +46,7 @@ export function PaneItemPreview(props: PaneItemPreviewProps) { : null const releases = useReleases() - const {bundlesPerspective} = usePerspective() + const {bundlesPerspective, perspective} = usePerspective() const previewStateObservable = useMemo( () => getPreviewStateObservable(props.documentPreviewStore, schemaType, value._id, title, {