From c276981dfd24eb4242b60cd7e0c21535eb093134 Mon Sep 17 00:00:00 2001 From: arturovt Date: Wed, 2 Apr 2025 18:57:49 +0300 Subject: [PATCH] refactor(core): drop computation error messages in production (#60700) Some of the error messages in `core/primitives` are already guarded with `ngDevMode`; this change guards the remaining ones. PR Close #60700 --- packages/core/primitives/signals/src/computed.ts | 4 +++- packages/core/primitives/signals/src/linked_signal.ts | 4 +++- packages/core/primitives/signals/src/watch.ts | 10 +++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/core/primitives/signals/src/computed.ts b/packages/core/primitives/signals/src/computed.ts index c8519f40df9..cc033839803 100644 --- a/packages/core/primitives/signals/src/computed.ts +++ b/packages/core/primitives/signals/src/computed.ts @@ -133,7 +133,9 @@ const COMPUTED_NODE = /* @__PURE__ */ (() => { producerRecomputeValue(node: ComputedNode): void { if (node.value === COMPUTING) { // Our computation somehow led to a cyclic read of itself. - throw new Error('Detected cycle in computations.'); + throw new Error( + typeof ngDevMode !== 'undefined' && ngDevMode ? 'Detected cycle in computations.' : '', + ); } const oldValue = node.value; diff --git a/packages/core/primitives/signals/src/linked_signal.ts b/packages/core/primitives/signals/src/linked_signal.ts index 2caecfc374f..9f940992690 100644 --- a/packages/core/primitives/signals/src/linked_signal.ts +++ b/packages/core/primitives/signals/src/linked_signal.ts @@ -137,7 +137,9 @@ export const LINKED_SIGNAL_NODE = /* @__PURE__ */ (() => { producerRecomputeValue(node: LinkedSignalNode): void { if (node.value === COMPUTING) { // Our computation somehow led to a cyclic read of itself. - throw new Error('Detected cycle in computations.'); + throw new Error( + typeof ngDevMode !== 'undefined' && ngDevMode ? 'Detected cycle in computations.' : '', + ); } const oldValue = node.value; diff --git a/packages/core/primitives/signals/src/watch.ts b/packages/core/primitives/signals/src/watch.ts index 7ef3272ff31..ded4d82cdb3 100644 --- a/packages/core/primitives/signals/src/watch.ts +++ b/packages/core/primitives/signals/src/watch.ts @@ -18,6 +18,10 @@ import { SIGNAL, } from './graph'; +// Required as the signals library is in a separate package, so we need to explicitly ensure the +// global `ngDevMode` type is defined. +declare const ngDevMode: boolean | undefined; + /** * A cleanup function that can be optionally registered from the watch logic. If registered, the * cleanup logic runs before the next watch execution. @@ -99,7 +103,11 @@ export function createWatch( } if (isInNotificationPhase()) { - throw new Error(`Schedulers cannot synchronously execute watches while scheduling.`); + throw new Error( + typeof ngDevMode !== 'undefined' && ngDevMode + ? 'Schedulers cannot synchronously execute watches while scheduling.' + : '', + ); } node.dirty = false;