From 5566d3217941d947b04ca591b1464a0601d7278f Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Sun, 15 Nov 2026 21:58:50 -0800 Subject: [PATCH 1/7] test(sandbox): a raw page that logs whether the platform animated a history back On a real phone, the page pushes two history entries and logs each popstate and Navigation API navigate event with its hasUAVisualTransition, and the display mode it runs in. It is the evidence page for NavigationStack skipping its own pop or push animation after a platform-animated traversal. --- apps/sandbox/scripts/next-export-routes.json | 1 + .../(raw)/pages/history-back-probe/page.tsx | 175 ++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 apps/sandbox/src/app/(raw)/pages/history-back-probe/page.tsx diff --git a/apps/sandbox/scripts/next-export-routes.json b/apps/sandbox/scripts/next-export-routes.json index 0364020f15251..64da411d7d24b 100644 --- a/apps/sandbox/scripts/next-export-routes.json +++ b/apps/sandbox/scripts/next-export-routes.json @@ -23,6 +23,7 @@ "/pages/example-cards/", "/pages/example/", "/pages/gothic-palette/", + "/pages/history-back-probe/", "/pages/layout-dsl/", "/pages/list-reorder-cases/", "/pages/markdown-perf/", diff --git a/apps/sandbox/src/app/(raw)/pages/history-back-probe/page.tsx b/apps/sandbox/src/app/(raw)/pages/history-back-probe/page.tsx new file mode 100644 index 0000000000000..0c02decb8f282 --- /dev/null +++ b/apps/sandbox/src/app/(raw)/pages/history-back-probe/page.tsx @@ -0,0 +1,175 @@ +// Copyright (c) Meta Platforms, Inc. and affiliates. + +'use client'; + +/** + * @file page.tsx + * @input A finger on a phone: the buttons that push two history entries and + * go back, and the platform's own back gesture (Safari's edge swipe, an + * iOS Home Screen app's edge swipe) + * @output A bare page that logs, on screen, each popstate and Navigation API + * navigate event with its hasUAVisualTransition, and the display mode the + * page runs in. Below the log, a NavigationStack pushes one history entry + * per push and pops when the history goes back, so the platform's back + * swipe has history to run on + * @position A raw page, with no sandbox chrome, for checking on a real phone + * whether the platform animated a history back (NavigationStack skips its + * own pop animation after one) + */ + +import {useEffect, useState} from 'react'; +import {Button} from '@astryxdesign/core/Button'; +import {HStack, VStack} from '@astryxdesign/core/Layout'; +import {List, ListItem} from '@astryxdesign/core/List'; +import { + NavigationScreen, + NavigationStack, + useNavigationStack, +} from '@astryxdesign/lab'; +import {Heading, Text} from '@astryxdesign/core/Text'; + +interface LogEntry { + time: string; + event: string; + detail: string; +} + +/** The Navigation API's navigate event fields this page reads. */ +interface NavigateEventLike extends Event { + navigationType?: string; + hasUAVisualTransition?: boolean; + destination?: {url: string}; +} + +function now(): string { + return new Date().toISOString().slice(11, 23); +} + +const ROWS = ['General', 'About', 'Storage']; + +function Rows() { + const nav = useNavigationStack(); + return ( + + {ROWS.map(row => ( + nav.push(row)} /> + ))} + + ); +} + +/** + * A NavigationStack whose every push adds a history entry, and whose path + * follows the history back and forward. + */ +function HistoryStack() { + const [path, setPath] = useState([]); + useEffect(() => { + const onPopState = (event: PopStateEvent) => { + const state = event.state as {path?: string[]} | null; + setPath(state?.path ?? []); + }; + window.addEventListener('popstate', onPopState); + return () => window.removeEventListener('popstate', onPopState); + }, []); + return ( +
+ + + + } + path={path} + onPathChange={(next: string[]) => { + if (next.length > path.length) { + history.pushState({path: next}, '', `?depth=${next.length}`); + setPath(next); + } else { + history.go(next.length - path.length); + } + }} + getKey={(entry: string) => entry} + renderScreen={(entry: string) => ( + + + + )} + data-testid="navigation-stack" + /> +
+ ); +} + +export default function HistoryBackProbePage() { + const [log, setLog] = useState([]); + const [mode, setMode] = useState(''); + + useEffect(() => { + const add = (event: string, detail: string) => + setLog(current => + [{time: now(), event, detail}, ...current].slice(0, 40), + ); + const standalone = + (navigator as Navigator & {standalone?: boolean}).standalone === true; + setMode( + `standalone=${standalone} display-mode:standalone=${matchMedia('(display-mode: standalone)').matches} ` + + `navigation=${'navigation' in window} ${navigator.userAgent}`, + ); + const onPopState = (event: PopStateEvent) => + add( + 'popstate', + `hasUAVisualTransition=${String((event as PopStateEvent & {hasUAVisualTransition?: boolean}).hasUAVisualTransition)} ` + + `state=${JSON.stringify(event.state)} url=${location.search || '/'}`, + ); + window.addEventListener('popstate', onPopState); + const navigation = (window as Window & {navigation?: EventTarget}) + .navigation; + const onNavigate = (event: Event) => { + const navigate = event as NavigateEventLike; + add( + 'navigate', + `type=${navigate.navigationType} hasUAVisualTransition=${String(navigate.hasUAVisualTransition)} ` + + `to=${navigate.destination?.url.split('?')[1] ?? '/'}`, + ); + }; + navigation?.addEventListener('navigate', onNavigate); + return () => { + window.removeEventListener('popstate', onPopState); + navigation?.removeEventListener('navigate', onNavigate); + }; + }, []); + + const pushTwo = () => { + history.pushState({step: 1}, '', '?step=1'); + history.pushState({step: 2}, '', '?step=2'); + setLog(current => [ + {time: now(), event: 'pushState', detail: 'step=1, step=2'}, + ...current, + ]); + }; + + return ( + + History back probe + + {mode} + + +