Skip to content

fix(pwa): the reader no longer rewrites theme-color / color-scheme on navigation - #1014

Merged
mbryantms merged 1 commit into
mainfrom
fix/reader-viewport-latch
Oct 4, 2026
Merged

mbryantms merged 1 commit into
mainfrom
fix/reader-viewport-latch

Conversation

@mbryantms

Copy link
Copy Markdown
Owner

The installed iPadOS app latches the first runtime change to the
theme-color / color-scheme metas: the status-bar strip switches from the
top bar's solid colour to a blur of the scrolled page content and stays
that way on every route until the app is force-quit. Folio hit this on
iPadOS 26.1 and fixed it for the explicit dark theme only (reader
viewport byte-identical to the root); light, amber and system themes kept
a reader-specific black viewport. With theme = system and the OS in light
mode on iPadOS 27.0.1, every visit to the reader flipped the strip, which
also explains why the lab pages (#1004, #1008, #1013) faded inside Folio
while the standalone test apps (#1009, #1011) never did.

The reader route now has no generateViewport at all and inherits the
root's. On iPadOS the strip takes its colour from the sticky header /
reader chrome, not theme-color (verified: a #000 theme-color test page
still showed the header colour), so nothing is lost there; on Android a
light-theme reader shows the theme's status-bar colour instead of black.

Follow-up, not in this change: standalone web apps freeze
prefers-color-scheme at launch, so with theme = system the app can stay
dark after the OS switches to light until a page re-resolves it.

… navigation

The installed iPadOS app latches the first runtime change to the
theme-color / color-scheme metas: the status-bar strip switches from the
top bar's solid colour to a blur of the scrolled page content and stays
that way on every route until the app is force-quit. Folio hit this on
iPadOS 26.1 and fixed it for the explicit dark theme only (reader
viewport byte-identical to the root); light, amber and system themes kept
a reader-specific black viewport. With theme = system and the OS in light
mode on iPadOS 27.0.1, every visit to the reader flipped the strip, which
also explains why the lab pages (#1004, #1008, #1013) faded inside Folio
while the standalone test apps (#1009, #1011) never did.

The reader route now has no generateViewport at all and inherits the
root's. On iPadOS the strip takes its colour from the sticky header /
reader chrome, not theme-color (verified: a #000 theme-color test page
still showed the header colour), so nothing is lost there; on Android a
light-theme reader shows the theme's status-bar colour instead of black.

Follow-up, not in this change: standalone web apps freeze
prefers-color-scheme at launch, so with theme = system the app can stay
dark after the OS switches to light until a page re-resolves it.
@mbryantms
mbryantms merged commit 110687a into main Oct 4, 2026
15 checks passed
@mbryantms
mbryantms deleted the fix/reader-viewport-latch branch October 4, 2026 21:34
mbryantms added a commit that referenced this pull request Oct 4, 2026
…gation never rewrites them (#1016)

Observed with a MutationObserver on <head>: on EVERY client-side
navigation Next re-renders its metadata tree, removing and re-inserting
theme-color, color-scheme, apple-mobile-web-app-capable, -title and
-status-bar-style (plus viewport/description/robots), even when nothing
changed. An installed iPadOS app latches such a runtime change into a
permanently blurred status-bar strip (force-quit resets it). #1014 only
stopped the reader's own value change, so it could not help: the root
tags still churned on each route change. The standalone test apps
(#1009, #1011) never navigate, which is why they were always clean.

- The apple-mobile-web-app-* / mobile-web-app-capable / color-scheme /
  theme-color tags are now static <head> children of RootLayout, which
  persists across navigations. Verified locally: across two in-app
  navigations they are the same DOM nodes with zero mutations; only
  Next's own viewport/description/robots tags still churn (no API to
  stop that), with identical values.
- `generateViewport` becomes the static `baseViewport`; `themeHeadMeta`
  (lib/viewport.ts) replaces themedViewport/readerViewport.
- tests/pwa/viewport.test.ts pins: tags present in the root layout, no
  route declaring them via the metadata/viewport API.
- /pwa-lab variant P, a latch probe: sticky grey header (strip state at
  a glance), a document-wide logger that survives in-app navigation
  (every <meta> change in <head> with old/new values, every change of
  the element iOS samples at the top edge, per route), one button per
  candidate trigger — including "churn: remove + re-add all app metas",
  i.e. exactly the old Next behaviour — a real Reload, and clean/faded
  note buttons. Delete with the rest of the lab.

iOS snapshots the apple-* tags at Add-to-Home-Screen time; the values
are unchanged, so no reinstall is needed.
mbryantms added a commit that referenced this pull request Oct 5, 2026
…tches into content blur (#1022)

Measured on iPadOS 27.0.1 with the /pwa-lab probe, each run from a
fresh document (Reload):
- a real Next navigation with the sticky header on screen throughout:
  strip stays clean;
- removing + re-adding the viewport meta: clean;
- hiding the sticky header for 2 s: FADED, and it stays faded for the
  life of the document (a reload clears it; the iPhone recovers on its
  own, the iPad does not).

So the rule is: the first time iOS samples the top edge and finds no
fixed/sticky bar, it switches the status-bar strip from the bar's colour
to a blur of the page content and never switches back. The real app has
such moments on every route change — the [locale] loading skeleton
(`bg-background grid min-h-screen`) has no header, which the device
logs caught right after each navigation — which is why every in-app
navigation flipped it while the standalone test apps (never navigating)
never did, and why #1014/#1016 (head-tag changes) could not help.

Fix: a 12px fixed, full-width, app-background bar as the first child of
<body> in the root layout. It is under every real header (z-0 vs their
z-20/z-30) so it is invisible in normal use, and it is what the sample
point hits whenever a header is absent. Verified locally: headerless
page → backstop; page with sticky header, at rest and scrolled → header;
header hidden → backstop. WebKit ignores edge bars ≤ 10px, hence 12.

Probe: two new triggers hide the header with a 12px / 32px fixed bar
behind it, to confirm on-device that 12px is enough.
mbryantms added a commit that referenced this pull request Oct 5, 2026
…a different bar (#1026)

Root cause, measured on iPadOS 27.0.1 with a parameterised probe served
from the dev box (no releases): the status-bar strip is painted in the
colour of the fixed/sticky element iOS finds at the top edge, and the
FIRST time that element changes — a header unmounting on a layout
switch, the reader chrome taking over, any other bar swapped in — it
switches to blurring the page content into the strip and never recovers
for the life of the document. Shrinking the same header to 12px kept
the strip clean; replacing it with any other bar (fixed or sticky,
12–56px, scrolling or not) latched it. This is why sidebar navigation
(header persists) was clean while About → admin and the reader (header
swapped) faded, why #1022's backstop could not help (it only became the
sampled element after the header had gone, itself a change), and why
head-tag work (#1014, #1016) was beside the point.

- Root layout: `#top-edge`, the first child of <body>: sticky, z-9999,
  12px (WebKit ignores bars ≤ 10px), negative margin so it costs no
  layout, in the page colour (`--top-edge-color`, default background).
  It is always what iOS samples: present from first paint, above every
  header and overlay. Replaces the fixed backstop.
- The reader marks its root `data-surface="reader"`; globals.css turns
  the bar black there (same element, colour change only — verified
  clean on-device).
- Verified on the iPad in one document: header hidden with a fixed 56px
  bar inserted, bar colour → black → back, header hidden with a sticky
  20px bar, three route changes through a headerless page, scrolling —
  all clean. Browser check: #top-edge is the sampled element at rest,
  scrolled, with headers hidden, during the colour change and under a
  dialog overlay.
- /pwa-lab: variant Q, a parameterised experiment console (position,
  height, colour, z-index, header kept/hidden, scroll lock, duration)
  plus a colour-change trigger; the sticky-vs-fixed ladder on P; the
  logger shared between them. manifest.ts: dev-only
  PWA_LAB_START_URL so a LAN dev server's installed app opens on a lab
  page instead of the API-backed home. Delete the lab once confirmed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant