next.js
315c8eba - Turbopack: skip invalidating a task on cell/output change when the dependency is outdated (#84376)

Commit
175 days ago
Turbopack: skip invalidating a task on cell/output change when the dependency is outdated (#84376) ### What? Fixes some cases of double invalidation of tasks. The concrete example here was tailwind executing twice on HMR changes. The problem was that tailwind has a glob dependency and a file dependency on files. That leads to two paths of invalidation of the `compute_webpack_loader_evaluation` task. `compute_webpack_loader_evaluation` has a dependency on the file content and on the glob result. So on a `FileContent` cell and a `Completion` cell. If the file content changes it invalidates `compute_webpack_loader_evaluation` and `track_glob`. Both start executing. Shortly after `track_glob` changes the content of the `Completion` cell. This invalidates `compute_webpack_loader_evaluation`. As it has already started executing with the "stale" content of the `Completion` cell, we mark it as stale so it's executed again. But we are a little bit to eager with the invalidation, because at the time the `Completion` cell has changed we haven't even read the cell from the `compute_webpack_loader_evaluation` task yet. But due to an optimization we keep stale dependencies until the task execution has finished (because they are unlikely to change anyway). But this is still possible to detect as there is a `OutdatedCellDependency` on the task. And that's what this PR is doing. When a cell or output is changed, we no longer directly invalidate all dependent tasks. Instead we check every dependent tasks if it still has a dependency on the cell/output or if that dependency is outdated. If that's the case we do not invalidate the task. There is a cost of that extra check, but we have to access the task anyway to make it dirty. So the cost is small, compared to the win of not unnecessarily executing a task again.
Author
Parents
Loading