Repository navigation
Swaps: another origin's module scripts do not decide the swap; a fallback load still morphs - #161
Merged
Merged
Conversation
…back load still morphs The swap imported every module script of the next page and loaded the page instead if any failed. A CDN's injected analytics beacon (Cloudflare's, on realworld.tiaforge.dev) blocked by an extension or offline turned every swap into a load. Only the page's own-origin modules are imported and awaited now; another origin's run after the commit through script elements, once per document, so their `integrity` and `crossorigin` apply (an `import()` ignored the integrity). A swap that loads instead navigated with `location.assign()`, whose navigation carries no link: the page's `pageswap` found no row and nothing morphed. It now navigates with the link in `info`, as `navigate()` calls do, here and where a history write makes the swap navigate again. e2e/permanent: a beacon on another origin that does not load, whose integrity does not match, and that runs once per document; and a swap that loads instead still morphing its pair. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AjKzdzTBYrLUCJWpL1Vstr
Firefox has no `pagereveal`: nothing is recorded, which is no transitions between documents, not a failed morph. WebKit reports a script whose integrity does not match without its URL: filtered as the others are. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AjKzdzTBYrLUCJWpL1Vstr
… error Not as a console message: the filter goes where the steps' page collects its errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AjKzdzTBYrLUCJWpL1Vstr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On realworld.tiaforge.dev, Cloudflare Web Analytics injects a module script from another origin into every page:
Two things went wrong because of it:
prepareimport()ed everyscript[type=module][src]of the next page and gave up if any import failed. With the beacon blocked (by an ad blocker, or by a network that doesn't allow its host), every link fell back to a full page load. Theimport()also ignored the tag'sintegrity, so a swap ran a script that a page load would have blocked.fail()usedlocation.assign(), whose navigation carries no link.transition.tsthen found no row onpageswap, so nodata-sn-transitionpair was named.Reproduced against the live site in Chromium: with the beacon blocked, every article link did a full load with no title morph; with the beacon stubbed in, every link swapped and morphed.
Fix
src/swap-run.ts: only the page's same-origin module scripts are imported, and only they decide whether the swap succeeds. Module scripts from another origin are run after the commit as real<script>elements, sointegrity,crossoriginand the nonce apply. They run once per document, the swap doesn't wait for them, and if one fails it fails alone, as on a page load.src/swap.ts+src/links.ts: the swap's own navigations (the fallback load, and the navigation it starts again after a history write) go throughnavigation.navigate()with the link ininfo, the same waynavigate()calls already do. The load'spageswapthen finds the row and the pair morphs.docs/navigation.md: swaps, page transitions) and a changelog entry.Tests
New steps in
e2e/permanent/run.mjs, using a second server on another origin (localhostagainst the pages'127.0.0.1) that injects a beacon into B the way Cloudflare does:integritydoesn't match: the page swaps, and the beacon is blocked;In Chromium, all steps pass, and without the
src/changes three of the four new ones fail (marker null,beacon 1,pair false). Firefox and WebKit aren't installed in this environment; CI runs both.npm test(3,599 tests),npm run typecheckandsize --checkpass.Generated by Claude Code