fix(app): keep the browser page up until its still is on screen (#54038)

This commit is contained in:
Luke Parker
2026-10-09 11:10:58 +10:00
committed by GitHub
Unverified
parent 5b312918ec
commit 3a2fa2b9d2
3 changed files with 58 additions and 14 deletions
@@ -69,19 +69,34 @@ story("hides the native view immediately while the pane stays mounted", async ({
story("keeps a still of the page under floating content that covers it", async ({ page }) => {
const root = page.getByTestId("browser-pane-fixture")
const still = root.locator("#browser-panel img")
const native = root.getByTestId("native-Alpha")
await root.getByRole("button", { name: "Hold capture", exact: true }).click()
await root.getByRole("button", { name: "Toggle popover", exact: true }).click()
await expect(root.getByText("Captures: 1", { exact: true })).toBeVisible()
// The native page stays up until its still is ready, so the pane never shows blank.
await expect(root.getByTestId("native-Alpha")).toHaveAttribute("data-visible", "true")
await expect(native).toHaveAttribute("data-visible", "true")
await expect(still).toHaveCount(0)
// Main hides the native page at once, so the pane hides it only after a frame has presented the still.
const order = await native.evaluateHandle((element) => {
const events: string[] = []
new PerformanceObserver((list) => {
if (list.getEntries().length > 0) events.push("still presented")
}).observe({ type: "element" })
new MutationObserver(() => {
if (element.getAttribute("data-visible") === "false") events.push("page hidden")
}).observe(element, { attributeFilter: ["data-visible"] })
return events
})
await root.getByRole("button", { name: "Release capture", exact: true }).click()
await expect(root.getByTestId("native-Alpha")).toHaveAttribute("data-visible", "false")
await expect(native).toHaveAttribute("data-visible", "false")
await expect(still).toBeVisible()
expect(await order.jsonValue()).toEqual(["still presented", "page hidden"])
await root.getByRole("button", { name: "Toggle popover", exact: true }).click()
await expect(root.getByTestId("native-Alpha")).toHaveAttribute("data-visible", "true")
await expect(native).toHaveAttribute("data-visible", "true")
await expect(still).toHaveCount(0)
await expect(root.getByText("Captures: 1", { exact: true })).toBeVisible()
})
+5
View File
@@ -28,5 +28,10 @@ export declare module "solid-js" {
interface Directives {
sortable: true
}
// The Element Timing attribute, which Solid's DOM types do not list.
interface ImgHTMLAttributes<T> {
elementtiming?: string
}
}
}
+35 -11
View File
@@ -30,7 +30,10 @@ export function createEmbeds(input: Input): Embeds {
}
function EmbedView(props: EmbedProps & { input: Input; bridge: Bridge }) {
const [store, setStore] = createStore<{ visible: boolean; snapshot: { id: string; url: string } | undefined }>({
const [store, setStore] = createStore<{
visible: boolean
snapshot: { id: string; url: string; presented: boolean } | undefined
}>({
visible: typeof document === "undefined" || document.visibilityState === "visible",
// A still of the embed shown in the DOM while floating content covers the hidden native view.
snapshot: undefined,
@@ -74,13 +77,13 @@ function EmbedView(props: EmbedProps & { input: Input; bridge: Bridge }) {
return r.width > 0 && r.left < rect.right && r.right > rect.left && r.top < rect.bottom && r.bottom > rect.top
})
const replaceSnapshot = (next?: { id: string; url: string }) => {
const replaceSnapshot = (next?: { id: string; url: string; presented: boolean }) => {
if (store.snapshot?.url) URL.revokeObjectURL(store.snapshot.url)
setStore("snapshot", next)
}
// Keep the embed on screen as a still under the floating content. The native view
// stays visible until the still has decoded, so the box never flashes blank.
// stays visible until the still is on screen, so the box never flashes blank.
const freeze = (id: string) => {
clearTimeout(release)
release = undefined
@@ -92,12 +95,16 @@ function EmbedView(props: EmbedProps & { input: Input; bridge: Bridge }) {
.catch(() => undefined)
.then(async (data) => {
const url = data ? URL.createObjectURL(new Blob([new Uint8Array(data)], { type: "image/jpeg" })) : ""
const image = new Image()
if (url) {
const image = new Image()
image.src = url
await image.decode().catch(() => undefined)
}
if (url) image.src = url
const decoded =
!!url &&
(await image
.decode()
.then(() => true)
.catch(() => false))
if (capturing !== id) {
if (url) URL.revokeObjectURL(url)
@@ -106,12 +113,28 @@ function EmbedView(props: EmbedProps & { input: Input; bridge: Bridge }) {
}
capturing = undefined
// A failed capture still hides the embed; the box shows its background as before.
replaceSnapshot({ id, url })
// A failed capture still hides the embed; the box shows its background as before. A still that
// cannot decode never paints, so Element Timing would never report it.
replaceSnapshot({ id, url, presented: !decoded })
schedule()
})
}
// Main hides the native view at once, but a still reaches the screen only a few frames after it
// enters the DOM, so wait for Element Timing to report the frame that presents it.
const presentation = new PerformanceObserver((list) => {
const snapshot = store.snapshot
if (!snapshot || snapshot.presented) return
if (!list.getEntries().some((entry) => "url" in entry && entry.url === snapshot.url)) return
setStore("snapshot", "presented", true)
schedule()
})
presentation.observe({ type: "element" })
onCleanup(() => presentation.disconnect())
const thaw = () => {
capturing = undefined
@@ -140,7 +163,7 @@ function EmbedView(props: EmbedProps & { input: Input; bridge: Bridge }) {
if (shown && cover) freeze(id)
if (!cover) thaw()
const visible = shown && !(cover && store.snapshot?.id === id)
const visible = shown && !(cover && store.snapshot?.id === id && store.snapshot.presented)
// The cutout exposes the app backdrop outside the rounded card, not the embed inside it.
const color =
@@ -246,6 +269,7 @@ function EmbedView(props: EmbedProps & { input: Input; bridge: Bridge }) {
<img
src={url()}
alt=""
elementtiming="embed-snapshot"
draggable={false}
class="absolute inset-0 size-full pointer-events-none select-none"
/>