diff --git a/src/gui/components/_legacy.py b/src/gui/components/_legacy.py index a23c2f5..88b81e1 100644 --- a/src/gui/components/_legacy.py +++ b/src/gui/components/_legacy.py @@ -815,17 +815,29 @@ a[data-testid="stPageLink"][href$="/close/"] { // reload, no websocket churn. Fall back to a hard nav if the // helper link hasn't rendered yet (first paint race) so the // button is never a no-op. + // + // The page_link's anchor uses ``data-testid="stPageLink-NavLink"`` + // (the outer wrapper div carries the bare ``stPageLink`` testid; + // dispatching click on the wrapper doesn't fire Streamlit's + // React onClick handler). ``href*="close"`` covers both root + // (/close) and base-path (e.g. /myapp/close) deployments. closeBtn.addEventListener('click', function (e) {{ e.preventDefault(); var helper = doc.querySelector( - 'a[data-testid="stPageLink"][href$="/close"], ' + - 'a[data-testid="stPageLink"][href$="/close/"]' + 'a[data-testid="stPageLink-NavLink"][href*="close"]' ); if (helper) {{ helper.click(); - }} else {{ - window.location.href = './close'; + return; }} + // Hard-nav fallback. ``window`` inside this script is the + // component iframe's window — changing ITS location only + // navigates the iframe (which lives in srcdoc and is + // invisible). Use the parent doc's location so the whole + // app navigates. + var topWin = (doc.defaultView) || window.parent || window.top || window; + try {{ topWin.location.href = './close'; }} + catch (err) {{ window.top.location.href = './close'; }} }}); div.appendChild(helpBtn);