web: boosted links read href FRESH at click time — fix stale nav after a morph swap

Reported: on blog.rose-ash.com, home --boosted nav--> a post --click "edit"--> lands on
/tags (a HOME footer link), not /<slug>/edit; subsequent navs stop updating.

Root cause: an innerHTML boost swap uses morph-children, which REUSES DOM nodes in place
(matched positionally when links have no id). The home footer's <a href="/tags"> element is
re-purposed as the post's <a href="/compose-demo/edit"> — its href attribute is rewritten,
but bind-client-route-click had captured the OLD href in its click closure, and the element's
is-processed? mark survived the morph (so boost-descendants skipped re-binding it). Clicking
the reused "edit" link fired the stale /tags closure.

Fix: bind-client-route-click now reads the href FRESH from the element at click time
(dom-get-attr link "href", falling back to the captured value) instead of trusting the
closure. A reused node then always follows its CURRENT href — robust to morph reuse without
needing to clear marks or remove listeners. Recompiled the web stack (.sxbc + manifest).

TEST-FIRST: lib/host/playwright/{boost-nav.spec.js, run-boost-nav-check.sh} reproduces the
exact flow (home -> boosted nav -> click edit -> assert URL is /compose-demo/edit, NOT /tags)
against an ephemeral server. Confirmed RED before the fix (landed on /tags), GREEN after. No
regressions: relate-picker 3/3 (incl. boosted-nav populate) + block-editor 1/1 still pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-01 05:55:46 +00:00
parent f804a71726
commit a511b21dd2
5 changed files with 108 additions and 4 deletions

View File

@@ -0,0 +1,37 @@
// Regression for the boosted-navigation link-rebinding bug (reported on blog.rose-ash.com):
// home --boosted nav--> a post --click "edit"--> lands on /tags (a HOME footer link),
// not /<slug>/edit. After a boost swap, the swapped-in links carry a STALE binding from
// the previous page. Run by run-boost-nav-check.sh against an ephemeral host server
// (serve.sh seeds /compose-demo + the home footer's /tags link).
const { test, expect } = require('playwright/test');
const BASE = process.env.SX_TEST_URL || 'http://127.0.0.1:8914';
async function waitReady(page) {
await expect(page.locator('html[data-sx-ready="true"]')).toHaveCount(1, { timeout: 45000 });
}
test.describe('boosted navigation (browser-only)', () => {
test('a post link clicked AFTER a boosted nav navigates to the right target (not a stale home link)', async ({ page }) => {
test.setTimeout(90000);
// 1) load HOME (its footer has a /tags link — the stale target the bug lands on)
await page.goto(BASE + '/');
await waitReady(page);
await expect(page.locator('a[href="/tags"]')).toHaveCount(1); // home has the /tags link
// 2) boosted nav HOME -> the composed post (no full reload)
await page.locator('a[href="/compose-demo/"]').first().click();
await expect(page.locator('body')).toContainText('composition object', { timeout: 15000 });
expect(page.url()).toContain('/compose-demo/');
// 3) click the post's "edit" link — brought in by the swap
await expect(page.locator('a[href="/compose-demo/edit"]')).toHaveCount(1);
await page.locator('a[href="/compose-demo/edit"]').click();
await page.waitForTimeout(3000);
// 4) it MUST navigate to the edit route (guarded -> the login view is fine, the URL is
// pushed to /compose-demo/edit), and MUST NOT land on the stale /tags link.
expect(page.url()).not.toContain('/tags');
expect(page.url()).toContain('/compose-demo/edit');
});
});

View File

