Commit e0668e4
authored
Run fast immediates during prerender abort to fix flaky I/O stack traces (#89969)
Follow-up for #89834.
In `prerenderAndAbortInSequentialTasks`, React's `finishHalt` (scheduled
via `setImmediate` from `abort()`) could race with the component's
pending `setTimeout` callback. When both ended up in the same timer
phase, the component timer would fire after `abort()` but before
`finishHalt`, linking the async graph and producing the more precise
`await` location (21:9). When `finishHalt` won the race, it read an
unlinked graph and fell back to the function declaration (20:16).
Adding `DANGEROUSLY_runPendingImmediatesAfterCurrentTask()` to the abort
task captures `finishHalt` as a fast immediate, ensuring it runs right
after `abort()` before any other timers. This makes the result
deterministic at the cost of always producing the less precise stack
frame (function declaration instead of `await` expression). The resolve
step is split into a separate task because it needs to wait for the
abort's fast immediates to complete.
When using `--debug-prerender`, we're also re-adding the hint to run
`next dev` for even better stack traces, since dev mode can produce the
precise `await` location by running the render to completion and
resolving the I/O promises.
[Flakiness
metric](https://app.datadoghq.com/ci/test/runs?query=test_level%3Atest%20%40git.repository.id%3A%22github.com%2Fvercel%2Fnext.js%22%20%40test.type%3A%22nextjs%22%20%40test.status%3A%22fail%22%20%40test.suite%3A%22Cache%20Components%20Errors%22%20%40git.branch%3Acanary%20-%40ci.pipeline.name%3Atest-e2e-deploy-release&agg_m=count&agg_m_source=base&agg_t=count¤tTab=overview&eventStack=&fromUser=false&index=citest&start=1770404554855&end=1771009354855&paused=false)1 parent 69d63ed commit e0668e4
File tree
4 files changed
+104
-11
lines changed- packages/next/src/server/app-render
- test
- e2e/app-dir/cache-components-errors
- production/app-dir/build-output-prerender
4 files changed
+104
-11
lines changedLines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
38 | 45 | | |
39 | 46 | | |
40 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
984 | 984 | | |
985 | 985 | | |
986 | 986 | | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
987 | 991 | | |
988 | 992 | | |
989 | 993 | | |
| |||
0 commit comments