mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-07-16 17:26:58 -04:00
Fixes #8896. ### What was happening `SharingBase.ensureUrlIsNotOutdated()` replaces the page URL with `httpRoot` (`/`) once the layout state diverges from the state recorded after load. That rewrite exists for the main site, so an outdated shortlink path (`/z/...`) doesn't linger in the address bar after you edit the code. Since #8166 started running the shared state-tracking (`SharingBase`) in embedded mode too — to keep the "Edit on Compiler Explorer" link in sync — the rewrite also fires inside `/e` iframes. There, `location.pathname` (`/e`) never equals `httpRoot` (`/`), so the first state change after load (an edit, or just layout churn) silently rewrites the iframe's URL to `/` — dropping both the `/e` path **and** the state hash. Reproduced with a `history.replaceState` spy: after two edits in an embed, the iframe's location is `/` with an empty hash. The visible symptoms are then browser-dependent, which is why it looked intermittent: Firefox restores an iframe's *session-history* URL when the parent page reloads, so the iframe comes back as `godbolt.org/` — the full site, showing the default language example, and (because cookies are unreadable in a cross-site iframe, per the `privacy_status` SameSite console error in the report) the privacy-policy popup. Chrome reloads iframes from their `src` attribute, so it never showed the problem. ### The fix Skip the rewrite entirely in embedded mode — the iframe's URL *is* the embedded state and must never be touched. The `a.link` "Edit on Compiler Explorer" state tracking from #8166 is unaffected. ### Tests New `cypress/e2e/embed.cy.ts`: - the embedded state's code loads (not the default example), - the `/e#state` URL survives state changes (fails before this fix: pathname becomes `/`, hash emptied), - the "Edit on Compiler Explorer" link still picks up edits (locks in #8166's behaviour). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: mattgodbolt-molty <mattgodbolt-molty@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>