From f0229548a0514b90ac43b4bec80d46e59322032a Mon Sep 17 00:00:00 2001 From: Isaries Date: Sun, 15 Nov 2026 17:48:50 +0800 Subject: [PATCH] fix(ProjectService): New unit page throws because isDefaultLocale() reads a project that is not loaded AuthoringToolComponent calls isDefaultLocale() on every UI change to decide whether to disable elements for translation. On the new unit page no project has been loaded yet, so getLocale() reads metadata from a null project and throws "Cannot read properties of null (reading 'metadata')". isDefaultLocale() now returns true when there is no project, since there is nothing to translate. --- src/app/services/projectService.spec.ts | 10 ++++++++++ src/assets/wise5/services/projectService.ts | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/app/services/projectService.spec.ts b/src/app/services/projectService.spec.ts index 6dfbb48375d..eaf5f653bc6 100644 --- a/src/app/services/projectService.spec.ts +++ b/src/app/services/projectService.spec.ts @@ -66,6 +66,7 @@ describe('ProjectService', () => { getMaxScoreForNode(); getPeerGrouping(); parseProject(); + isDefaultLocale(); // TODO: add test for service.getFlattenedProjectAsNodeIds() // TODO: add test for service.getFirstNodeIdInPathAtIndex() // TODO: add test for service.removeNodeIdFromPaths() @@ -602,3 +603,12 @@ function expectNodeIdsToHaveNumbers(objs: any[]): void { function expectNodeIdToHaveNumber(nodeId: string, number: string): void { expect(service.nodeIdToNumber[nodeId]).toEqual(number); } + +function isDefaultLocale() { + describe('isDefaultLocale()', () => { + it('should return true when no project is loaded', () => { + service.project = null; + expect(service.isDefaultLocale()).toBeTrue(); + }); + }); +} diff --git a/src/assets/wise5/services/projectService.ts b/src/assets/wise5/services/projectService.ts index 55aa647da4f..f36f950c44c 100644 --- a/src/assets/wise5/services/projectService.ts +++ b/src/assets/wise5/services/projectService.ts @@ -1856,6 +1856,9 @@ export class ProjectService { } isDefaultLocale(): boolean { + if (this.project == null) { + return true; + } return this.getLocale().isDefaultLocale(this.currentLanguage().locale); }