back home

blog

the time a React useEffect froze Firefox on the PlayStation store

In late 2023, a number of Firefox users started reporting the same thing: try to log in to the Sony PlayStation Store and the browser would freeze, pin a CPU core, and eat memory until the tab died. Other Sony properties — the entertainment site, account pages — exhibited the same thing.

The cause turned out to be a small, almost philosophical disagreement between how React thinks about the DOM and how Firefox's password manager thinks about the DOM. This is the story of bug 1863300.

this is my own bug. so the gory details are first-hand.

How the password manager listens

Firefox's password manager doesn't poll the page; it listens for events. Whenever a form gains a password input, the platform fires a synthetic event called DOMFormHasPassword. There's a sibling event, DOMFormHasPossibleUsername, for username-shaped fields. The login manager listens for both, finds the form's saved credentials in storage, and pre-fills the field if the user wants it.

For a static HTML form this fires exactly once. The browser sees the form, dispatches the event, the login manager does its work, and everyone is happy.

these events are platform-only — web content can't listen for them. they fire on the chrome side, where the login manager runs.

How React thinks about the DOM

React doesn't treat the DOM as something you mutate; it treats the DOM as the output of a render function. If a component re-renders and produces a slightly different tree, React reconciles the difference: some nodes get removed, some get added, some get moved. Inputs are no exception.

Normally this is invisible. The Sony login form was not normal. It had a state-update pattern — exactly the kind of pattern you write accidentally in a useEffect without proper dependencies — that caused the form component to re-mount on a tight cadence. Each re-mount detached the existing password input and inserted a new one. Hundreds of times a second.

a state update inside a useEffect with no guard, where the effect depends on that state, is the classic react foot-gun. it loops as fast as react can schedule it.

Where the two worlds collided

Each newly-inserted password input fired DOMFormHasPassword. The login manager dutifully handled each one — looked up credentials, sent the data across the parent/child process boundary, queued up a UI hint. It would have handled a few hundred of these without breaking a sweat.

The problem was a second, subtler issue: bug 1864379 — the events were also firing for inputs that React had already unmounted. The login manager was working hard for nodes that had stopped existing. Each handler ran, walked the (no-longer-attached) form tree, queued IPC messages, and held references to dead nodes. Memory went up. The main thread fell behind. The tab became unresponsive.

the workaround at the time was almost folklore: log in via the rewards subdomain first, then come back to the store and refresh.

The fix

The fix didn't try to make the login manager faster, and it didn't try to detect React's pattern. Both of those would have been losing fights. Instead it asked a simpler question: should we be firing these events for elements that aren't in the document at all?

The answer, in retrospect, was obviously no. A disconnected element has no form to fill, no UI to show, no saved credential to match. The patch tightened the dispatch logic so that DOMFormHasPassword and DOMFormHasPossibleUsername are only fired for elements still attached to a document. Everything downstream got cheaper for free.

this is one of those bugs where the fix is three lines and the investigation is three weeks.

The lesson, such as it is

Browsers have to be defensive about web content's shape. Most of the time, an "input added to a form" means a user-facing element that just got rendered. A small fraction of the time, it means React reconciled a form four hundred times in the last second and you should not, in fact, do anything about it.

A good browser-internal listener treats every event as potentially hostile. It checks that the element is still attached, that the document is still alive, that the work hasn't already been done. It assumes the worst, because somewhere out there a site is re-mounting a password input at sixty hertz and someone is going to try to log in.

Try it yourself

To see the original broken behavior you'd need Firefox 119 or 120 (or ESR 115 pre-uplift). On modern Firefox — anything 121 or newer — this is a no-op. You can grab old builds from the Mozilla FTP archive.

Paste this into the dev tools on a blank page. It mimics the mount/unmount pattern that the Sony site was inadvertently doing, minus the React layer:

// a tight mount/unmount loop for a password input.
// pre-121 firefox: ram climbs, tab freezes.
// 121+: nothing observable.
setInterval(() => {
const form = document.createElement("form");
const input = document.createElement("input");
input.type = "password";
input.name = "p";
form.appendChild(input);
document.body.appendChild(form);
// detach on the next microtask, mimicking react reconciliation
queueMicrotask(() => form.remove());
}, 4);

On Firefox Nightly or any current release, you can leave that running indefinitely. The password manager sees the disconnected elements and quietly ignores them — which is, in the end, all this fix was about.

if you want to read the actual patches, both 1863300 and 1864379 are public. mozilla is open all the way down.