fix: reset previousPartIdsRef on build clear; clarify first-hydration skip comment

This commit is contained in:
2026-03-25 07:05:57 -04:00
parent f12e2ffee7
commit 668398e66a
+4 -2
View File
@@ -618,6 +618,7 @@ function GunbuilderPageContent() {
if (ids.length === 0) {
lastHydrateKeyRef.current = "";
setParts([]);
previousPartIdsRef.current = new Set(); // keep in sync so re-selecting fires the event
setError(null);
setLoading(false);
return;
@@ -670,8 +671,9 @@ function GunbuilderPageContent() {
setParts(hydrated);
// Track newly selected parts (fires after API returns with real names).
// Skip the first hydration that's restoring a saved build, not a new selection.
// Track newly selected parts after API fetch — fires with real name, not a numeric ID.
// Skip the first hydration: this covers both localStorage build restoration and ?select=
// share-link arrivals. Neither represents a live user interaction in the current session.
if (isFirstPartsHydrationRef.current) {
isFirstPartsHydrationRef.current = false;
} else {