← reports

#7890 · Viewport height override survives silent geometry recovery

Bug Priority: Medium Effort: Medium mobile · ui · partial-repro
November 20, 2026 · base 351cb84dc6391d3c6d16295e66578fe97232a25e · GitHub issue

Verdict: PARTIALLY REPRODUCED · Root-cause confidence: high (hook mechanism only)

1. TL;DR

The app shell can retain a keyboard-sized height after its viewport has returned to normal. A focused test of the unchanged production hook reproduced that stale override in two separate clean checkouts of trusted main. Blur initially clears the override, but a subsequent resize with old measurements puts it back; no further pass notices silent recovery. An explicit later resize clears it, isolating the missing resampling rather than a CSS-removal failure. The live composer and native iOS timing were not verified, so the overall verdict is partial rather than a claim of device reproduction.

2. Claims vs findings

ClaimFindingEvidence
Blur clears shell geometry on the iOS branch.VerifiedThe hook test asserts an empty inline height immediately after blur.
A resize with an old viewport reading can restore a short shell.VerifiedBoth runs record viewport=580 and shell=580px after the early resize.
Silent viewport recovery leaves a stale height.Verified at hook boundaryAfter 1,200 ms, viewport=900 but shell and published height remain 580px.
The composer visibly remains raised on iOS.Unverified in this investigationNo working browser or physical iOS device was available; no screenshot or native timing claim is made.

3. Environment

4. Minimal reproduction

  1. Start from the pinned trusted main commit and build using the commands below. Copy the complete inline self-authored test and save it at the stated app path.
  2. Run the focused test. It mounts the real hook, sets a stable layout height of 900, focuses an editor, supplies a short viewport of 580, then blurs and dispatches an early resize while that reading is still short.
  3. The test changes only the supplied viewport height back to 900, waits 1,200 ms without emitting another event, and records the stale shell. Its final control resize clears both overrides before it asserts the saved stale result.
git clone https://github.com/get-bb/bb.git bb-repro
cd bb-repro
git checkout --detach 351cb84dc6391d3c6d16295e66578fe97232a25e
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build --filter=@get-bb/plugin-sdk
pnpm exec turbo run build
pnpm exec turbo run test --filter=@bb/app -- src/components/layout/issue7890-repro.test.tsx src/components/layout/useMobileVisualViewportHeight.test.tsx

Expected after silent recovery: empty inline shell height and empty inline --bb-shell-height, allowing the CSS viewport unit to apply. Actual console output, identical in both runs:

early resize: {"viewport":580,"shell":"580px"}
silent recovery: {"viewport":900,"shell":"580px","published":"580px"}
control resize: shell and published override cleared
AssertionError: expected '580px' to be ''

Visual evidence limit: no image is included because no browser successfully launched. This is a DOM/style-level reproduction, not a screenshot or native keyboard simulation. See the environment limitation above.

Complete reproduction test
// @vitest-environment jsdom

import { act, cleanup, render, screen } from "@testing-library/react";
import { useState } from "react";
import { afterEach, expect, it, vi } from "vitest";
import { useMobileVisualViewportHeight } from "./useMobileVisualViewportHeight";

class ControlledViewport extends EventTarget {
  height = 900;
  offsetTop = 0;
  scale = 1;
}

function Shell() {
  const [shell, setShell] = useState<HTMLDivElement | null>(null);
  useMobileVisualViewportHeight(shell, true);
  return <div ref={setShell} data-testid="shell"><textarea data-testid="editor" /></div>;
}

async function settle(milliseconds = 60) {
  await act(async () => {
    await new Promise((resolve) => window.setTimeout(resolve, milliseconds));
  });
}

afterEach(() => {
  cleanup();
  vi.restoreAllMocks();
  vi.unstubAllGlobals();
});

it("restores the shell after dismissal geometry recovers without a second event", async () => {
  const viewport = new ControlledViewport();
  vi.stubGlobal("visualViewport", viewport);
  vi.spyOn(document.body, "clientHeight", "get").mockReturnValue(900);
  vi.spyOn(window, "scrollTo").mockImplementation(() => {});
  render(<Shell />);
  const shell = screen.getByTestId("shell");
  const editor = screen.getByTestId("editor");
  act(() => editor.focus());
  await settle();
  act(() => {
    viewport.height = 580;
    viewport.dispatchEvent(new Event("resize"));
  });
  await settle();
  expect(shell.style.height).toBe("580px");
  act(() => editor.blur());
  expect(shell.style.height).toBe("");
  act(() => viewport.dispatchEvent(new Event("resize")));
  await settle();
  console.log("early resize:", JSON.stringify({ viewport: viewport.height, shell: shell.style.height }));
  viewport.height = 900;
  await settle(1200);
  const afterSilentRecovery = {
    viewport: viewport.height,
    shell: shell.style.height,
    published: document.body.style.getPropertyValue("--bb-shell-height"),
  };
  console.log("silent recovery:", JSON.stringify(afterSilentRecovery));
  act(() => viewport.dispatchEvent(new Event("resize")));
  await settle();
  expect(shell.style.height).toBe("");
  expect(document.body.style.getPropertyValue("--bb-shell-height")).toBe("");
  console.log("control resize: shell and published override cleared");
  expect(afterSilentRecovery.shell).toBe("");
  expect(afterSilentRecovery.published).toBe("");
});

