fix(mobile): fit the shell and sheets to safe areas and the on-screen keyboard

Safe areas. The installed app draws under the status bar and beside the
notch, and each 4rem header band padded the inset inside its own
border-box height: on a phone with a 59 px inset the top bar kept a 5 px
content box and the logo and account menu straddled its bottom border.
The authenticated shell now takes the top and side insets once on its
outer wrapper (`shell-safe-area`, the strip painted in the chrome
colour), so the top bar, the sidebar band and any docked panel start
below the status bar together and the seam between them holds. The two
Coach full-height pages subtract the inset at every width, the full-
height day sheet keeps its handle clear of the Dynamic Island, side
sheets keep clear of the status bar and the notch, the bottom bar and
the Coach button take the side insets of a phone held sideways, a
footer-less responsive sheet keeps its last row above the home
indicator, and the sign-in and onboarding shells pad themselves. The
sign-in shell grows with its content (`min-h-dvh`), so a phone held
sideways can scroll to the top of the card.

Keyboard. iOS Safari and Chrome on Android shrink only the visual
viewport when the keyboard opens, so a bottom sheet kept Save and the
Coach composer behind it. `KeyboardInsetBridge` publishes the covered
height (`--keyboard-inset`, `data-keyboard` on <html>); bottom sheets
stand on the keyboard and give up its height to their scrolling body,
and the bottom bar and the Coach button step aside while it is open.
Pinch-zoom and toolbar-sized changes do not count as a keyboard. The
sheet primitive names its side in `data-sheet-side`, which consumers do
not override the way they replace `data-slot`.

pwa-mobile-shell-guard.test.ts pins the structure no headless browser
can show (no browser in CI reports a safe-area inset).
This commit is contained in:
Marc-André Bombeck committed 2026-10-08 17:24:17 +02:00
1 parent 56a3008cf0
commit a4ad8ebe92
17 files changed
+470 -36

No files matched your search

