Skip to content

Commit

Permalink
Use a fake ID from idHolder() when in an {if} block, in productio…
Browse files Browse the repository at this point in the history
…n, not just `goog.DEBUG`.

PiperOrigin-RevId: 704715690
  • Loading branch information
SLaks authored and copybara-github committed Dec 11, 2024
1 parent 2a20391 commit db8038d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions javascript/soyutils_idom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() : {};
}

Expand Down

0 comments on commit db8038d

Please sign in to comment.