MOBILE-4470 compile: Fix component ID collision detected warning

Angular generates a unique component ID for each component to apply style encapsulation, restore application state, etc. Our compile code generated the same ID every time some HTML was compiled, and Angular displayed a warning in the console. Applying a different attribute every time makes sure the component ID is different in each compile.
main
Dani Palou 2024-05-27 15:43:07 +02:00
parent 4cae0f704d
commit ff7a075cec
1 changed files with 2 additions and 1 deletions

View File

@ -161,6 +161,7 @@ export class CoreCompileProvider {
getModWorkshopComponentModules,
];
protected componentId = 0;
protected libraries?: unknown[];
protected exportedObjects?: Record<string, unknown>;
@ -187,7 +188,7 @@ export class CoreCompileProvider {
await import('@angular/compiler');
// Create the component using the template and the class.
const component = Component({ template })(componentClass);
const component = Component({ template, host: { 'compiled-component-id': String(this.componentId++) } })(componentClass);
const lazyImports = await Promise.all(this.LAZY_IMPORTS.map(getModules => getModules()));
const imports = [