Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(presentation): perspective switching regression (#8383)
Browse files Browse the repository at this point in the history
stipsan authored Jan 23, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 53e7dd7 commit 9caf5d8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/sanity/src/presentation/preview/Preview.tsx
Original file line number Diff line number Diff line change
@@ -82,11 +82,13 @@ export const Preview = memo(
vercelProtectionBypass,
} = props

const [stablePerspective, setStablePerspective] = useState<typeof perspective | null>(null)
const urlPerspective = stablePerspective === null ? perspective : stablePerspective
const previewUrl = useMemo(() => {
const url = new URL(initialUrl)
// Always set the perspective that's being used, even if preview mode isn't configured
if (!url.searchParams.get(urlSearchParamPreviewPerspective)) {
url.searchParams.set(urlSearchParamPreviewPerspective, perspective)
url.searchParams.set(urlSearchParamPreviewPerspective, urlPerspective)
}

if (vercelProtectionBypass || url.searchParams.get(urlSearchParamVercelProtectionBypass)) {
@@ -102,7 +104,19 @@ export const Preview = memo(
}

return url
}, [initialUrl, perspective, vercelProtectionBypass])
}, [initialUrl, urlPerspective, vercelProtectionBypass])

useEffect(() => {
/**
* If the preview iframe is connected to the loader, we know that switching the perspective can be done without reloading the iframe.
*/
if (loadersConnection === 'connected') {
/**
* Only set the stable perspective if it hasn't been set yet.
*/
setStablePerspective((prev) => (prev === null ? perspective : prev))
}
}, [loadersConnection, perspective])

const {t} = useTranslation(presentationLocaleNamespace)
const {devMode} = usePresentationTool()

0 comments on commit 9caf5d8

Please sign in to comment.