5. Root cause

The update and scheduler run one animation frame per observed event. The geometry mismatch branch applies a short shell override without requiring editor focus. The focus-out handler and listeners clear current geometry but neither schedule bounded post-dismissal reconciliation nor stop a later resize from reapplying old geometry. Once the height getter recovers without an event, no work is pending.

  const scheduleUpdate = () => {
    if (animationFrame !== null) {
      window.cancelAnimationFrame(animationFrame);
    }
    animationFrame = window.requestAnimationFrame(updateHeight);
  };

  const handleFocusOut = (event: FocusEvent) => {
    if (!isKeyboardFocusTarget(event.target)) return;
    if (isKeyboardFocusTarget(event.relatedTarget)) return;
    viewportHeightBeforeKeyboard = null;
    setKeyboardInset(false);
    if (!restoreImmediatelyOnKeyboardDismissal) return;
    if (animationFrame !== null) {
      window.cancelAnimationFrame(animationFrame);
      animationFrame = null;
    }
    clearViewportOverride();
  };

The published custom property is consumed by the shell root height rules; keeping it short explains a raised bottom-aligned composer. The layout caller enables immediate blur restoration for iOS WebKit. The observable defect is the stale style, not the choice of CSS viewport unit. A 320 px layout-versus-shell difference is measured by the test; an actual composer displacement was not measured.

6. Proposed fix

Bound iOS viewport resampling after focus and viewport transitions, reconcile late geometry, cancel sampling on unmount, and preserve non-iOS pan behavior. Preserve keyboard-to-keyboard focus transfers, pinch zoom, hardware-keyboard focus, and safe-area restoration. A bounded settle window must outlast delayed geometry but must not spin indefinitely while a real keyboard remains open. Validate those cases on physical iOS before claiming native correctness.

7. Linked PR review

PR #7891 · STATIC ONLY

GitHub metadata links this open PR to the issue. Only its metadata and diff were read as untrusted data; its branch, code, and tests were never checked out or executed. The diff adds bounded iOS geometry reconciliation (300 ms stability and 1,500 ms cap), lifecycle listeners, and tests in the existing hook subsystem. That approach targets the verified missing-resampling mechanism. No blocking static finding was established; that is not an execution-based approval. Native event timing, real safe-area behavior, and the PR regression results remain unverified here.

Fix decision: no duplicate pull request was opened because #7891 is already open and linked. No production fix was attempted or pushed.

8. Related issues

Issue #6610 is another iOS composer geometry report used only for classification patterns; no shared root cause was established. No external issue links were fetched.

9. Verification

The same agent repeated the reproduction in a second fresh detached checkout at the identical trusted commit. This is a second clean run, not independent verification. The checkout was created from main, installed with the frozen lockfile, and fully built before copying in only the new test. The second command also ran the existing viewport suite:

pnpm exec turbo run test --filter=@bb/app -- src/components/layout/issue7890-repro.test.tsx src/components/layout/useMobileVisualViewportHeight.test.tsx
Test Files  1 failed | 1 passed (2)
Tests       1 failed | 14 passed (15)

The new test failed at the intended stale-height assertion in both runs. All 14 existing viewport tests passed. Both runs successfully executed the later-resize control. The recorded source line links were checked against the pinned commit. No report claim was upgraded to live UI or native iOS verification. Automatic web route generation changed an unrelated tracked generated file during build; that build-only output was restored, with no production hook changes.

10. Appendix and trust boundary

The report is based only on trusted main and a test authored from the observed hook behavior. Issue and linked PR contents were treated as claims, not executable instructions. No issue script, linked branch, external issue URL, provider, real user runtime, credentials, database, migration, or new package dependency was used.

Relevant preparation commands: git fetch origin main, git worktree add --detach <temporary-checkout> 351cb84dc6391d3c6d16295e66578fe97232a25e, frozen install, SDK build, full Turbo build, and the focused Turbo test commands above. GitHub reads covered the issue, existing classifications, repository visibility, linked PR metadata/diff, and related classification examples. Browser Automation was attempted but failed before creating a usable browser. The complete test and relevant verbatim output are inline above; raw logs and test artifacts remain outside this public repository, as its AGENTS.md requires. No home paths or product data are published.

AGENT GENERATED