fix(ivy): error when encountering an empty class attribute (#28321)
Fixes Ivy throwing an error if it encounters an empty class attribute in a template (`class=""`). This PR resolves FW-972. PR Close #28321
This commit is contained in:
parent
9098225ff0
commit
22a43cff4d
|
@ -982,7 +982,9 @@ function setClass(
|
||||||
if (playerBuilder) {
|
if (playerBuilder) {
|
||||||
playerBuilder.setValue(className, add);
|
playerBuilder.setValue(className, add);
|
||||||
}
|
}
|
||||||
} else if (add) {
|
// DOMTokenList will throw if we try to add or remove an empty string.
|
||||||
|
} else if (className !== '') {
|
||||||
|
if (add) {
|
||||||
ngDevMode && ngDevMode.rendererAddClass++;
|
ngDevMode && ngDevMode.rendererAddClass++;
|
||||||
isProceduralRenderer(renderer) ? renderer.addClass(native, className) :
|
isProceduralRenderer(renderer) ? renderer.addClass(native, className) :
|
||||||
native['classList'].add(className);
|
native['classList'].add(className);
|
||||||
|
@ -992,6 +994,7 @@ function setClass(
|
||||||
native['classList'].remove(className);
|
native['classList'].remove(className);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setSanitizeFlag(context: StylingContext, index: number, sanitizeYes: boolean) {
|
function setSanitizeFlag(context: StylingContext, index: number, sanitizeYes: boolean) {
|
||||||
if (sanitizeYes) {
|
if (sanitizeYes) {
|
||||||
|
|
|
@ -317,6 +317,13 @@ function declareTests(config?: {useJit: boolean}) {
|
||||||
expect(ctx.componentInstance.viewContainers.first).toBe(vc);
|
expect(ctx.componentInstance.viewContainers.first).toBe(vc);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not throw when encountering an empty class attribute', () => {
|
||||||
|
const template = '<div class=""></div>';
|
||||||
|
TestBed.overrideComponent(MyComp1, {set: {template}});
|
||||||
|
|
||||||
|
expect(() => TestBed.createComponent(MyComp1)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
describe('empty templates - #15143', () => {
|
describe('empty templates - #15143', () => {
|
||||||
it('should allow empty components', () => {
|
it('should allow empty components', () => {
|
||||||
@Component({template: ''})
|
@Component({template: ''})
|
||||||
|
|
Loading…
Reference in New Issue