+10 -5
View File
@@ -249,10 +249,9 @@ function DayLayer() {
className="bg-card text-card-foreground border-border motion-safe:animate-in motion-safe:fade-in-0 flex h-full w-105 shrink-0 flex-col border-l motion-safe:duration-150"
>
{view(DockedTitle, {
headerClassName: cn(
SHELL_HEADER_BAND,
"border-border pt-[env(safe-area-inset-top,0px)]",
),
// No status-bar inset here: the docked column sits inside
// the app shell, which takes it (`shell-safe-area`).
headerClassName: cn(SHELL_HEADER_BAND, "border-border"),
})}
</aside>
</ShellSidePanel>
@@ -436,7 +435,13 @@ function DaySheet({
bottom
? cn(
"rounded-t-2xl transition-[height] duration-200 motion-reduce:transition-none",
full ? "h-[calc(100dvh-2.5rem)]" : "h-[58dvh]",
// Full height leaves a strip of the page above the
// sheet, and never less than the status bar of an
// installed app plus a margin: a 2.5rem strip put the
// handle under a 59 px Dynamic Island.
full
? "h-[calc(100dvh-max(2.5rem,env(safe-area-inset-top,0px)+0.75rem))]"
: "h-[58dvh]",
)
: "w-105 max-w-[90vw] sm:max-w-105",
)}
@@ -69,13 +69,22 @@ describe("<LayoutCoachFab>", () => {
// bottom-nav hides (`md:hidden`) — so the FAB never floats mid-air
// in the 768-1023px band. v1.18.1 (C5) — the corner inset is
// symmetric: right equals bottom at each breakpoint (`right-6`
// mobile-band / `md:right-8` desktop mirrors `md:bottom-8`).
expect(html).toContain("fixed right-6");
expect(html).toContain("md:right-8");
// mobile-band / `md:right-8` desktop mirrors `md:bottom-8`). v1.42 —
// each offset sits on top of the matching safe-area inset (the notch
// of a phone held sideways, an installed iPad's home indicator).
expect(html).toContain(
"fixed right-[calc(env(safe-area-inset-right,0px)+1.5rem)]",
);
expect(html).toContain(
"md:right-[calc(env(safe-area-inset-right,0px)+2rem)]",
);
expect(html).toContain(
"bottom-[calc(env(safe-area-inset-bottom,0px)+5rem)]",
);
expect(html).toContain("md:bottom-8");
expect(html).toContain(
"md:bottom-[calc(env(safe-area-inset-bottom,0px)+2rem)]",
);
expect(html).toContain('data-keyboard-hide=""');
expect(html).not.toContain("md:bottom-6");
expect(html).not.toContain("lg:bottom-6");
});
@@ -209,12 +209,9 @@ export function ConversationsPanel({
const header = (inSheet: boolean) => (
<div
data-slot="coach-conversations-panel-header"
// Docked, the row reserves the safe-area inset the top bar reserves,
// so a standalone PWA on a tablet does not tuck it under the status
// bar; the band keeps its height (border-box), like the top bar.
style={
inSheet ? undefined : { paddingTop: "env(safe-area-inset-top, 0px)" }
}
// No inset of its own: docked, the panel is a column of the app
// shell, which already starts below the status bar of an installed
// app (`shell-safe-area` in `auth-shell.tsx`).
// Docked, the row is the top bar's band (height and bottom border
// from `SHELL_HEADER_BAND`), so the two borders draw one line.
className={cn(
+7 -2
View File
@@ -224,6 +224,8 @@ export function LayoutCoachFab() {
type="button"
size="icon"
data-slot="coach-fab"
// Steps aside while the on-screen keyboard is open (globals.css).
data-keyboard-hide=""
data-unread={showDot ? "true" : undefined}
onClick={handleOpen}
aria-label={accessibleLabel}
@@ -240,8 +242,11 @@ export function LayoutCoachFab() {
// 64 px bottom-nav plus the home-indicator safe-area inset
// (`bottom-[calc(env(safe-area-inset-bottom,0px)+5rem)]`), so the
// gap is asymmetric there by design, not drift.
"fixed right-6 z-40 size-14 rounded-full shadow-lg md:right-8",
"bottom-[calc(env(safe-area-inset-bottom,0px)+5rem)] md:bottom-8",
// v1.42 — the side and bottom insets apply at every width: a
// phone held sideways (844 px, past `md`) has its notch on one
// side, and an installed iPad its home indicator along the bottom.
"fixed right-[calc(env(safe-area-inset-right,0px)+1.5rem)] z-40 size-14 rounded-full shadow-lg md:right-[calc(env(safe-area-inset-right,0px)+2rem)]",
"bottom-[calc(env(safe-area-inset-bottom,0px)+5rem)] md:bottom-[calc(env(safe-area-inset-bottom,0px)+2rem)]",
// Dark glyph on the purple/pink gradient — white sat at
// ≈2.3:1 against the gradient midpoint; the background token
// reads ≈6.5:1.
+16
View File
@@ -0,0 +1,16 @@
"use client";
import { useEffect } from "react";
import { trackKeyboardInset } from "@/lib/pwa/keyboard-inset";
/**
* Publishes the on-screen keyboard's height for the whole app, once (see
* `src/lib/pwa/keyboard-inset.ts` for the measurement and `globals.css` for
* what reads it: bottom sheets stand on the keyboard, the bottom bar and the
* Coach button step aside).
*/
export function KeyboardInsetBridge(): null {
useEffect(() => trackKeyboardInset(window, document.documentElement), []);
return null;
}
+23 -4
View File
@@ -278,13 +278,18 @@ export function AuthShell({
if (isStandalonePublicPage) {
return <>{children}</>;
}
// `min-h-dvh`, not `h-dvh`: a phone held sideways is ~390 px tall, and
// a sign-in form that is taller than a fixed-height box centres out of
// it at the top, where nothing can scroll back to it. A minimum lets the
// box grow and the document scroll. The safe-area padding keeps the form
// off the status bar and the home indicator in an installed app.
return (
<div className="flex h-dvh flex-col">
<div className="flex min-h-dvh flex-col pt-[env(safe-area-inset-top,0px)] pr-[env(safe-area-inset-right,0px)] pb-[env(safe-area-inset-bottom,0px)] pl-[env(safe-area-inset-left,0px)]">
{demoMode ? <DemoBanner /> : null}
<MaintainershipBanner />
<main
id="main-content"
className="flex flex-1 items-center justify-center px-4"
className="flex flex-1 items-center justify-center px-4 py-6"
>
{children}
</main>
@@ -352,7 +357,7 @@ export function AuthShell({
{showUnlockNotifier && user?.id ? (
<AchievementUnlockNotifier userId={user.id} />
) : null}
<div className="flex min-h-dvh flex-col">
<div className="flex min-h-dvh flex-col pt-[env(safe-area-inset-top,0px)] pr-[env(safe-area-inset-right,0px)] pl-[env(safe-area-inset-left,0px)]">
<MaintainershipBanner />
<div className="flex flex-1 items-center justify-center px-4 py-8">
{children}
@@ -418,7 +423,21 @@ export function AuthShell({
vertical scroller. Measured in `e2e/chrome-header-seam-banners.spec.ts`
at both breakpoints.
*/}
<div className="flex h-dvh flex-col">
{/*
The installed app draws under the status bar and beside the notch
(`viewport-fit=cover` + `black-translucent`), so the shell takes the
insets once, here, for everything inside it: the banner stack, the
top bar, the sidebar's logo band and any docked side panel all start
below the status bar together, and the seam between the top bar and
the logo band cannot come apart over an inset only one of them
reserved. The bands used to pad themselves inside their 4rem
(border-box), which on a phone with a 59 px inset left the top bar
five pixels of content box and pushed the logo and the account menu
across its bottom border. `shell-safe-area` paints the strip behind
the status bar in the chrome colour (globals.css). The bottom inset
stays with the bottom nav and `<main>`, which own that edge.
*/}
<div className="shell-safe-area flex h-dvh flex-col">
{/*
v1.4.43 QoL (M5) — `<OfflineBanner>` paints only when
`navigator.onLine === false`. Sits above the maintainership
+7 -1
View File
@@ -200,9 +200,15 @@ export function BottomNav() {
`bg-card` + `border-t` give the bar a clean visual edge so page
content that scrolls under the bar is occluded, not bleeding
through. */}
{/* The side insets keep the outer tabs clear of the notch on a phone
held sideways. `data-keyboard-hide`: while the on-screen keyboard
is open the bar steps aside (globals.css) instead of floating
over the field being typed into. */}
<nav
aria-label={t("nav.mobileNavigation")}
className="bg-card border-border fixed bottom-0 left-0 z-50 min-h-16 w-full border-t pb-[env(safe-area-inset-bottom)] backdrop-blur-md md:hidden"
data-slot="bottom-nav"
data-keyboard-hide=""
className="bg-card border-border fixed bottom-0 left-0 z-50 min-h-16 w-full border-t pr-[env(safe-area-inset-right)] pb-[env(safe-area-inset-bottom)] pl-[env(safe-area-inset-left)] backdrop-blur-md md:hidden"
>
<div className="mx-auto flex h-16 max-w-lg items-stretch justify-around px-1">
{primaryLeft.map(renderPrimary)}
+3 -8
View File
@@ -92,14 +92,9 @@ export function TopBar() {
"bg-card/80 border-border sticky top-0 z-40 flex items-center justify-between px-4 backdrop-blur-md md:px-6",
SHELL_HEADER_BAND,
)}
// iOS PWA on notched iPhones overlays the status bar onto the
// sticky header unless we reserve the safe-area inset. The
// inline style adds `safe-area-inset-top` as padding-top on
// devices that report one and is a no-op on every other
// platform. The band stays 4rem tall either way (border-box), so
// on a device that reports an inset the content area inside it
// gives up those pixels.
style={{ paddingTop: "env(safe-area-inset-top, 0px)" }}
// The status-bar inset of the installed app is the shell's
// (`shell-safe-area` in `auth-shell.tsx`), not this band's: padded
// inside its own 4rem, a 59 px inset left the bar a 5 px content box.
>
{/* Mobile logo */}
<Link href="/" className="flex items-center gap-2 md:hidden">
+2
View File
@@ -19,6 +19,7 @@ import { I18nProvider, useTranslations } from "@/lib/i18n/context";
import type { Locale } from "@/lib/i18n/config";
import { toast } from "sonner";
import { Toaster } from "@/components/ui/sonner";
import { KeyboardInsetBridge } from "@/components/keyboard-inset-bridge";
import { VersionPoller } from "@/components/version-poller";
import { ServiceWorkerRegistrar } from "@/components/service-worker-registrar";
import { SharedRecordGrantLossBridge } from "@/components/layout/shared-record-grant-loss-bridge";
@@ -405,6 +406,7 @@ export function Providers({
<RecordSessionFenceBridge />
{children}
<Toaster position="bottom-right" richColors />
<KeyboardInsetBridge />
<VersionPoller />
<ServiceWorkerRegistrar />
</I18nProvider>
+8 -2
View File
@@ -232,8 +232,14 @@ export function ResponsiveSheet({
className={cn(
// Vertical-only scroll port — see the note on the Dialog
// branch's body below for why `overflow-y-auto` alone does not
// say that.
"flex min-h-0 flex-1 flex-col gap-4 overflow-x-clip overflow-y-auto p-4",
// say that. `overscroll-contain`: a flick that reaches the end
// of the form stops there instead of chaining into the page
// (or the browser's pull-to-refresh) behind the sheet.
"flex min-h-0 flex-1 flex-col gap-4 overflow-x-clip overflow-y-auto overscroll-contain p-4",
// Without a footer the body is the sheet's bottom edge, so it
// keeps its last row above the home indicator of an
// installed app; the footer does that when there is one.
!footer && "pb-[calc(env(safe-area-inset-bottom,0px)+1rem)]",
bodyClassName,
)}
>
+6
View File
@@ -61,6 +61,12 @@ function SheetContent({
<SheetOverlay />
<SheetPrimitive.Content
data-slot="sheet-content"
// Read by the safe-area and on-screen-keyboard rules in
// `globals.css`: a bottom sheet stands on the keyboard, the
// full-height sides keep clear of the status bar and the notch.
// Its own attribute rather than `data-slot`, which consumers
// replace with theirs (`responsive-sheet-content`, `day-panel`).
data-sheet-side={side}
className={cn(
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col gap-4 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500",
side === "right" &&