next.js
dedbd829 - Fix potential race condition in createRouterAct (#78473)

Commit
290 days ago
Fix potential race condition in createRouterAct (#78473) A few of the tests that use `createRouterAct` occasionally flake in CI. I'm not exactly sure why because I'm struggling to reproduce them locally, but my best guess based on some of the logs is that there's a race condition between the IntersectionObserver event that triggers the prefetch request, and the async event scheduled by `createRouterAct` that is meant to always run after that. I had thought `requestAnimationFrame` would be a good way to ensure that the event runs after the IntersectionObserver, but I think that's not always correct and depends on the timing of the paint/layout cycle. So I've switched it to `requestIdleCallback` instead since that won't run until the rest of the event queue is empty. (A timer would obviously work here, too, but we should avoid using timers except to timeout a failing test, because they slow down CI.) I've also added better error message to `createRouterAct` in the case where an unexpected request is initiated. The updated message now includes both the URL and the response body.
Author
Parents
Loading