@littlepartytime/dev-kit 1.15.1 → 1.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -19,6 +19,8 @@ export default function Play() {
|
|
|
19
19
|
|
|
20
20
|
const isAutoMode = useMemo(() => new URLSearchParams(window.location.search).get('auto') === 'true', []);
|
|
21
21
|
const [myPlayerId, setMyPlayerId] = useState<string | null>(null);
|
|
22
|
+
// Ref survives React Fast Refresh (HMR) but not new tabs — perfect for reconnect identity
|
|
23
|
+
const assignedNicknameRef = useRef<string | null>(null);
|
|
22
24
|
|
|
23
25
|
// Load renderer
|
|
24
26
|
useEffect(() => {
|
|
@@ -28,13 +30,12 @@ export default function Play() {
|
|
|
28
30
|
}, []);
|
|
29
31
|
|
|
30
32
|
// Auto-join: connect immediately with server-assigned name
|
|
31
|
-
//
|
|
33
|
+
// assignedNicknameRef persists across HMR (React Refresh keeps refs) but resets per new tab
|
|
32
34
|
useEffect(() => {
|
|
33
35
|
if (!isAutoMode) return;
|
|
34
36
|
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
? { nickname: JSON.parse(stored).nickname }
|
|
37
|
+
const query = assignedNicknameRef.current
|
|
38
|
+
? { nickname: assignedNicknameRef.current }
|
|
38
39
|
: { auto: 'true' };
|
|
39
40
|
|
|
40
41
|
const sock = io('http://localhost:4001', { query });
|
|
@@ -47,7 +48,7 @@ export default function Play() {
|
|
|
47
48
|
sock.on('player:assigned', ({ id, nickname: assignedName }: { id: string; nickname: string }) => {
|
|
48
49
|
setMyPlayerId(id);
|
|
49
50
|
setNickname(assignedName);
|
|
50
|
-
|
|
51
|
+
assignedNicknameRef.current = assignedName;
|
|
51
52
|
});
|
|
52
53
|
|
|
53
54
|
sock.on('room:update', (r: any) => {
|