From 55f2f6ce328625d0e7a20f265c1924d15dc0f0ad Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Tue, 14 Jan 2025 22:34:14 -0800 Subject: [PATCH] Suppress duplicate diagnostics in `EntrypointsOperation::new` --- crates/next-api/src/operation.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/next-api/src/operation.rs b/crates/next-api/src/operation.rs index b42fad21f910e0..6cc4d467b8687b 100644 --- a/crates/next-api/src/operation.rs +++ b/crates/next-api/src/operation.rs @@ -3,8 +3,10 @@ use indexmap::IndexMap; use serde::{Deserialize, Serialize}; use turbo_rcstr::RcStr; use turbo_tasks::{ - debug::ValueDebugFormat, trace::TraceRawVcs, NonLocalValue, OperationVc, ResolvedVc, Vc, + debug::ValueDebugFormat, trace::TraceRawVcs, CollectiblesSource, NonLocalValue, OperationVc, + ResolvedVc, Vc, }; +use turbopack_core::diagnostics::Diagnostic; use crate::{ entrypoints::Entrypoints, @@ -29,11 +31,33 @@ pub struct EntrypointsOperation { pub pages_error_endpoint: OperationVc>, } +/// HACK: Wraps an `OperationVc` inside of a second `OperationVc`. +/// +/// When `CollectiblesSource::take_collectibles` happens, it in-place *mutates* the `OperationVc`, +/// which isn't what we want in `entrypoints_without_diagnostics_operation`. Instead we want a *new* +/// `OperationVc` without diagnostics. This creates that new `OperationVc` to be mutated. +#[turbo_tasks::function(operation)] +fn entrypoints_wrapper(entrypoints: OperationVc) -> Vc { + entrypoints.connect() +} + +/// Removes diagnostics from the top-level `entrypoints` operation so that they're not duplicated +/// across many different individual. +#[turbo_tasks::function(operation)] +fn entrypoints_without_diagnostics_operation( + entrypoints: OperationVc, +) -> Vc { + let entrypoints = entrypoints_wrapper(entrypoints); + let _ = entrypoints.take_collectibles::>(); + entrypoints.connect() +} + #[turbo_tasks::value_impl] impl EntrypointsOperation { #[turbo_tasks::function(operation)] pub async fn new(entrypoints: OperationVc) -> Result> { let e = entrypoints.connect().await?; + let entrypoints = entrypoints_without_diagnostics_operation(entrypoints); Ok(Self { routes: e .routes