1- import { useEffect , useRef } from "preact/hooks" ;
1+ import { useEffect , useRef , useState } from "preact/hooks" ;
22import { Button } from "../../../design/button/Button" ;
33import styles from "./global-modal.module.css" ;
44import localStyles from "./AdAction.module.css" ;
@@ -11,7 +11,9 @@ export interface AdActionProps {
1111
1212export function AdAction ( { url, label } : AdActionProps ) {
1313 const dialogRef = useRef < HTMLDialogElement > ( null ) ;
14+ const iframeRef = useRef < HTMLIFrameElement > ( null ) ;
1415 const scrollPositionRef = useRef ( 0 ) ;
16+ const [ iframeKey , setIframeKey ] = useState ( 0 ) ; // To force iframe reload on each open
1517
1618 const handleOpenModal = ( ) => {
1719 // Save current scroll position
@@ -22,6 +24,10 @@ export function AdAction({ url, label }: AdActionProps) {
2224 document . body . classList . add ( "modal-open" ) ;
2325
2426 dialogRef . current ?. showModal ( ) ;
27+ iframeRef . current ?. contentWindow ?. postMessage (
28+ { type : "bolt-gaming-start-ads" } ,
29+ "*" ,
30+ ) ;
2531 } ;
2632
2733 const handleCloseModal = ( ) => {
@@ -31,6 +37,8 @@ export function AdAction({ url, label }: AdActionProps) {
3137 document . body . classList . remove ( "modal-open" ) ;
3238 document . body . style . top = "" ;
3339 window . scrollTo ( 0 , scrollPositionRef . current ) ;
40+
41+ setIframeKey ( ( prev ) => prev + 1 ) ;
3442 } ;
3543
3644 useEffect ( ( ) => {
@@ -80,6 +88,8 @@ export function AdAction({ url, label }: AdActionProps) {
8088 Close Demo < Close size = { 20 } />
8189 </ button >
8290 < iframe
91+ key = { iframeKey }
92+ ref = { iframeRef }
8393 src = { url }
8494 className = { localStyles . iframe }
8595 sandbox = "allow-scripts allow-same-origin allow-forms"
0 commit comments