Next.js Discord

Discord Forum

next dev losing scroll position on hot reload

Unanswered
Eurasian Coot posted this in #help-forum
Open in Discord
Eurasian CootOP
I yesterday upgraded my app router site to next and next/mdx 15.1.3 from 14.2.13.

I work using "next dev" and rely on the hot reload feature to update as I write articles.

After the upgrade, now when I edit my pages, frequently but not always it will lose my scroll position or simply render the "not found" page. This is because the client requests the page, and the server returns 404 apparently while it is rebuilding. It's maybe one in ten changes, but since I am saving my source files on almost every key stroke it happens constantly.

I mitigated this for myself by running a proxy between browser and next dev server that watches the live reload web socket and discards all messages sent by client or server between the server's {"action":"building"} message and the {"action":"built"} message. This has fully resolved the issue, although occasionally I now need to save my source files an extra time to trigger the client to see the changes.

Has anyone else seen this, or found a less hacky way to resolve the issue? Did something change in the hot reload web socket protocol between these NextJS versions?

1 Reply

Eurasian CootOP
When it loads without losing my position, I see this in next dev output:

 
 ✓ Compiled in 459ms (761 modules)
 GET /16 200 in 69ms


but when it loses the scroll (without my hacky workaround) I see this:

 ✓ Compiled in 357ms (761 modules)
 ✓ Compiled /_not-found in 262ms (751 modules)
 GET /16 404 in 303ms
 GET /16 200 in 73ms


These are both triggered by just a CTRL+S of the page.mdx for page /16. The bottom one happens like one in ten and either loses my scroll or renders the not-found text.