From 55312b48ae225237d70d2df6cbcb9bdb633fffe3 Mon Sep 17 00:00:00 2001 From: dominik-korsa <29484605+dominik-korsa@users.noreply.github.com> Date: Sun, 13 Jul 2025 23:06:09 +0200 Subject: [PATCH] Don't use flapMap for a single category in SceneryLayer --- src/components/map/SceneryLayer.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/map/SceneryLayer.js b/src/components/map/SceneryLayer.js index 3ea50f5..ee26395 100644 --- a/src/components/map/SceneryLayer.js +++ b/src/components/map/SceneryLayer.js @@ -13,12 +13,15 @@ export default function SceneryLayer(props) { const objects = useMemo(() => { if (!scenery || !isVisible) return []; - const categoryList = typeof category === 'string' ? [category] : category; - return categoryList.flatMap((category) => { + + const getCategoryObjects = (category) => { const categoryObjs = scenery.objects[category]; if (!categoryObjs) return []; return Object.values(categoryObjs); - }); + } + // flatMap is not used in the case of a single category to avoid an unnecessary array copy + if (typeof category === 'string') return getCategoryObjects(category); + return category.flatMap(getCategoryObjects); }, [scenery, category, isVisible]); if (!scenery || !isVisible) return null;