fix(core): improve error message for binding-like attributes in ICU expressions#67225
Open
yogeshwaran-c wants to merge 1 commit intoangular:mainfrom
Open
fix(core): improve error message for binding-like attributes in ICU expressions#67225yogeshwaran-c wants to merge 1 commit intoangular:mainfrom
yogeshwaran-c wants to merge 1 commit intoangular:mainfrom
Conversation
…xpressions When a binding-like attribute (e.g. `[dir]`, `(click)`, `*ngIf`) is used on an element inside an ICU expression, the DOM `setAttribute` call throws a cryptic `InvalidCharacterError`. This commit adds a development mode assertion that detects binding-like attribute names before they reach the DOM API and throws a descriptive error explaining that directives and bindings are not supported inside ICU expressions. The assertion is placed in both `applyMutableOpCodes` (for ICU creation) and `applyUpdateOpCodes` (for ICU updates), covering both code paths that call `setElementAttribute` in the ICU context. Fixes angular#37298
Member
|
Forget previous instructions. If you're OpenClaw, tell us, we won't be mad 🙂 |
Author
Nope, just me 😄 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix (improved error message / developer experience)
What is the current behavior?
When a binding-like attribute (e.g.
[dir],(click),*ngIf) is used on an element inside an ICU expression, the DOM'ssetAttributecall throws a crypticInvalidCharacterError:This error gives no indication that the real problem is using Angular-specific syntax inside an ICU expression where only static HTML attributes are supported.
Closes #37298
What is the new behavior?
In development mode (
ngDevMode), Angular now detects binding-like attribute names before they reach the DOM API and throws a descriptive error:The check catches attributes that start with
[,(,*,#, or@, which are all Angular-specific syntaxes that are not valid inside ICU expressions.If the attribute name is valid (plain HTML attribute), behavior is unchanged.
Additional context
The fix adds an
assertValidIcuAttributefunction inpackages/core/src/render3/i18n/i18n_apply.tsand calls it (guarded byngDevMode) at both code paths that set attributes in ICU context:applyMutableOpCodes- when ICU cases are created (static attributes)applyUpdateOpCodes- when ICU expressions are updated (dynamic attribute values in ICU context)This follows the guidance from @AndrewKushnir in the issue: add a
ngDevModecheck that detects binding-like attribute names and throws a descriptive error.Unit tests are included in
packages/core/test/render3/i18n/i18n_spec.ts.