fix(platform-server): don't clobber parse5 properties when setting (#18237)
element properties. Fixes #17050. We now store all element properties in a separate 'properties' bag. PR Close #18237
This commit is contained in:

committed by
Miško Hevery

parent
b4c98305da
commit
a094769bca
@ -85,12 +85,17 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||
} else if (name === 'className') {
|
||||
el.attribs['class'] = el.className = value;
|
||||
} else {
|
||||
el[name] = value;
|
||||
// Store the property in a separate property bag so that it doesn't clobber
|
||||
// actual parse5 properties on the Element.
|
||||
el.properties = el.properties || {};
|
||||
el.properties[name] = value;
|
||||
}
|
||||
}
|
||||
// TODO(tbosch): don't even call this method when we run the tests on server side
|
||||
// by not using the DomRenderer in tests. Keeping this for now to make tests happy...
|
||||
getProperty(el: any, name: string): any { return el[name]; }
|
||||
getProperty(el: any, name: string): any {
|
||||
return el.properties ? el.properties[name] : undefined;
|
||||
}
|
||||
|
||||
logError(error: string) { console.error(error); }
|
||||
|
||||
|
@ -197,6 +197,20 @@ class MyHostComponent {
|
||||
class FalseAttributesModule {
|
||||
}
|
||||
|
||||
@Component({selector: 'app', template: '<input [name]="name">'})
|
||||
class MyInputComponent {
|
||||
@Input()
|
||||
name = '';
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
declarations: [MyInputComponent],
|
||||
bootstrap: [MyInputComponent],
|
||||
imports: [ServerModule, BrowserModule.withServerTransition({appId: 'name-attributes'})]
|
||||
})
|
||||
class NameModule {
|
||||
}
|
||||
|
||||
export function main() {
|
||||
if (getDOM().supportsDOMEvents()) return; // NODE only
|
||||
|
||||
@ -439,13 +453,22 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should handle false values on attributes', async(() => {
|
||||
renderModule(FalseAttributesModule, {document: doc}).then((output) => {
|
||||
renderModule(FalseAttributesModule, {document: doc}).then(output => {
|
||||
expect(output).toBe(
|
||||
'<html><head></head><body><app ng-version="0.0.0-PLACEHOLDER">' +
|
||||
'<my-child ng-reflect-attr="false">Works!</my-child></app></body></html>');
|
||||
called = true;
|
||||
});
|
||||
}));
|
||||
|
||||
it('should handle element property "name"', async(() => {
|
||||
renderModule(NameModule, {document: doc}).then(output => {
|
||||
expect(output).toBe(
|
||||
'<html><head></head><body><app ng-version="0.0.0-PLACEHOLDER">' +
|
||||
'<input name=""></app></body></html>');
|
||||
called = true;
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('http', () => {
|
||||
|
Reference in New Issue
Block a user