@@ -0,0 +1,51 @@
#!/usr/bin/env bash
# Regression harness for the boosted-nav link-rebinding bug (composition step polish).
# Spins up an EPHEMERAL host server (this worktree's binary + lib + web + WASM), which on
# boot seeds /compose-demo and the home footer's /tags link, runs boost-nav.spec.js in the
# main worktree's Playwright, then tears down. No live-site dependency.
#
# bash lib/host/playwright/run-boost-nav-check.sh
#
# Requires: the OCaml binary built + Playwright + chromium in /root/rose-ash.
set -uo pipefail
cd "$(git rev-parse --show-toplevel)"
ROOT=$(pwd)
PORT="${BOOST_PORT:-8914}"
PW_DIR="${PW_DIR:-/root/rose-ash}"
USER="admin"; PASS="boost-check-pw"; SECRET="boost-check-secret"
PDIR=$(mktemp -d)
SPEC_SRC="lib/host/playwright/boost-nav.spec.js"
SPEC_DST="$PW_DIR/tests/playwright/_boost-nav-check.spec.js"
SERVE_LOG=$(mktemp)
cleanup() {
[ -n "${SVPID:-}" ] && kill "$SVPID" 2>/dev/null
local pid
pid=$(ss -lptn "sport = :$PORT" 2>/dev/null | grep -oE 'pid=[0-9]+' | head -1 | cut -d= -f2)
[ -n "$pid" ] && kill "$pid" 2>/dev/null
rm -f "$SPEC_DST" "$SERVE_LOG"; rm -rf "$PDIR"
}
trap cleanup EXIT
echo "== starting ephemeral host server on :$PORT (persist=$PDIR) =="
SX_SERVING_JIT=1 HOST_PORT="$PORT" SX_PERSIST_DIR="$PDIR" \
SX_ADMIN_USER="$USER" SX_ADMIN_PASSWORD="$PASS" SX_SESSION_SECRET="$SECRET" \
bash lib/host/serve.sh >"$SERVE_LOG" 2>&1 &
SVPID=$!
for i in $(seq 1 60); do
curl -sf -o /dev/null "http://127.0.0.1:$PORT/health" 2>/dev/null && break
sleep 1
[ "$i" = "60" ] && { echo "server never came up:"; cat "$SERVE_LOG"; exit 1; }
done
echo "== server up =="
echo "== running Playwright =="
cp "$ROOT/$SPEC_SRC" "$SPEC_DST"
cd "$PW_DIR"
SX_TEST_URL="http://127.0.0.1:$PORT" \
node_modules/.bin/playwright test _boost-nav-check.spec.js --workers=1 \
--config tests/playwright/playwright.config.js
RC=$?
echo "== done (exit $RC) =="
exit $RC

View File

@@ -611,7 +611,15 @@
(not (event-modifier-key? e)) (not (event-modifier-key? e))
(prevent-default e) (prevent-default e)
(let (let
((boost-el (dom-query "[sx-boost]")) (;; Read the href FRESH from the element at click time. A morph swap
;; (innerHTML) REUSES DOM nodes in place — an <a> from the previous page
;; can be re-purposed as a different link, its href rewritten but this
;; click closure (and its is-processed? mark, so boost-descendants skips
;; re-binding) left intact. Capturing href in the closure then navigated
;; to the STALE target (e.g. home's /tags for a swapped-in "edit" link).
;; Reading the live attribute makes a reused node follow its CURRENT href.
(href (or (dom-get-attr link "href") href))
(boost-el (dom-query "[sx-boost]"))
(target-sel (target-sel
(if (if
boost-el boost-el

File diff suppressed because one or more lines are too long

View File

@@ -611,7 +611,15 @@
(not (event-modifier-key? e)) (not (event-modifier-key? e))
(prevent-default e) (prevent-default e)
(let (let
((boost-el (dom-query "[sx-boost]")) (;; Read the href FRESH from the element at click time. A morph swap
;; (innerHTML) REUSES DOM nodes in place — an <a> from the previous page
;; can be re-purposed as a different link, its href rewritten but this
;; click closure (and its is-processed? mark, so boost-descendants skips
;; re-binding) left intact. Capturing href in the closure then navigated
;; to the STALE target (e.g. home's /tags for a swapped-in "edit" link).
;; Reading the live attribute makes a reused node follow its CURRENT href.
(href (or (dom-get-attr link "href") href))
(boost-el (dom-query "[sx-boost]"))
(target-sel (target-sel
(if (if
boost-el boost-el