From 6a688cc3835404907034ec935b3fce4524ec2f4c Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 29 Mar 2024 18:07:45 +0200 Subject: [PATCH] Add fallback if tag_map is uninitialized --- public/scripts/tags.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/public/scripts/tags.js b/public/scripts/tags.js index 816087d73..a20f0ff40 100644 --- a/public/scripts/tags.js +++ b/public/scripts/tags.js @@ -339,6 +339,12 @@ export function getTagKeyForEntity(entityOrKey) { x = character.avatar; } + // Uninitialized character tag map + if (character && !(x in tag_map)) { + tag_map[x] = []; + return x; + } + // We should hopefully have a key now. Let's check if (x in tag_map) { return x; @@ -349,7 +355,7 @@ export function getTagKeyForEntity(entityOrKey) { } function addTagToMap(tagId, characterId = null) { - const key = getTagKey() ?? getTagKeyForEntity(characterId); + const key = characterId !== null && characterId !== undefined ? getTagKeyForEntity(characterId) : getTagKey(); if (!key) { return; @@ -365,7 +371,7 @@ function addTagToMap(tagId, characterId = null) { } function removeTagFromMap(tagId, characterId = null) { - const key = getTagKey() ?? getTagKeyForEntity(characterId); + const key = characterId !== null && characterId !== undefined ? getTagKeyForEntity(characterId) : getTagKey(); if (!key) { return;