# demarkus-library journal: 2026-12-02 Reader light/dark switch on branch `feat/reader-scheme`, uncommitted. Nav has a 3-way form (auto · light · dark) that POSTs `/scheme`. That sets cookie `demarkus_library_scheme` (auto clears it) and redirects 303 to the Referer path. The server renders `` from the cookie, so the first paint is right. library.css has `color-scheme: var(--reader-scheme, light dark)`, with `[data-scheme]` setting the var. The user chose "theme wins". A theme that sets color-scheme itself (e.g. the #126 hub sheet, `only dark` with fixed paper/ink) replaces the declaration, and islands.js `syncSchemeSwitch` hides the switch. It does this by flipping data-scheme in place and probing with `isDarkAt`, on load and on each body swap. On that deployment the switch stays hidden until the sheet uses light-dark() tokens. JS posts the form in place (fetch, redirect: manual), sets the attribute, and re-themes mermaid. `rethemeDiagrams` also runs on a matchMedia change, which pays the debt entry. `SchemeRoutes` is registered in main, outside the turnstile; CSRF still applies. Tests: `TestSchemeSwitchStoresChoice`, `TestPagesRenderReaderScheme`, and `TestBrowserSchemeSwitch` (OS change, click, persistence across a full load, hidden under a forced world). Each piece was verified by mutation. Gates green. Seen: the nav overflows at 600px. This is pre-existing and now recorded in debt.md. Nav overflow on narrow screens fixed on `feat/reader-scheme` (same branch as the scheme switch, still uncommitted). `nav` now has `flex-wrap: wrap; justify-content: flex-end`. Doors that do not fit wrap to a second row, flush right; `.world` still grows on row one, so the first row looks unchanged. The pane-scroll room is fine with it, since the nav is `flex: 0 0 auto` in a column and the canvas takes the rest. `TestBrowserNavFitsNarrowScreen` fails before the fix at 480px (librarian door, switch). Gotcha: a headless Chrome `--window-size=380,…` screenshot is not a 380px layout. Chrome enforces a wider minimum window, so the page lays out wider and the PNG is clipped. Items look missing or overflowing when they are not. For narrow widths use CDP `Emulation.setDeviceMetricsOverride`, as the browser test does, and measure rects instead of trusting the screenshot. Applied the code-review fixes on `feat/reader-scheme` (simplify pass done first: the switch now posts through htmx, `hx-post` + `hx-swap="none"`, and the server answers 204 to htmx and 303 otherwise). Fixes: - Mermaid renders queue one at a time, because the theme is global in `mermaid.initialize`. A run whose scheme turned mid-draw calls `rethemeDiagrams` when it finishes. - `form.scheme` has `hx-sync="this:replace"`. htmx 4 defaults to `queue first`, which drops clicks after the queued one. - `savedScheme` and `pendingScheme` in islands.js: a failed save (finally:request with status ≥400 or no response) reverts the page. On a body swap the page adopts the fresh nav's pressed choice, which covers another tab changing the cookie, unless a post is in flight. - The retheme skip-check matches `:scope > svg.diagram`; the popout button's icon is also an ``. A re-theme that removes the focused popout button refocuses the new one. - The forced-scheme cache is skipped when `stylesSettled` timed out. It now resolves true or false. - The buttons have aria-labels. README and values.yaml say `DEMARKUS_COOKIE_SECURE` covers the session, CSRF and scheme cookies. Skipped: the switch flashing before it hides in a forced world (it would need the server to detect forcing in theme CSS); the 2048-character return cap for no-JS long trails; content jumping during a redraw; the example logo's prefers-color-scheme. Test gotcha: CDP `Emulation.setEmulatedMedia` returns before the matchMedia change event fires. The event lands at the next rendering step, so wait two requestAnimationFrames before acting, or the test races past the window it means to cover. Mutation of the popout fix only failed after adding that wait. Fixed the AbortError seen on every boosted navigation, also present on main, by bumping vendored htmx and hx-sse from 4.0.0 to 4.0.2 on `feat/reader-scheme`. The tarball integrity was checked against the npm registry, and `.coderabbit.yaml` now carries the 4.0.2 pin note. Cause: the 4.0.0 hx-sse `cleanup` (htmx_before_cleanup on the body swap) called `abortController.abort()` and then `reader.cancel()`. Cancelling an errored stream returns a promise rejected with the stored AbortError, and nothing caught it. 4.0.2 cancels the reader first and nulls it on release. 4.0.1 also fixes an older response overwriting a newer one under `hx-sync` replace, which the scheme switch relies on. Regression test: `TestBrowserSwapClosesStreamQuietly`. It fails on 4.0.0 and passes on 4.0.2. Its SSE endpoint is served beside the room's one-request-at-a-time test handler, because an open stream would otherwise block every request. Real-app smoke on 4.0.2: all scheme steps pass and the console shows no errors. The full browser suite passes. PR #128 review, CodeRabbit's one thread: fixed, uncommitted. htmx 4.0.2 `trigger()` dispatches a detached element's events on `document` (`n = e?.isConnected ? e : document`). It also repoints `ctx.sourceElement` to the swap target after a body swap. So a handler that filters by `e.target` misses requests whose source was swapped out. The scheme `htmx:finally:request` handler now filters by `ctx.sourceEvent.target`, the submit's own form. `TestBrowserSchemeSwitch` covers it: the form is removed while a refused post is in flight, and the page must still revert. That fails with the old guard. PR #128 (reader light/dark switch, nav wrap, htmx 4.0.2) squash-merged to main as `aa57cfd`. Both CodeRabbit threads were fixed and resolved before the merge (`986c716` detached-form guard, `8f965ce` held refusal in the test). The Release workflow is running on `aa57cfd`. Open follow-ups, not started: - A theming-docs note: a theme needs `light-dark()` pairs for the switch to work, and `only dark` hides it. - At 360px the pane's min-width scrolls the document sideways. This is pre-existing and not logged in debt. Promoted to GKE as v0.55.0. Deploy repo PR #250 (`fbec83c`) bumped `apps/demarkus-library/applicationset.yaml` from 0.54.3 to 0.55.0; 0.54.4 had never been pinned and was folded into this bump with a note. Argo synced about 130s after the merge. Both pods run `ghcr.io/latebit-io/demarkus-library:0.55.0`, Ready, 0 restarts. `/health` returns 200. The live `/static/` htmx.min.js, hx-sse.min.js, islands.js and library.css hash-match main. The logs show only the existing warning that the internal broker URL is plain http. Not checked: whether the live hub stylesheet forces a scheme, which hides the switch. It sits behind the session, and `/theme/site.css` returns 404.