From db8038d27b53df092341f5392027f1daff097a67 Mon Sep 17 00:00:00 2001 From: Schabse Laks <slaks@google.com> Date: Tue, 10 Dec 2024 08:14:28 -0800 Subject: [PATCH] Use a fake ID from `idHolder()` when in an `{if}` block, in production, not just `goog.DEBUG`. PiperOrigin-RevId: 704715690 --- javascript/soyutils_idom.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/javascript/soyutils_idom.ts b/javascript/soyutils_idom.ts index 0921b85bc9..6ae60fa992 100644 --- a/javascript/soyutils_idom.ts +++ b/javascript/soyutils_idom.ts @@ -491,11 +491,6 @@ class IdHolderForDebug implements IdHolder { backing?: string; get id(): string | undefined { if (!this.backing) { - // b/235271145: When checking idom blocks for truthiness, the attribute is - // skipped. Ignore this error in this case. - if (inFalsinessRendererDepth > 0) { - return 'zSoyz: Fake ID in FalsyRenderer'; - } throw new Error( ` Cannot read 'idHolder.id' until the element with the 'uniqueAttribute()' call is @@ -576,6 +571,12 @@ function stableUniqueAttribute( * Note: This returns a mutable object; this implementation is a bit hacky. */ function stableUniqueAttributeIdHolder(): IdHolder { + // b/235271145: When creating an IdHolder from inside an {if $html} block, the + // actual uniqueAttribute() may be skipped. If the IdHolder is read later on, + // don't fail. + if (inFalsinessRendererDepth > 0) { + return {id: 'zSoyz: Fake ID in FalsyRenderer'}; + } return goog.DEBUG ? new IdHolderForDebug() : {}; }