Nov 2026
One to two seconds: chasing repeated popups in Next.js
A production login felt slow because the same modal kept opening. The fix was not a faster query; it was giving the state a single owner.
- nextjs
- debugging
At SolemtI I worked on two Next.js applications that were already in production. In one of them, the login flow felt slow. The fix that mattered was not a faster request or a smaller bundle: it was popup control logic that was running twice. Removing the repetition cut one to two seconds off login.
The instinct is to blame the network
When a screen feels slow, the first guess is always the request. I timed the flow instead: submit, request, render, next screen. The request came back in normal time. The wait was happening in the interface. The same modal was being opened more than once, and every open did its own setup work before the user could continue.
The state had too many owners
The popups were controlled from more than one place: an effect inside the component and a response handler. Each had its own guard, and neither guard knew about the other. That is the bug in one sentence: two owners for one piece of state.
The fix was to give the flow a single owner. One value records whether a popup has already been claimed for this attempt. Components read it; handlers only set it. No effect gets to open the dialog “just in case”, and no handler gets to reopen it because it did not see the first one.
The result
- one source of truth instead of two guards
- no repeated open and close cycles during login
- one to two seconds less waiting, measured on the same flow
What I took from it
The expensive part was not a single render. It was doing the same work twice and making the user wait for both. In React, “how many owners does this state have?” is often a better first question than “how do I make this faster?”