fixed builder hydration issues

This commit is contained in:
2026-01-18 08:39:29 -05:00
parent b55bd7041d
commit 045e742362
5 changed files with 1143 additions and 299 deletions
+8 -7
View File
@@ -1,4 +1,4 @@
import type { CategoryId } from "@/types/builderSlots";
import type { BuilderSlotKey } from "@/types/builderSlots";
/**
* Normalize backend part roles into a canonical kebab-case form.
@@ -16,7 +16,7 @@ export const normalizePartRole = (role: string) =>
* - Keep the list here as the *source of truth*.
* - The derived `PART_ROLE_TO_CATEGORY` map below stores both the original and normalized keys.
*/
export const CATEGORY_TO_PART_ROLES: Partial<Record<CategoryId, string[]>> = {
export const CATEGORY_TO_PART_ROLES: Partial<Record<BuilderSlotKey, string[]>> = {
// ===== UPPER =====
"upper-receiver": ["upper-receiver"],
// (optional) Back-compat if anything still uses the old ids:
@@ -37,7 +37,8 @@ export const CATEGORY_TO_PART_ROLES: Partial<Record<CategoryId, string[]>> = {
// (optional) Back-compat if anything still uses the old ids:
"complete-lower": ["complete-lower"],
"lower-parts": ["lower-parts-kit", "lower-parts"],
// Lower Parts Kit (LPK)
"lower-parts-kit": ["lower-parts-kit", "lower-parts"],
trigger: ["trigger", "trigger-kit"],
grip: ["pistol-grip", "grip"],
safety: ["safety", "safety-selector"],
@@ -86,15 +87,15 @@ export const CATEGORY_TO_PART_ROLES: Partial<Record<CategoryId, string[]>> = {
* - Stores BOTH the original role and its normalized version as keys.
* - De-dupes role lists per category.
*/
export const PART_ROLE_TO_CATEGORY: Record<string, CategoryId> = Object.entries(
export const PART_ROLE_TO_CATEGORY: Record<string, BuilderSlotKey> = Object.entries(
CATEGORY_TO_PART_ROLES
).reduce((acc, [categoryId, roles]) => {
const unique = Array.from(new Set(roles ?? []));
for (const role of unique) {
acc[role] = categoryId as CategoryId;
acc[normalizePartRole(role)] = categoryId as CategoryId;
acc[role] = categoryId as BuilderSlotKey;
acc[normalizePartRole(role)] = categoryId as BuilderSlotKey;
}
return acc;
}, {} as Record<string, CategoryId>);
}, {} as Record<string, BuilderSlotKey>);