Skip to content

Commit

Permalink
chore(router): remove perspective state from router
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Nov 5, 2024
1 parent daca134 commit 0075739
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 28 deletions.
13 changes: 0 additions & 13 deletions packages/sanity/src/router/RouterProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -198,14 +187,12 @@ export function RouterProvider(props: RouterProviderProps): ReactElement {
resolvePathFromState,
state: routerState,
stickyParams: stickyParamsByName,
perspectiveState,
}),
[
handleNavigateStickyParams,
navigate,
navigateIntent,
onNavigate,
perspectiveState,
resolveIntentLink,
resolvePathFromState,
routerState,
Expand Down
8 changes: 0 additions & 8 deletions packages/sanity/src/router/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,4 @@ export interface RouterContextValue {
* The current router state. See {@link RouterState}
*/
stickyParams: Record<string, string | undefined>

/**
* Values pertaining to the active perspective.
*/
perspectiveState: {
perspective: string | undefined
excludedPerspectives: string | undefined
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
useDocumentPreviewStore,
useSchema,
} from 'sanity'
import {useRouter} from 'sanity/router'

import {MissingSchemaType} from '../MissingSchemaType'
import {usePaneRouter} from '../paneRouter'
Expand Down Expand Up @@ -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<boolean>(false)
Expand All @@ -90,7 +88,6 @@ export function PaneItem(props: PaneItemProps) {

return (
<PaneItemPreview
perspective={perspective}
documentPreviewStore={documentPreviewStore}
icon={getIconWithFallback(icon, schemaType, DocumentIcon)}
layout={layout}
Expand Down Expand Up @@ -122,7 +119,6 @@ export function PaneItem(props: PaneItemProps) {
schemaType,
title,
hasSchemaType,
perspective,
documentPreviewStore,
layout,
documentPresence,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {TooltipDelayGroupProvider} from '../../../ui-components'
export interface PaneItemPreviewProps {
documentPreviewStore: DocumentPreviewStore
icon: ComponentType | false
perspective?: string
layout: GeneralPreviewLayoutKey
presence?: DocumentPresence[]
schemaType: SchemaType
Expand All @@ -38,7 +37,7 @@ export interface PaneItemPreviewProps {
* and are rendered by `<SanityDefaultPreview>`.
*/
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) ||
Expand All @@ -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, {
Expand Down

0 comments on commit 0075739

Please sign in to comment.