From ff7a075cec5146c7362ac291e3ecff8df7aac171 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 27 May 2024 15:43:07 +0200 Subject: [PATCH 1/2] 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. --- src/core/features/compile/services/compile.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/features/compile/services/compile.ts b/src/core/features/compile/services/compile.ts index 3fea8a902..f1f9073dd 100644 --- a/src/core/features/compile/services/compile.ts +++ b/src/core/features/compile/services/compile.ts @@ -161,6 +161,7 @@ export class CoreCompileProvider { getModWorkshopComponentModules, ]; + protected componentId = 0; protected libraries?: unknown[]; protected exportedObjects?: Record; @@ -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 = [ From 6f56afbb842ab315a2211a88a77b5dbbcd11f743 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 28 May 2024 08:46:11 +0200 Subject: [PATCH 2/2] MOBILE-4470 compile: Remove unneeded translate pipe This pipe is no longer needed after afb5ce3cdeb50d86dffe718ddfc87b37c0d10595 --- src/core/features/compile/pipes/translate.ts | 28 ------------------- src/core/features/compile/services/compile.ts | 2 -- 2 files changed, 30 deletions(-) delete mode 100644 src/core/features/compile/pipes/translate.ts diff --git a/src/core/features/compile/pipes/translate.ts b/src/core/features/compile/pipes/translate.ts deleted file mode 100644 index 86e1ac728..000000000 --- a/src/core/features/compile/pipes/translate.ts +++ /dev/null @@ -1,28 +0,0 @@ -// (C) Copyright 2015 Moodle Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import { Injectable, Pipe, PipeTransform } from '@angular/core'; -import { TranslatePipe } from '@ngx-translate/core'; - -/** - * Copy of translate pipe to use when compiling a dynamic component. - * For some reason, when compiling a dynamic component the original translate pipe isn't found so we use this copy instead. - */ -@Injectable() -@Pipe({ - name: 'translate', - pure: false, // required to update the value when the promise is resolved - standalone: true, -}) -export class TranslatePipeForCompile extends TranslatePipe implements PipeTransform {} diff --git a/src/core/features/compile/services/compile.ts b/src/core/features/compile/services/compile.ts index f1f9073dd..2d084e4ab 100644 --- a/src/core/features/compile/services/compile.ts +++ b/src/core/features/compile/services/compile.ts @@ -33,7 +33,6 @@ import { ToastController, } from '@ionic/angular'; import { TranslateService } from '@ngx-translate/core'; -import { TranslatePipeForCompile } from '../pipes/translate'; import { CoreLogger } from '@singletons/logger'; import { CoreEvents } from '@singletons/events'; @@ -195,7 +194,6 @@ export class CoreCompileProvider { ...lazyImports.flat(), ...this.IMPORTS, ...extraImports, - TranslatePipeForCompile, ]; try {