@@ -21,16 +21,12 @@ import {
21
21
SplitPanel ,
22
22
useSplitPanel ,
23
23
} from '../../components/SplitPanel/SplitPanel.js' ;
24
- import {
25
- DraftDocProvider ,
26
- useDraftDocData ,
27
- useDraftDoc ,
28
- } from '../../hooks/useDraftDoc.js' ;
24
+ import { DraftDocProvider , useDraftDoc } from '../../hooks/useDraftDoc.js' ;
29
25
import { useLocalStorage } from '../../hooks/useLocalStorage.js' ;
26
+ import { useStringParam } from '../../hooks/useQueryParam.js' ;
30
27
import { Layout } from '../../layout/Layout.js' ;
31
28
import { joinClassNames } from '../../utils/classes.js' ;
32
29
import { getDocPreviewPath , getDocServingPath } from '../../utils/doc-urls.js' ;
33
- import { CMSDoc } from '../../utils/doc.js' ;
34
30
35
31
interface DocumentPageProps {
36
32
collection : string ;
@@ -46,6 +42,13 @@ function getPreviewUrl(
46
42
const basePreviewPath = getDocPreviewPath ( { collectionId, slug} ) ;
47
43
const searchParams = new URLSearchParams ( window . location . search ) ;
48
44
searchParams . set ( 'preview' , 'true' ) ;
45
+ // Avoid passing through the ?locale= param (set by the CMS to preserve the
46
+ // preview frame locale).
47
+ // NOTE(stevenle): if we ever need to pass through the locale param, switch to
48
+ // using hash params for the internal CMS params that shouldn't pass through.
49
+ if ( searchParams . has ( 'locale' ) ) {
50
+ searchParams . delete ( 'locale' ) ;
51
+ }
49
52
const query = `${ searchParams . toString ( ) } ${ window . location . hash } ` ;
50
53
if ( selectedLocale ) {
51
54
const localizedPreviewPath = getDocPreviewPath ( {
@@ -274,7 +277,7 @@ DocumentPage.Preview = (props: PreviewProps) => {
274
277
'--iframe-height' : '100%' ,
275
278
'--iframe-scale' : '1' ,
276
279
} ) ;
277
- const [ selectedLocale , setSelectedLocale ] = useState ( '' ) ;
280
+ const [ selectedLocale , setSelectedLocale ] = useStringParam ( 'locale' , '' ) ;
278
281
const iframeRef = useRef < HTMLIFrameElement > ( null ) ;
279
282
280
283
const locales = draft . controller ! . getLocales ( ) || [ ] ;
0 commit comments