File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -17,8 +17,8 @@ export function IFramePreview({ content }: IFramePreviewProps): React.ReactEleme
1717
1818 const onLoadListener = useCallback ( ( ) => {
1919 if ( content . postMessage ) {
20- const url = new URL ( content . href )
21- iFrameElement . current ?. contentWindow ?. postMessage ( content . postMessage , url . origin )
20+ // use * as URL reference to avoid cors when posting message with new reference:
21+ iFrameElement . current ?. contentWindow ?. postMessage ( content . postMessage , '*' )
2222 }
2323 } , [ content . postMessage , content . href ] )
2424
@@ -31,6 +31,14 @@ export function IFramePreview({ content }: IFramePreviewProps): React.ReactEleme
3131 return ( ) => currentIFrame . removeEventListener ( 'load' , onLoadListener )
3232 } , [ onLoadListener ] )
3333
34+ // Handle postMessage updates when iframe is already loaded
35+ useEffect ( ( ) => {
36+ if ( content . postMessage && iFrameElement . current ?. contentWindow ) {
37+ // use * as URL reference to avoid cors when posting message with new reference:
38+ iFrameElement . current . contentWindow . postMessage ( content . postMessage , '*' )
39+ }
40+ } , [ content . postMessage , content . href ] )
41+
3442 const style : Record < string , string | number > = { }
3543 if ( content . dimensions ) {
3644 style [ '--preview-render-width' ] = content . dimensions . width
You can’t perform that action at this time.
0 commit comments