We make a minifigure configurator: the customer puts together a figure in 3D, sees the price, and orders. It runs in production on kloniko.store.
For a while iPad users saw "A problem repeatedly occurred" in Safari and "Can't open this page" in Chrome. No error in Sentry, no error boundary triggered. The tab just died.
The cause: iPad got the desktop budget
Every "light" branch in our code was guarded by screen width:
const isPhone = window.innerWidth < 768;
On a phone we lowered the pixel ratio, turned off ambient occlusion and bloom, and kept one 3D snapshot slot. An iPad is 820–1366 px wide, so it got the desktop path: on the frame layout step it had up to two live 3D figures plus three parallel snapshot renderers, each with post-processing.
But the memory available to a tab on an iPad is close to an iPhone, not to a laptop. The OS killed the tab.
So we separated two questions that we had mixed:
- Layout (bottom sheet or sidebar) still depends on width.
- Memory and render quality depend on the device.
export function isTightGpuBudget() {
const ua = navigator.userAgent || '';
const isIOS = /iP(hone|od|ad)/.test(ua)
// iPadOS reports itself as a Mac
|| (/Macintosh/.test(ua) && (navigator.maxTouchPoints || 0) > 1);
return isIOS || /Android/i.test(ua);
}
export function isPerfConstrained() {
return window.innerWidth < 768 || isTightGpuBudget();
}
Android is in the list on purpose. In-app browsers of Instagram, Facebook and TikTok share memory with the app itself, and three WebGL contexts at once kill them the same way.
One detail that matters: call this synchronously, in the useState initialiser, not in useEffect. Otherwise the heavy component mounts for one frame and the WebGL context already exists.
The crash loop
There was a second problem. After the crash the browser offers to reload, the page restores the same heavy state, and crashes again.
You cannot catch an out-of-memory kill: the process is gone. But you can notice it on the next start. We keep an "alive and on screen" mark in localStorage:
- set it on start and every time the tab becomes visible;
- remove it on
pagehideand when the tab is hidden (close, reload, navigation, switching apps); - if the mark is still there on start, the previous session died while on screen. That is a crash.
Then we turn on a safe mode for 30 minutes, with levels by the number of crashes in a row:
- tight budget: one live 3D context, low pixel ratio, no AO or bloom;
- no post-processing anywhere;
- the main preview is 2D, no WebGL at all.
Two things we got wrong at first:
-
A second tab is not a crash. The mark carries a tab id, and a live tab answers through
BroadcastChannel. If the owner of the mark answers, we roll the crash record back. - Desktop does not need this. Desktop tabs are not killed for memory, but the mark stayed from normal cases, like two windows side by side. Our managers ended up with a 2D preview after three such "crashes". Now it is phones and tablets only.
How we test without the device
A URL switch: ?gpu=tight forces the phone budget on a desktop, and window.__glStats counts live WebGL contexts. A narrow window plus tight reproduces the iPad path well enough to catch regressions.
Takeaways
- Screen width tells you about layout. It tells you nothing about memory.
- Count WebGL contexts. Hidden ones (snapshots, thumbnails) count too.
- A tab killed by the OS is invisible to error tracking. Detect it on the next start.
We build configurators like this for other brands at Kastomiko: 3D product configurator, minifigure configurator.
Top comments (1)
My React Native app went the other way when I added iPad: layout follows the window width, never the device, because an iPad window can be resized to almost anything.
The catch is a phone on its side. It's wider than the tablet breakpoint, so the rule also checks the screen's short side, and anything phone-sized keeps the phone layout.