fix(webui): provide iOS PWA top-edge color surface

This commit is contained in:
Xubin Ren committed 2026-10-03 20:39:46 +08:00
1 parent 9136fe364e
commit 4a99c0342e
3 files changed
+138

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
# iOS PWA top-edge rendering
NAN-162 / [#5772](https://github.com/HKUDS/nanobot/issues/5772) tracks washed-out
controls at the top of an installed iOS PWA. This is separate from the mobile
sidebar focus and double-tap fixes in #5839.
## Compatibility surface
The initial HTML includes one empty, non-interactive `.pwa-status-bar-surface`
outside React's root. It only renders in standalone mode on engines supporting
`-webkit-touch-callout` and text background clipping. Normal browser tabs and
Chromium PWAs keep it `display: none`.
WebKit's [fixed-container sampling implementation](https://github.com/WebKit/WebKit/blob/d620932d8ce37cf83f60d5c50dace2d50fed4f80/Source/WebCore/page/LocalFrameView.cpp)
looks for fixed/sticky elements near the viewport edge, covering at least 90% of
its width. A primary background must exceed the 10px thin-border threshold and
must not be hidden or nearly transparent. Sampling can ignore `pointer-events`.
Nanobot's relative/absolute header and small button backgrounds do not meet that
contract across the top edge.
The surface is 11px high, viewport-fixed, full-width, and above the application
layers. It inherits the body's background color, including startup and live theme
changes. Clipping that background to empty text prevents it from painting over
controls while retaining the background style for WebKit's sampler. It has no
focusable content and cannot intercept taps. It does not add padding, move the
header, change viewport fitting, or animate an artificial overlay.
This is a compatibility workaround, **not a supported Apple status-bar API**.
Independent device experiments describing the same mechanism:
- [Empty-text fixed surface on iOS 27](https://qiita.com/na-trium-144/items/0add98a80ca2391e3f17)
- [iOS PWA blur experiments, CSS-only update](https://tips.ojapp.app/en/ios-27-pwa-top-blur-workaround-2/)
Keep `viewport-fit=auto` and the existing status-bar metadata. Do not replace this
with a guessed safe-area inset or claim that a desktop screenshot verifies iOS
system compositing.
## Device acceptance gate
HTML/CSS contract tests and desktop layout checks verify scoping, color inheritance,
non-interference and safe-area preservation. They cannot prove the reported iOS
system blur is gone. Before marking NAN-162 resolved, record the actual device,
iOS version and nanobot commit, then compare the same device before/after:
1. Completely quit and relaunch the installed PWA; verify the latest HTML is served.
2. Check sidebar/theme controls on new and existing chats, before and after scrolling.
3. Switch light/dark themes, rotate portrait/landscape, and open/close the keyboard.
4. Open and close the sidebar and settings; verify top controls and one-tap navigation.
5. Compare an ordinary Safari tab and an unaffected browser to rule out added space,
painted strips, blocked input or zoom regressions.
If the workaround stops matching WebKit behavior, re-check the upstream sampling
implementation and device results rather than increasing padding or layer sizes.
The separately reported portrait `@` selection failure is not addressed here.
+21
View File
@@ -57,6 +57,26 @@
color: #fafafa;
}
/* iOS standalone's scroll-edge blur needs a viewport-fixed color surface.
Keep this outside React's root for cold starts and route changes.
See docs/guides/ios-pwa-status-bar.md for the WebKit sampling contract. */
.pwa-status-bar-surface { display: none; }
@supports (-webkit-touch-callout: none) and (background-clip: text) {
@media (display-mode: standalone) {
.pwa-status-bar-surface {
display: block;
position: fixed;
inset: 0 0 auto;
height: 11px; /* Must exceed WebKit's 10px thin-border threshold. */
z-index: 100;
pointer-events: none;
background-color: inherit;
-webkit-background-clip: text;
background-clip: text; /* Empty text paints nothing over the controls. */
}
}
}
.startup-shell { position: relative; height: 100%; }
.startup-header { display: flex; justify-content: space-between; padding: 5px 13px; }
.startup-control-shadow {
@@ -99,6 +119,7 @@
<title>nanobot</title>
</head>
<body class="bg-background text-foreground antialiased">
<div class="pwa-status-bar-surface" aria-hidden="true"></div>
<div id="root">
<main class="startup-shell" aria-busy="true">
<div class="startup-header" aria-hidden="true">
+63
View File
@@ -0,0 +1,63 @@
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import postcss, { type Rule } from "postcss";
import { describe, expect, it } from "vitest";
const html = readFileSync(resolve(process.cwd(), "index.html"), "utf8");
const document = new DOMParser().parseFromString(html, "text/html");
const css = postcss.parse(document.querySelector("style")?.textContent ?? "");
const rules: Rule[] = [];
css.walkRules(".pwa-status-bar-surface", (rule) => { rules.push(rule); });
function declarations(rule: Rule): Record<string, string> {
const result: Record<string, string> = {};
rule.walkDecls((decl) => { result[decl.prop] = decl.value; });
return result;
}
describe("iOS standalone status-bar surface", () => {
it("exists before React loads and survives root replacement without entering the focus order", () => {
const surfaces = document.querySelectorAll(".pwa-status-bar-surface");
expect(surfaces).toHaveLength(1);
const surface = surfaces[0] as HTMLElement;
expect(surface.parentElement).toBe(document.body);
expect(document.getElementById("root")?.contains(surface)).toBe(false);
expect(surface.getAttribute("aria-hidden")).toBe("true");
expect(surface.childNodes).toHaveLength(0);
expect(surface.tabIndex).toBe(-1);
document.getElementById("root")?.replaceChildren(document.createElement("main"));
expect(document.body.contains(surface)).toBe(true);
});
it("is disabled outside standalone WebKit with text background clipping", () => {
const base = rules.filter((rule) => rule.parent?.type === "root");
expect(base).toHaveLength(1);
expect(declarations(base[0])).toEqual({ display: "none" });
const enabled = rules.filter((rule) => declarations(rule).display === "block");
expect(enabled).toHaveLength(1);
const conditions: Record<string, string> = {};
for (let parent = enabled[0].parent; parent; parent = parent.parent) {
if (parent.type === "atrule" && "name" in parent) conditions[parent.name] = parent.params;
}
expect(conditions.media).toBe("(display-mode: standalone)");
expect(conditions.supports).toBe("(-webkit-touch-callout: none) and (background-clip: text)");
});
it("keeps the fixed, theme-inheriting, text-clipped and non-interactive CSS contract", () => {
const enabled = rules.find((rule) => declarations(rule).display === "block");
expect(enabled).toBeDefined();
expect(declarations(enabled!)).toEqual({
display: "block",
position: "fixed",
inset: "0 0 auto",
height: "11px",
"z-index": "100",
"pointer-events": "none",
"background-color": "inherit",
"-webkit-background-clip": "text",
"background-clip": "text",
});
});
});