Unverified Commit c38833d1 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Revert "Turbopack: skip invalidating a task on cell/output change when the…

Revert "Turbopack: skip invalidating a task on cell/output change when the dependency is outdated" (#84526)

Reverts vercel/next.js#84376
parent d4eb8915
import './globals.css'
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function Page() {
return <p>hello world</p>
}
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}
module.exports = nextConfig
import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('no-double-tailwind-execution', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
dependencies: {
'@tailwindcss/postcss': '^4',
tailwindcss: '^4',
},
env: {
DEBUG: 'tailwindcss',
...process.env,
},
})
if (skipped) {
return
}
it('should run tailwind only once initially and per change', async () => {
const browser = await next.browser('/')
expect(await browser.elementByCss('p').text()).toBe('hello world')
if (isNextDev) {
const filePath = 'app/page.tsx'
const origContent = await next.readFile(filePath)
let getOutput = next.getCliOutputFromHere()
await next.patchFile(
filePath,
origContent.replace('hello world', 'hello hmr'),
async () => {
await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe('hello hmr')
let tailwindProcessingCount = [
...getOutput().matchAll(
/\[@tailwindcss\/postcss\] app\/globals.css/g
),
].length
expect(tailwindProcessingCount).toBe(1)
})
}
)
}
let tailwindProcessingCount = [
...next.cliOutput.matchAll(/\[@tailwindcss\/postcss\] app\/globals.css/g),
].length
if (isNextDev) {
expect(tailwindProcessingCount).toBe(3) // dev: initial + hmr + hmr (revert)
} else {
expect(tailwindProcessingCount).toBe(1) // build
}
})
})
const config = {
plugins: ['@tailwindcss/postcss'],
}
export default config
......@@ -601,7 +601,6 @@ pub enum AnyOperation {
ConnectChild(connect_child::ConnectChildOperation),
Invalidate(invalidate::InvalidateOperation),
UpdateOutput(update_output::UpdateOutputOperation),
UpdateCell(update_cell::UpdateCellOperation),
CleanupOldEdges(cleanup_old_edges::CleanupOldEdgesOperation),
AggregationUpdate(aggregation_update::AggregationUpdateQueue),
Nested(Vec<AnyOperation>),
......@@ -613,7 +612,6 @@ impl AnyOperation {
AnyOperation::ConnectChild(op) => op.execute(ctx),
AnyOperation::Invalidate(op) => op.execute(ctx),
AnyOperation::UpdateOutput(op) => op.execute(ctx),
AnyOperation::UpdateCell(op) => op.execute(ctx),
AnyOperation::CleanupOldEdges(op) => op.execute(ctx),
AnyOperation::AggregationUpdate(op) => op.execute(ctx),
AnyOperation::Nested(ops) => {
......@@ -628,7 +626,6 @@ impl AnyOperation {
impl_operation!(ConnectChild connect_child::ConnectChildOperation);
impl_operation!(Invalidate invalidate::InvalidateOperation);
impl_operation!(UpdateOutput update_output::UpdateOutputOperation);
impl_operation!(UpdateCell update_cell::UpdateCellOperation);
impl_operation!(CleanupOldEdges cleanup_old_edges::CleanupOldEdgesOperation);
impl_operation!(AggregationUpdate aggregation_update::AggregationUpdateQueue);
......@@ -642,5 +639,6 @@ pub use self::{
cleanup_old_edges::OutdatedEdge,
connect_children::connect_children,
prepare_new_children::prepare_new_children,
update_cell::UpdateCellOperation,
update_collectible::UpdateCollectibleOperation,
};
use std::mem::take;
use serde::{Deserialize, Serialize};
use smallvec::SmallVec;
use turbo_tasks::{CellId, TaskId, backend::CellContent};
#[cfg(feature = "trace_task_dirty")]
......@@ -9,29 +5,13 @@ use crate::backend::operation::invalidate::TaskDirtyCause;
use crate::{
backend::{
TaskDataCategory,
operation::{
AggregationUpdateQueue, ExecuteContext, Operation, TaskGuard,
invalidate::make_task_dirty_internal,
},
operation::{ExecuteContext, InvalidateOperation, TaskGuard},
storage::{get_many, remove},
},
data::{CachedDataItem, CachedDataItemKey, CellRef},
data::{CachedDataItem, CachedDataItemKey},
};
#[derive(Serialize, Deserialize, Clone, Default)]
#[allow(clippy::large_enum_variant)]
pub enum UpdateCellOperation {
InvalidateWhenCellDependency {
cell_ref: CellRef,
dependent_tasks: SmallVec<[TaskId; 4]>,
queue: AggregationUpdateQueue,
},
AggregationUpdate {
queue: AggregationUpdateQueue,
},
#[default]
Done,
}
pub struct UpdateCellOperation;
impl UpdateCellOperation {
pub fn run(task_id: TaskId, cell: CellId, content: CellContent, mut ctx: impl ExecuteContext) {
......@@ -59,7 +39,7 @@ impl UpdateCellOperation {
// This is a hack for the streaming hack. Stateful tasks are never recomputed, so this forces invalidation for them in case of this hack.
task.has_key(&CachedDataItemKey::Stateful {}))
{
let dependent_tasks = get_many!(
let dependent = get_many!(
task,
CellDependent { cell: dependent_cell, task }
if dependent_cell == cell
......@@ -69,78 +49,17 @@ impl UpdateCellOperation {
drop(task);
drop(old_content);
UpdateCellOperation::InvalidateWhenCellDependency {
cell_ref: CellRef {
task: task_id,
cell,
InvalidateOperation::run(
dependent,
#[cfg(feature = "trace_task_dirty")]
TaskDirtyCause::CellChange {
value_type: cell.type_id,
},
dependent_tasks,
queue: AggregationUpdateQueue::new(),
}
.execute(&mut ctx);
ctx,
);
} else {
drop(task);
drop(old_content);
}
}
}
impl Operation for UpdateCellOperation {
fn execute(mut self, ctx: &mut impl ExecuteContext) {
loop {
ctx.operation_suspend_point(&self);
match self {
UpdateCellOperation::InvalidateWhenCellDependency {
cell_ref,
ref mut dependent_tasks,
ref mut queue,
} => {
if let Some(dependent_task_id) = dependent_tasks.pop() {
if ctx.is_once_task(dependent_task_id) {
// once tasks are never invalidated
continue;
}
let dependent = ctx.task(dependent_task_id, TaskDataCategory::All);
if dependent.has_key(&CachedDataItemKey::OutdatedCellDependency {
target: cell_ref,
}) {
// cell dependency is outdated, so it hasn't read the cell yet
// and doesn't need to be invalidated
continue;
}
if !dependent
.has_key(&CachedDataItemKey::CellDependency { target: cell_ref })
{
// cell dependency has been removed, so the task doesn't depend on the
// cell anymore and doesn't need to be
// invalidated
continue;
}
make_task_dirty_internal(
dependent,
dependent_task_id,
true,
#[cfg(feature = "trace_task_dirty")]
TaskDirtyCause::CellChange {
value_type: cell_ref.cell.type_id,
},
queue,
ctx,
);
}
if dependent_tasks.is_empty() {
self = UpdateCellOperation::AggregationUpdate { queue: take(queue) };
}
}
UpdateCellOperation::AggregationUpdate { ref mut queue } => {
if queue.process(ctx) {
self = UpdateCellOperation::Done
}
}
UpdateCellOperation::Done => {
return;
}
}
}
}
}
......@@ -12,7 +12,7 @@ use crate::{
TaskDataCategory,
operation::{
AggregationUpdateQueue, ExecuteContext, Operation, TaskGuard,
invalidate::make_task_dirty_internal,
invalidate::{make_task_dirty, make_task_dirty_internal},
},
storage::{get, get_many},
},
......@@ -25,6 +25,7 @@ use crate::{
#[derive(Serialize, Deserialize, Clone, Default)]
pub enum UpdateOutputOperation {
MakeDependentTasksDirty {
#[cfg(feature = "trace_task_dirty")]
task_id: TaskId,
dependent_tasks: SmallVec<[TaskId; 4]>,
children: SmallVec<[TaskId; 4]>,
......@@ -131,6 +132,7 @@ impl UpdateOutputOperation {
}
UpdateOutputOperation::MakeDependentTasksDirty {
#[cfg(feature = "trace_task_dirty")]
task_id,
dependent_tasks,
children,
......@@ -146,35 +148,15 @@ impl Operation for UpdateOutputOperation {
ctx.operation_suspend_point(&self);
match self {
UpdateOutputOperation::MakeDependentTasksDirty {
#[cfg(feature = "trace_task_dirty")]
task_id,
ref mut dependent_tasks,
ref mut children,
ref mut queue,
} => {
if let Some(dependent_task_id) = dependent_tasks.pop() {
if ctx.is_once_task(dependent_task_id) {
// once tasks are never invalidated
continue;
}
let dependent = ctx.task(dependent_task_id, TaskDataCategory::All);
if dependent.has_key(&CachedDataItemKey::OutdatedOutputDependency {
target: task_id,
}) {
// output dependency is outdated, so it hasn't read the output yet
// and doesn't need to be invalidated
continue;
}
if !dependent
.has_key(&CachedDataItemKey::OutputDependency { target: task_id })
{
// output dependency has been removed, so the task doesn't depend on the
// output anymore and doesn't need to be invalidated
continue;
}
make_task_dirty_internal(
dependent,
make_task_dirty(
dependent_task_id,
true,
#[cfg(feature = "trace_task_dirty")]
TaskDirtyCause::OutputChange { task_id },
queue,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment