Skip to content

Commit 859f91a

Browse files
[DevTools] Fix hooks indexes counting
1 parent 65eec42 commit 859f91a

File tree

2 files changed

+142
-5
lines changed

2 files changed

+142
-5
lines changed

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,14 @@ function useSyncExternalStore<T>(
478478
debugInfo: null,
479479
dispatcherHookName: 'SyncExternalStore',
480480
});
481+
hookLog.push({
482+
displayName: null,
483+
primitive: 'SyncExternalStore',
484+
stackError: new Error(),
485+
value,
486+
debugInfo: null,
487+
dispatcherHookName: 'SyncExternalStore',
488+
});
481489
return value;
482490
}
483491

@@ -493,6 +501,15 @@ function useTransition(): [
493501

494502
const isPending = stateHook !== null ? stateHook.memoizedState : false;
495503

504+
hookLog.push({
505+
displayName: null,
506+
primitive: 'Transition',
507+
stackError: new Error(),
508+
value: isPending,
509+
debugInfo: null,
510+
dispatcherHookName: 'Transition',
511+
});
512+
496513
hookLog.push({
497514
displayName: null,
498515
primitive: 'Transition',
@@ -642,6 +659,24 @@ function useFormState<S, P>(
642659
dispatcherHookName: 'FormState',
643660
});
644661

662+
hookLog.push({
663+
displayName: null,
664+
primitive: 'FormState',
665+
stackError: stackError,
666+
value: value,
667+
debugInfo: debugInfo,
668+
dispatcherHookName: 'FormState',
669+
});
670+
671+
hookLog.push({
672+
displayName: null,
673+
primitive: 'FormState',
674+
stackError: stackError,
675+
value: value,
676+
debugInfo: debugInfo,
677+
dispatcherHookName: 'FormState',
678+
});
679+
645680
if (error !== null) {
646681
throw error;
647682
}
@@ -712,6 +747,24 @@ function useActionState<S, P>(
712747
dispatcherHookName: 'ActionState',
713748
});
714749

750+
hookLog.push({
751+
displayName: null,
752+
primitive: 'ActionState',
753+
stackError: stackError,
754+
value: value,
755+
debugInfo: debugInfo,
756+
dispatcherHookName: 'ActionState',
757+
});
758+
759+
hookLog.push({
760+
displayName: null,
761+
primitive: 'ActionState',
762+
stackError: stackError,
763+
value: value,
764+
debugInfo: debugInfo,
765+
dispatcherHookName: 'ActionState',
766+
});
767+
715768
if (error !== null) {
716769
throw error;
717770
}

packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js

Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,20 @@ describe('ReactHooksInspectionIntegration', () => {
10261026
},
10271027
"id": 1,
10281028
"isStateEditable": false,
1029+
"name": "Transition",
1030+
"subHooks": [],
1031+
"value": false,
1032+
},
1033+
{
1034+
"debugInfo": null,
1035+
"hookSource": {
1036+
"columnNumber": 0,
1037+
"fileName": "**",
1038+
"functionName": "Foo",
1039+
"lineNumber": 0,
1040+
},
1041+
"id": 2,
1042+
"isStateEditable": false,
10291043
"name": "Memo",
10301044
"subHooks": [],
10311045
"value": "hello",
@@ -1038,7 +1052,7 @@ describe('ReactHooksInspectionIntegration', () => {
10381052
"functionName": "Foo",
10391053
"lineNumber": 0,
10401054
},
1041-
"id": 2,
1055+
"id": 3,
10421056
"isStateEditable": false,
10431057
"name": "Memo",
10441058
"subHooks": [],
@@ -1119,6 +1133,20 @@ describe('ReactHooksInspectionIntegration', () => {
11191133
},
11201134
"id": 2,
11211135
"isStateEditable": false,
1136+
"name": "Transition",
1137+
"subHooks": [],
1138+
"value": false,
1139+
},
1140+
{
1141+
"debugInfo": null,
1142+
"hookSource": {
1143+
"columnNumber": 0,
1144+
"fileName": "**",
1145+
"functionName": "Foo",
1146+
"lineNumber": 0,
1147+
},
1148+
"id": 3,
1149+
"isStateEditable": false,
11221150
"name": "Memo",
11231151
"subHooks": [],
11241152
"value": "hello",
@@ -1131,7 +1159,7 @@ describe('ReactHooksInspectionIntegration', () => {
11311159
"functionName": "Foo",
11321160
"lineNumber": 0,
11331161
},
1134-
"id": 3,
1162+
"id": 4,
11351163
"isStateEditable": false,
11361164
"name": "Memo",
11371165
"subHooks": [],
@@ -1188,6 +1216,20 @@ describe('ReactHooksInspectionIntegration', () => {
11881216
},
11891217
"id": 2,
11901218
"isStateEditable": false,
1219+
"name": "Transition",
1220+
"subHooks": [],
1221+
"value": true,
1222+
},
1223+
{
1224+
"debugInfo": null,
1225+
"hookSource": {
1226+
"columnNumber": 0,
1227+
"fileName": "**",
1228+
"functionName": "Foo",
1229+
"lineNumber": 0,
1230+
},
1231+
"id": 3,
1232+
"isStateEditable": false,
11911233
"name": "Memo",
11921234
"subHooks": [],
11931235
"value": "hello",
@@ -1200,7 +1242,7 @@ describe('ReactHooksInspectionIntegration', () => {
12001242
"functionName": "Foo",
12011243
"lineNumber": 0,
12021244
},
1203-
"id": 3,
1245+
"id": 4,
12041246
"isStateEditable": false,
12051247
"name": "Memo",
12061248
"subHooks": [],
@@ -2439,6 +2481,20 @@ describe('ReactHooksInspectionIntegration', () => {
24392481
},
24402482
"id": 1,
24412483
"isStateEditable": false,
2484+
"name": "SyncExternalStore",
2485+
"subHooks": [],
2486+
"value": "snapshot",
2487+
},
2488+
{
2489+
"debugInfo": null,
2490+
"hookSource": {
2491+
"columnNumber": 0,
2492+
"fileName": "**",
2493+
"functionName": "Foo",
2494+
"lineNumber": 0,
2495+
},
2496+
"id": 2,
2497+
"isStateEditable": false,
24422498
"name": "Memo",
24432499
"subHooks": [],
24442500
"value": "memo",
@@ -2451,7 +2507,7 @@ describe('ReactHooksInspectionIntegration', () => {
24512507
"functionName": "Foo",
24522508
"lineNumber": 0,
24532509
},
2454-
"id": 2,
2510+
"id": 3,
24552511
"isStateEditable": false,
24562512
"name": "Memo",
24572513
"subHooks": [],
@@ -2637,6 +2693,34 @@ describe('ReactHooksInspectionIntegration', () => {
26372693
},
26382694
"id": 1,
26392695
"isStateEditable": false,
2696+
"name": "ActionState",
2697+
"subHooks": [],
2698+
"value": 0,
2699+
},
2700+
{
2701+
"debugInfo": null,
2702+
"hookSource": {
2703+
"columnNumber": 0,
2704+
"fileName": "**",
2705+
"functionName": "Foo",
2706+
"lineNumber": 0,
2707+
},
2708+
"id": 2,
2709+
"isStateEditable": false,
2710+
"name": "ActionState",
2711+
"subHooks": [],
2712+
"value": 0,
2713+
},
2714+
{
2715+
"debugInfo": null,
2716+
"hookSource": {
2717+
"columnNumber": 0,
2718+
"fileName": "**",
2719+
"functionName": "Foo",
2720+
"lineNumber": 0,
2721+
},
2722+
"id": 3,
2723+
"isStateEditable": false,
26402724
"name": "Memo",
26412725
"subHooks": [],
26422726
"value": "memo",
@@ -2649,7 +2733,7 @@ describe('ReactHooksInspectionIntegration', () => {
26492733
"functionName": "Foo",
26502734
"lineNumber": 0,
26512735
},
2652-
"id": 2,
2736+
"id": 4,
26532737
"isStateEditable": false,
26542738
"name": "Memo",
26552739
"subHooks": [],

0 commit comments

Comments
 (0)