Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/mobile-nav-small-viewport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@hyperdx/app': patch
---

fix: keep the team switcher and user preferences reachable in the mobile app
nav. The app shell and nav were sized with `100vh`, which on mobile browsers
includes the area behind the retractable toolbar, so the bottom of the nav sat
off screen with no way to scroll to it. They now size to the small viewport.
2 changes: 1 addition & 1 deletion packages/app/pages/trace/[traceId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function TraceRedirectPage() {
}, [isReady, replace, traceIdParam]);

return (
<Center h="100vh">
<Center h="var(--app-viewport-height)">
<Text size="sm" c="dimmed">
Redirecting to search...
</Text>
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/DBSearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2399,7 +2399,7 @@ function DBSearchPageContent() {
return (
<Flex
direction="column"
h="100vh"
h="var(--app-viewport-height)"
style={{ overflow: 'hidden' }}
data-testid="search-page"
>
Expand Down
7 changes: 5 additions & 2 deletions packages/app/src/components/AppNav/AppNav.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ $transition-slow: 0.2s ease;
}

.nav {
height: 100vh;
max-height: 100vh;
// Matches the app shell. The overlay nav is position: fixed with body scroll
// locked, so anything laid out past the small viewport is unreachable on a
// phone. See --app-viewport-height in styles/globals.css.
height: var(--app-viewport-height);
max-height: var(--app-viewport-height);
display: flex;
flex-flow: column nowrap;
justify-content: space-between;
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/components/PageLayout.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
}

.fillViewport {
height: 100vh;
// Same reason the app shell avoids 100vh — see styles/globals.css.
height: var(--app-viewport-height);
}

.content {
Expand Down
24 changes: 22 additions & 2 deletions packages/app/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,32 @@ a {
background-color: var(--color-text-muted);
}

/*
* Height of a full-viewport, non-scrolling app shell.
*
* Mobile browsers resolve 100vh against the large viewport, which includes the
* area behind the retractable toolbar. A shell sized that way puts its bottom
* row off screen, and since the shell itself never scrolls there is no way to
* reach it. The small viewport is the part that is always on screen; the
* toolbar only retracts when the root document scrolls, which this shell does
* not do, so svh is also the steady-state height and never reflows.
*/
:root {
--app-viewport-height: 100vh;
}

@supports (height: 100svh) {
:root {
--app-viewport-height: 100svh;
}
}

.app-layout {
height: 100vh;
height: var(--app-viewport-height);
}

.app-layout-with-banner {
height: 100vh;
height: var(--app-viewport-height);
display: grid;
grid-template-rows: auto 1fr;
}
110 changes: 110 additions & 0 deletions packages/app/tests/e2e/core/mobile-nav.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import type { Page } from '@playwright/test';

import { expect, test } from '../utils/base-test';

/**
* iPhone 12 Safari: 390x745 with the browser toolbar retracted, 390x664 with
* it on screen. The viewport below is the large one, because that is what
* `100vh` resolves to; the toolbar covers the bottom of it.
*/
const LARGE_VIEWPORT = { width: 390, height: 745 };

// Playwright has no toolbar emulation, so Chromium's own override stands in for
// one: it makes `svh` smaller than `lvh` the way a phone with its toolbar on
// screen does. The value is not in CSS pixels, only "large enough that the two
// units differ", which the test asserts before relying on it.
const SMALL_VIEWPORT_DIFFERENCE = 200;

// APP_CONTENT_SCROLL_CONTAINER_ID from src/layout.tsx, inlined because
// importing that module pulls the whole page tree into the test runtime.
const APP_CONTENT_SCROLL_CONTAINER_ID = 'app-content-scroll-container';

async function measureViewportHeights(page: Page) {
return page.evaluate(() => {
const measure = (unit: string) => {
const probe = document.createElement('div');
probe.style.cssText = `position:fixed;top:0;width:0;height:100${unit}`;
document.body.appendChild(probe);
const height = probe.getBoundingClientRect().height;
probe.remove();
return height;
};
return { small: measure('svh'), large: measure('lvh') };
});
}

async function expectUserMenuOnScreen(page: Page, smallViewportHeight: number) {
const userMenu = page.locator('[data-testid="user-menu-trigger"]');
await expect(userMenu).toBeVisible();
await expect
.poll(async () => {
const box = await userMenu.boundingBox();
return box ? box.y + box.height : Number.POSITIVE_INFINITY;
})
.toBeLessThanOrEqual(smallViewportHeight);
// Fitting inside the small viewport is not enough on its own: a nav that
// collapsed to nothing, or one pushed off the top, would also satisfy it.
expect((await userMenu.boundingBox())?.y).toBeGreaterThanOrEqual(0);
}

test.describe('Mobile app shell', { tag: ['@core'] }, () => {
test.use({ viewport: LARGE_VIEWPORT, isMobile: true, hasTouch: true });

test.beforeEach(async ({ page }) => {
const cdp = await page.context().newCDPSession(page);
await cdp.send('Emulation.setSmallViewportHeightDifferenceOverride', {
difference: SMALL_VIEWPORT_DIFFERENCE,
});
});

test('keeps the user menu on screen behind a browser toolbar', async ({
page,
}) => {
await page.goto('/search');
await expect(page.locator('[data-testid="app-nav"]')).toBeVisible();

const viewport = await measureViewportHeights(page);
// Without this the test would pass vacuously on a browser that ignores the
// override, since every viewport unit would resolve to the same height.
expect(viewport.small).toBeLessThan(viewport.large);

const navToggle = page.locator(
'button[aria-label="Collapse/expand navigation"]',
);

await test.step('collapsed rail', async () => {
await expect(navToggle).toHaveAttribute('aria-expanded', 'false');
await expectUserMenuOnScreen(page, viewport.small);
});

await test.step('expanded overlay', async () => {
await navToggle.click();
// Without this a dropped click would quietly re-measure the rail.
await expect(navToggle).toHaveAttribute('aria-expanded', 'true');
await expectUserMenuOnScreen(page, viewport.small);
});
});

test('does not leave the page content taller than the shell', async ({
page,
}) => {
await page.goto('/search');
await expect(page.locator('[data-testid="search-page"]')).toBeVisible();

const viewport = await measureViewportHeights(page);
expect(viewport.small).toBeLessThan(viewport.large);

// A page root still sized to the large viewport would overflow the shell
// and make the whole app scroll, which it is not meant to do.
await expect
.poll(async () =>
page.evaluate(id => {
const scroller = document.getElementById(id);
return scroller
? scroller.scrollHeight - scroller.clientHeight
: Number.POSITIVE_INFINITY;
}, APP_CONTENT_SCROLL_CONTAINER_ID),
)
.toBe(0);
});
});
Loading