@@ -82,11 +82,13 @@ export const Preview = memo(
82
82
vercelProtectionBypass,
83
83
} = props
84
84
85
+ const [ stablePerspective , setStablePerspective ] = useState < typeof perspective | null > ( null )
86
+ const urlPerspective = stablePerspective === null ? perspective : stablePerspective
85
87
const previewUrl = useMemo ( ( ) => {
86
88
const url = new URL ( initialUrl )
87
89
// Always set the perspective that's being used, even if preview mode isn't configured
88
90
if ( ! url . searchParams . get ( urlSearchParamPreviewPerspective ) ) {
89
- url . searchParams . set ( urlSearchParamPreviewPerspective , perspective )
91
+ url . searchParams . set ( urlSearchParamPreviewPerspective , urlPerspective )
90
92
}
91
93
92
94
if ( vercelProtectionBypass || url . searchParams . get ( urlSearchParamVercelProtectionBypass ) ) {
@@ -102,7 +104,19 @@ export const Preview = memo(
102
104
}
103
105
104
106
return url
105
- } , [ initialUrl , perspective , vercelProtectionBypass ] )
107
+ } , [ initialUrl , urlPerspective , vercelProtectionBypass ] )
108
+
109
+ useEffect ( ( ) => {
110
+ /**
111
+ * If the preview iframe is connected to the loader, we know that switching the perspective can be done without reloading the iframe.
112
+ */
113
+ if ( loadersConnection === 'connected' ) {
114
+ /**
115
+ * Only set the stable perspective if it hasn't been set yet.
116
+ */
117
+ setStablePerspective ( ( prev ) => ( prev === null ? perspective : prev ) )
118
+ }
119
+ } , [ loadersConnection , perspective ] )
106
120
107
121
const { t} = useTranslation ( presentationLocaleNamespace )
108
122
const { devMode} = usePresentationTool ( )
0 commit comments