next.js
0287e106 - fix(edge): run after() if request is cancelled mid-streaming (#76013)

Commit
317 days ago
fix(edge): run after() if request is cancelled mid-streaming (#76013) ### What - Fixes an issue where `after()` in an edge page would not run if the request was cancelled/aborted - Unskips the `runs callbacks if redirect() was called` test which was disabled to not block other things ### Background This was initially hit in #75882, during which the `runs callbacks if redirect() was called` test started failing when using experimental react + turbo in dev mode. Turns out that this happenws because something got slower and we weren't finishing the redirect response in time, i.e. before the browser disconnected and started loading the page it got redirected to. It's relevant that the response didn't finish streaming, because in `edge`, we use that as the trigger to start running `after()` callbacks. In particular, we instrument the response stream using `trackStreamConsumed`. The problem was that this function didn't handle the stream being cancelled, which is what happens when a request is aborted mid-streaming, so `after()` never ended up executing. This PR fixes that and adds some tests for cancellation and interrupted streaming.
Author
Parents
Loading