diff --git a/apps/host/src/lib/router.ts b/apps/host/src/lib/router.ts index d9319fe5..be48fa4e 100644 --- a/apps/host/src/lib/router.ts +++ b/apps/host/src/lib/router.ts @@ -90,6 +90,16 @@ export function closeSettings() { navigateHash(locationHref(location), false); } +/** + * WebKitGTK (the Linux app window; Safari does not exist on Linux) crashes its own UI process with a null pointer in + * AcceleratedBackingStore::update when a page calls the View Transitions API (seen on Ubuntu 24.04 and 26.04, WebKitGTK + * 2.52, under Xvfb and on a real NVIDIA/Wayland desktop alike; one startViewTransition call is enough). The route + * cross-fade is only a nicety, so on that engine a route changes at once. + */ +export function isWebKitGtk(ua: string = navigator.userAgent): boolean { + return /AppleWebKit/.test(ua) && /Linux|X11/.test(ua) && !/Chrome|Chromium|CriOS|Edg|OPR|Android/.test(ua); +} + function navigateHash(next: string, morph = true) { if (window.location.hash === next) return; @@ -97,6 +107,7 @@ function navigateHash(next: string, morph = true) { const mayMorph = morph && typeof document.startViewTransition === 'function' && + !isWebKitGtk() && root.dataset.motion !== 'reduced' && !window.matchMedia('(prefers-reduced-motion: reduce)').matches && root.dataset.streaming !== 'true'; diff --git a/apps/host/tests/webkitgtk-view-transitions.test.mjs b/apps/host/tests/webkitgtk-view-transitions.test.mjs new file mode 100644 index 00000000..c6059e3d --- /dev/null +++ b/apps/host/tests/webkitgtk-view-transitions.test.mjs @@ -0,0 +1,25 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { readFile } from 'node:fs/promises'; +import { transform } from 'esbuild'; + +// WebKitGTK 2.52 crashes its UI process (null pointer in AcceleratedBackingStore::update) on document.startViewTransition, +// so the route morph must never be used there. This test pins the engine check and that the router uses it. +const source = await readFile(new URL('../src/lib/router.ts', import.meta.url), 'utf8'); +const fn = source.match(/export function isWebKitGtk[\s\S]*?\r?\n}\r?\n/)[0]; +const { code } = await transform(fn, { loader: 'ts', format: 'esm' }); +const { isWebKitGtk } = await import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`); + +test('WebKitGTK is recognised, other engines are not', () => { + assert.equal(isWebKitGtk('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15'), true); + assert.equal(isWebKitGtk('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1.15 (KHTML, like Gecko)'), true); + assert.equal(isWebKitGtk('Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0'), false); + assert.equal(isWebKitGtk('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0 Safari/537.36'), false); + assert.equal(isWebKitGtk('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15'), false); + assert.equal(isWebKitGtk('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0 Edg/130.0'), false); +}); + +test('the router skips the view transition on WebKitGTK', () => { + assert.match(source, /typeof document\.startViewTransition === 'function' &&\s*!isWebKitGtk\(\)/); + assert.equal((source.match(/document\.startViewTransition\(/g) ?? []).length, 1, 'one call site only, guarded above'); +});