Manual
Almnck.
Price: 50ⓐ

View Transitions Migration Implementation Plan

For Claude: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.

Goal: Replace HTMX-based partial-swap navigation with browser-native cross-document View Transitions.

Architecture: Browser handles fetch + swap + transition on same-origin navigation via @view-transition { navigation: auto }. Each subsystem (sidenotes, margin boxes, pen marginalia, celestial) reverts to a single page-load lifecycle; bfcache restoration uses pageshow/pagehide.

Tech Stack: vanilla CSS + browser View Transition API, vanilla JS, Django, django-distill

Reference: Design plan


Stage 1 — Additive: Ship cross-document VTs alongside HTMX

Goal: cross-document View Transitions activate on navigation paths HTMX doesn’t intercept (article-to-article, direct URL entry, external links into the site). HTMX remains for prev/next/today links. No behaviour regressions.

Task 1.1: Add @view-transition CSS rule

Files: - Modify: src/almnck/static/css/main.css (or whichever stylesheet is loaded site-wide — verify)

Step 1: Locate the site-wide stylesheet

grep -rn "main.css\|site.css\|base.css" src/almnck/templates/base.html

Step 2: Add the rule near the top of the stylesheet

@view-transition {
  navigation: auto;
}

Step 3: Verify in Safari and Chrome

make serve
# Open localhost:1969 in Safari and Chrome, navigate between articles by clicking links.
# Should see a crossfade transition between pages.
# Firefox: should see plain navigation (no transition), no errors in console.

Step 4: Commit

git add src/almnck/static/css/
git commit -m "Enable cross-document View Transitions for navigation

Adds @view-transition rule to opt into browser-handled crossfade on
same-origin navigation. Activates in Chromium 126+ and Safari 18.2+;
Firefox falls through to plain navigation pending Interop 2026 support."

Task 1.2: Smoke test for VT activation

Files: - Create: src/tests/test_view_transitions.py

Step 1: Write a browser test that verifies the CSS rule is present and applies

"""Smoke test: cross-document View Transitions are enabled."""
import pytest

@pytest.mark.browser
class TestViewTransitions:
    def test_view_transition_rule_in_stylesheet(self, page, dev_server):
        page.goto(f"{dev_server}/")
        # Check that the CSS rule is reachable in the document's CSSOM
        rules_found = page.evaluate("""
            () => {
                for (const sheet of document.styleSheets) {
                    try {
                        for (const rule of sheet.cssRules) {
                            if (rule.constructor.name === 'CSSViewTransitionRule') return true;
                        }
                    } catch (e) { /* cross-origin sheet */ }
                }
                return false;
            }
        """)
        assert rules_found, "@view-transition rule not found in any stylesheet"

Step 2: Run the test

make test-browser

Step 3: Commit

git add src/tests/test_view_transitions.py
git commit -m "Add smoke test for cross-document View Transitions"

Task 1.3: Verify no regression on HTMX-handled paths

Step 1: Run the full test suite

make test-all

All existing tests should still pass — Stage 1 is purely additive.

Step 2: Manual smoke

  • Click prev/next/today on the frontpage → should still HTMX-swap (no full reload), no visible double-transition
  • Click an article link from the chronology page → should now cross-fade (new behaviour, was full reload)
  • Click an external link out → no change

Step 3: Verify prefers-reduced-motion is respected

Enable reduced motion in OS settings, repeat the above. Transitions should be suppressed.

Step 4: Commit any regression fixes that emerge

Each fix as its own commit.


Stage 2 — Removal: Delete HTMX and the celestial sweep

Goal: HTMX library, frontpage-nav.js, and the celestial date-sweep animation are removed. Subsystems lose their HTMX hooks. History restoration migrates to pageshow/pagehide. Tests rewritten.

Each task in Stage 2 ships independently. Run make test after every task.

Files: - Modify: assets/js/frontpage-nav.js (do not delete yet — see Task 2.7)

Step 1: Remove the wireLink / unwireLink HTMX attribute machinery

In assets/js/frontpage-nav.js, delete the lines that set/remove hx-get, hx-select, hx-target, hx-swap, hx-push-url (currently lines 144-163). Links become plain <a href="..."> with whatever href they’re given. Remove the htmx.process(el) calls.

Step 2: Remove the htmx:afterSwap listener and onSwapComplete handler

Cross-doc navigation no longer fires HTMX events. The post-swap orchestration (title update, celestial setDate) is no longer needed — title comes with the new page, celestial re-initializes on the new page.

Step 3: Verify behaviour

make serve
# Click prev/next/today — should now navigate cross-document with a crossfade.
# No HTMX intercept; URL changes; back/forward works via browser bfcache.

Step 4: Commit

git commit -m "Strip HTMX attributes from frontpage navigation links

Cross-document View Transitions handle the smooth transition; the
HTMX swap path is no longer needed. frontpage-nav.js retains link
enable/disable logic for the prev/next/today UI state but no longer
intercepts navigation."

