Commit fe72e262 authored by Tobias Koppers's avatar Tobias Koppers Committed by Jiachi Liu

Turbopack: remove the streaming hack for improved stability (#85858)

### What?

Remove the hack we use for streaming in turbo-tasks.
We don't use the stream capability and the streaming hack causes some problems.

fixes `Item already exists` error

Closes https://github.com/vercel/next.js/issues/85833
parent b422017d
......@@ -8,7 +8,6 @@ use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{Completion, FxIndexMap, ResolvedVc, Vc};
use turbo_tasks_bytes::stream::SingleValue;
use turbo_tasks_env::{CommandLineProcessEnv, ProcessEnv};
use turbo_tasks_fetch::{FetchClientConfig, HttpResponseBody};
use turbo_tasks_fs::{
......@@ -768,10 +767,9 @@ async fn get_mock_stylesheet(
)
.await?;
match &val.try_into_single().await? {
SingleValue::Single(val) => {
let val: FxHashMap<RcStr, Option<RcStr>> =
parse_json_with_source_context(val.to_str()?)?;
match &*val {
Some(val) => {
let val: FxHashMap<RcStr, Option<RcStr>> = parse_json_with_source_context(val)?;
Ok(val
.get(&stylesheet_url)
.context("url not found")?
......
......@@ -1953,8 +1953,6 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
&& !session_dependent
// Task has no invalidator
&& !task.has_key(&CachedDataItemKey::HasInvalidator {})
// This is a hack for the streaming hack.
&& !task.has_key(&CachedDataItemKey::Stateful {})
// Task has no dependencies on collectibles
&& count!(task, CollectiblesDependency) == 0
{
......
......@@ -58,14 +58,11 @@ impl UpdateCellOperation {
let mut task = ctx.task(task_id, TaskDataCategory::All);
let is_stateful = task.has_key(&CachedDataItemKey::Stateful {});
// We need to detect recomputation, because here the content has not actually changed (even
// if it's not equal to the old content, as not all values implement Eq). We have to
// assume that tasks are deterministic and pure.
let assume_unchanged = !ctx.should_track_dependencies()
|| (!task.has_key(&CachedDataItemKey::Dirty {})
// This is a hack for the streaming hack. Stateful tasks are never recomputed, so this forces invalidation for them in case of this hack.
&& !is_stateful);
let assume_unchanged =
!ctx.should_track_dependencies() || !task.has_key(&CachedDataItemKey::Dirty {});
let old_content = get!(task, CellData { cell });
......
......@@ -6,7 +6,6 @@ use turbo_tasks::{
Completion, Completions, NonLocalValue, ResolvedVc, TaskInput, TryFlatJoinIterExt, Vc,
fxindexmap, trace::TraceRawVcs,
};
use turbo_tasks_bytes::stream::SingleValue;
use turbo_tasks_fs::{
File, FileContent, FileSystemEntryType, FileSystemPath, json::parse_json_with_source_context,
};
......@@ -519,7 +518,7 @@ impl PostCssTransformedAsset {
})
.await?;
let SingleValue::Single(val) = config_value.try_into_single().await? else {
let Some(val) = &*config_value else {
// An error happened, which has already been converted into an issue.
return Ok(ProcessPostCssResult {
content: AssetContent::File(FileContent::NotFound.resolved_cell()).resolved_cell(),
......@@ -527,7 +526,7 @@ impl PostCssTransformedAsset {
}
.cell());
};
let processed_css: PostCssProcessingResult = parse_json_with_source_context(val.to_str()?)
let processed_css: PostCssProcessingResult = parse_json_with_source_context(val)
.context("Unable to deserializate response from PostCSS transform operation")?;
// TODO handle SourceMap
......
......@@ -12,7 +12,6 @@ use turbo_tasks::{
Completion, NonLocalValue, OperationValue, OperationVc, ResolvedVc, TaskInput, TryJoinIterExt,
ValueToString, Vc, trace::TraceRawVcs,
};
use turbo_tasks_bytes::stream::SingleValue;
use turbo_tasks_env::ProcessEnv;
use turbo_tasks_fs::{
File, FileContent, FileSystemPath,
......@@ -56,8 +55,7 @@ use crate::{
debug::should_debug,
embed_js::embed_file_path,
evaluate::{
EnvVarTracking, EvaluateContext, EvaluationIssue, JavaScriptEvaluation,
JavaScriptStreamSender, compute, custom_evaluate, get_evaluate_pool,
EnvVarTracking, EvaluateContext, EvaluationIssue, custom_evaluate, get_evaluate_pool,
},
execution_context::ExecutionContext,
pool::{FormattingMode, NodeJsPool},
......@@ -275,7 +273,7 @@ impl WebpackLoadersProcessedAsset {
})
.await?;
let SingleValue::Single(val) = config_value.try_into_single().await? else {
let Some(val) = &*config_value else {
// An error happened, which has already been converted into an issue.
return Ok(ProcessWebpackLoadersResult {
content: AssetContent::File(FileContent::NotFound.resolved_cell()).resolved_cell(),
......@@ -284,10 +282,8 @@ impl WebpackLoadersProcessedAsset {
}
.cell());
};
let processed: WebpackLoadersProcessingResult = parse_json_with_source_context(
val.to_str()?,
)
.context("Unable to deserializate response from webpack loaders transform operation")?;
let processed: WebpackLoadersProcessingResult = parse_json_with_source_context(val)
.context("Unable to deserializate response from webpack loaders transform operation")?;
// handle SourceMap
let source_map = if !transform.source_maps {
......@@ -319,18 +315,10 @@ impl WebpackLoadersProcessedAsset {
#[turbo_tasks::function]
pub(crate) async fn evaluate_webpack_loader(
webpack_loader_context: WebpackLoaderContext,
) -> Result<Vc<JavaScriptEvaluation>> {
) -> Result<Vc<Option<RcStr>>> {
custom_evaluate(webpack_loader_context).await
}
#[turbo_tasks::function]
async fn compute_webpack_loader_evaluation(
webpack_loader_context: WebpackLoaderContext,
sender: Vc<JavaScriptStreamSender>,
) -> Result<Vc<()>> {
compute(webpack_loader_context, sender).await
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
enum LogType {
......@@ -439,12 +427,6 @@ impl EvaluateContext for WebpackLoaderContext {
type ResponseMessage = ResponseMessage;
type State = Vec<LogInfo>;
async fn compute(self, sender: Vc<JavaScriptStreamSender>) -> Result<()> {
compute_webpack_loader_evaluation(self, sender)
.as_side_effect()
.await
}
fn pool(&self) -> OperationVc<crate::pool::NodeJsPool> {
get_evaluate_pool(
self.module_asset,
......
......@@ -17,7 +17,6 @@ use turbo_tasks::{
debug::ValueDebugFormat, fxindexmap, trace::TraceRawVcs,
};
use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage};
use turbo_tasks_bytes::stream::SingleValue;
use turbo_tasks_env::CommandLineProcessEnv;
use turbo_tasks_fs::{
DiskFileSystem, FileContent, FileSystem, FileSystemEntryType, FileSystemPath,
......@@ -528,12 +527,7 @@ async fn run_test_operation(prepared_test: ResolvedVc<PreparedTest>) -> Result<V
)
.await?;
let single = res
.try_into_single()
.await
.context("test node result did not emit anything")?;
let SingleValue::Single(bytes) = single else {
let Some(str) = &*res else {
return Ok(RunTestResult {
js_result: JsResult {
uncaught_exceptions: vec![],
......@@ -549,7 +543,7 @@ async fn run_test_operation(prepared_test: ResolvedVc<PreparedTest>) -> Result<V
};
Ok(RunTestResult {
js_result: JsResult::resolved_cell(parse_json_with_source_context(bytes.to_str()?)?),
js_result: JsResult::resolved_cell(parse_json_with_source_context(str)?),
path: path.clone(),
}
.cell())
......
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