Task 2.2: Delete the celestial sweep animation

Files: - Modify: assets/js/celestial.js

Step 1: Delete window.__celestialSetDate and its date-animation state machine

Remove the block starting at assets/js/celestial.js:1679 (// --- HTMX date change API ---) through the end of the __celestialSetDate function (~120 lines, ending where dateAnim is no longer referenced).

Also remove the assignment to window.__celestialDateStr at line 1707 (the variable is read elsewhere at line 190, 210, 1026 — those readings will fall back to currentDateStr or resolvePageDate()).

Step 2: Verify celestial sphere still renders on initial page load

make serve
# Visit /, /chronology/, an article. Sun/moon should appear in masthead.
# Navigate between articles — sphere should cross-fade with the page.

Step 3: Commit

git commit -m "Drop celestial date-sweep animation

Cross-document View Transitions cross-fade the celestial canvas
naturally on navigation. The bespoke sweep animation (animating
sun/moon between dates) is no longer needed and removes ~120 lines
of state-machine plus the __celestialSetDate cross-module API."

Task 2.3: Remove HTMX hooks from interactive-margin-boxes.js

Files: - Modify: assets/js/interactive-margin-boxes.js

Step 1: Delete the teardownAll function and its HTMX listeners

Remove lines 48-78 (the teardownAll function, the cleanups map at line 15, the htmx:beforeSwap and htmx:afterSettle listeners).

The module reduces to: initAll runs once on DOMContentLoaded (or when sidenotes signal ready).

Step 2: Remove the <style> hoist (vestigial)

Lines 27-29: the comment says “so they survive innerHTML replacements in setup()”. Hoist is no longer needed since the document is fresh on every navigation. Verify by checking whether any margin box’s setup() calls container.innerHTML = ... — if so, leave the hoist; if not, drop it.

grep -rn "innerHTML" editorial/margin-boxes/*/assets/code.js

Step 3: Verify margin boxes work on initial load and on back/forward

Step 4: Commit

git commit -m "Drop HTMX hooks from interactive margin box loader

Margin boxes initialize once per page load. The teardown/re-init
choreography around HTMX swaps is obsolete now that navigation
loads a fresh document."

Task 2.4: Remove HTMX hooks from pen-marginalia.js

Files: - Modify: assets/js/pen-marginalia.js

Step 1: Remove the htmx:beforeSwap and htmx:afterSettle listeners

Lines 340-348ish. The stroke canvas dies with the page; new article gets a new canvas keyed to the new article’s path (the existing per-path keying from commit 931050b is untouched).

Step 2: Verify pen strokes persist per-article

  • Make a stroke on article A
  • Navigate to article B (stroke gone)
  • Navigate back to article A via browser back (stroke restored from localStorage / wherever it’s persisted)

Step 3: Commit

git commit -m "Drop HTMX hooks from pen marginalia

Stroke canvas re-initializes on each page load. Per-article stroke
keying (commit 931050b) handles persistence across navigation.
HTMX teardown is no longer needed."

Task 2.5: Migrate sidenotes history hooks to pageshow/pagehide

Files: - Modify: assets/js/sidenotes.js

Step 1: Replace htmx:afterSwap listener

The afterSwap handler at line 2367 rebuilds layout when #article-swap is replaced. With cross-doc nav this fires on first paint of the new page — equivalent to running the existing initial-load layout path. Remove the listener; verify the initial-load path runs unconditionally.

Step 2: Replace htmx:beforeHistorySave with pagehide

window.addEventListener('pagehide', (event) => {
  // event.persisted === true when page enters bfcache
  // Save placedState to sessionStorage keyed by URL
  if (placedState) {
    sessionStorage.setItem(
      'sidenotes:placedState:' + location.pathname + location.search,
      serializePlacedState(placedState)
    );
  }
});

Step 3: Replace htmx:historyRestore with pageshow

window.addEventListener('pageshow', (event) => {
  if (event.persisted) {
    // Restored from bfcache — layout state is intact in the DOM, no work needed
    return;
  }
  // Fresh nav (back/forward to a page bfcache rejected): restore placedState
  const saved = sessionStorage.getItem(
    'sidenotes:placedState:' + location.pathname + location.search
  );
  if (saved) {
    placedState = deserializePlacedState(saved);
    repositionAll();
  }
});

(Serialization helpers may already exist from the HTMX history path — reuse them.)

Step 4: Test

  • Navigate forward through several articles
  • Use browser back/forward
  • Sidenotes should appear in the same positions they had originally

Step 5: Commit

git commit -m "Migrate sidenotes history restoration to pageshow/pagehide

Replaces htmx:beforeHistorySave/historyRestore with browser-native
pageshow/pagehide events. bfcache handles most restores at zero
cost; sessionStorage fallback covers the case where bfcache rejects
the page."

Task 2.6: Rewrite or delete HTMX-specific tests

Files: - Modify: src/tests/test_htmx_rapid_nav.py → src/tests/test_rapid_nav.py - Modify: src/tests/test_layout_lifecycle.py - Delete: src/tests/test_layout_stress.py

Step 1: Rewrite test_htmx_rapid_nav.py

The test premise — rapid prev/next clicks don’t corrupt state — is still valuable. Rename to test_rapid_nav.py and rewrite to use plain page.click() on links, asserting URL and title settle correctly. Drop assertions about HTMX-specific events.

Step 2: Rewrite test_layout_lifecycle.py

Most lifecycle assertions go away (no teardown/reinit during nav). What remains: - bfcache restoration (verify pageshow with event.persisted === true keeps DOM intact) - Fresh-nav fallback (sessionStorage path) - Initial-load layout runs cleanly

Step 3: Delete test_layout_stress.py

git rm src/tests/test_layout_stress.py

Its outerHTML-swap stress premise (commit f77b423) no longer corresponds to any production code path.

Step 4: Run full suite

make test-all

Step 5: Commit

git commit -m "Rewrite HTMX-specific tests for cross-document navigation

- test_htmx_rapid_nav.py renamed to test_rapid_nav.py; tests plain
  link clicks rather than HTMX swap orchestration.
- test_layout_lifecycle.py rewritten against pageshow/pagehide.
- test_layout_stress.py deleted; its outerHTML-swap premise is gone."

Task 2.7: Delete frontpage-nav.js and the HTMX library

Files: - Delete: assets/js/frontpage-nav.js - Delete: assets/js/htmx.min.js - Modify: src/almnck/templates/base.html (remove both <script> tags)

Step 1: Verify nothing else references frontpage-nav.js

grep -rn "frontpage-nav" src/ assets/ editorial/

After Task 2.1, the script does only link enable/disable styling — confirm no behaviour depends on it that isn’t expressible as plain CSS.

Step 2: Delete the files and template references

git rm assets/js/frontpage-nav.js assets/js/htmx.min.js

Edit src/almnck/templates/base.html:65 and the corresponding line loading frontpage-nav.js, remove both script tags.

Step 3: Full smoke test

make build
# Open web/ in a browser, click around. No console errors. Navigation works.

Step 4: Verify build output has no HTMX references

grep -r "hx-\|htmx" web/ | grep -v ".map$"

Should return nothing.

Step 5: Commit

git commit -m "Remove HTMX library and frontpage-nav.js

Cross-document View Transitions handle navigation transitions
natively. The HTMX library and its orchestration script are no
longer needed."

Task 2.8: Update CLAUDE.md and docs

Files: - Modify: CLAUDE.md (remove the HTMX-related notes about #article-swap traveling with content swaps) - Modify: doc/05-process/plans/index.md (link to this plan) - Possibly: doc/03-website/ if any setup docs mention HTMX

Step 1: Find HTMX references in docs

grep -rn "htmx\|HTMX\|article-swap" CLAUDE.md doc/

Step 2: Update or remove each reference

The data-hide-on-page note in CLAUDE.md mentions that the <style> block “travels with HTMX content swaps during frontpage navigation”. With cross-doc nav, the style block simply reloads with each page — update the explanation.

Step 3: Commit

git commit -m "Update docs for View Transitions migration"

Task 2.9: Final verification

Step 1: Full test suite

make test-all

Step 2: Production-shape build

make build

Inspect web/ for any straggling HTMX references.

Step 3: Manual smoke in three browsers

  • Chrome: smooth cross-fade on all navigation
  • Safari: smooth cross-fade on all navigation
  • Firefox: plain navigation (no transition), no errors

Step 4: Check bfcache eligibility

Open DevTools → Application → Back/Forward Cache → Run Test. Should report “served from back/forward cache” on a back navigation. If not, investigate the disqualifying API usage and remove it.

Step 5: Open PR

gh pr create --title "Replace HTMX with cross-document View Transitions" --body "$(cat <<'EOF'
## Summary
- Replaces HTMX-based partial-swap navigation with browser-native cross-document View Transitions
- Drops the celestial date-sweep animation in favour of a plain crossfade
- Removes ~500 lines of HTMX orchestration across 5 files
- Migrates sidenotes history restoration to pageshow/pagehide

Design: doc/05-process/plans/2026-05-19-view-transitions-migration-design.md

## Test plan
- [ ] make test-all passes
- [ ] Chrome, Safari, Firefox manual smoke
- [ ] bfcache eligibility verified in DevTools
- [ ] prefers-reduced-motion suppresses transitions
EOF
)"

Rollback

Stage 1 is safely reversible by removing the @view-transition rule.

Stage 2 requires git revert of the Stage 2 commits. Because commits are small and focused, individual subsystems can be reverted independently (e.g., re-enable HTMX for just sidenotes if its pageshow/pagehide migration is buggy).