Skip to content

Commit 01bd074

Browse files
committed
Synchronize resuspending with the current timeline index
This uses an effect event since we're not reacting to changes in the timeline after the timeline index has changed. Otherwise we'd infinite loop.
1 parent 767c571 commit 01bd074

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

packages/react-devtools-shared/src/devtools/views/SuspenseTab/SuspenseTimeline.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,7 @@ function SuspenseTimelineInput() {
101101
}
102102

103103
function handleChange(event: SyntheticEvent) {
104-
if (rootID === null) {
105-
return;
106-
}
107-
const rendererID = store.getRendererIDForElement(rootID);
108-
if (rendererID === null) {
109-
console.error(
110-
`No renderer ID found for root element ${rootID} in suspense timeline.`,
111-
);
112-
return;
113-
}
114-
115104
const pendingTimelineIndex = +event.currentTarget.value;
116-
const suspendedSet = timeline.slice(pendingTimelineIndex);
117-
118-
bridge.send('overrideSuspenseMilestone', {
119-
rendererID,
120-
rootID,
121-
suspendedSet,
122-
});
123-
124105
switchSuspenseNode(pendingTimelineIndex);
125106
}
126107

@@ -189,6 +170,32 @@ function SuspenseTimelineInput() {
189170
});
190171
}
191172

173+
// TODO: useEffectEvent here once it's supported in all versions DevTools supports.
174+
// For now we just exclude it from deps since we don't lint those anyway.
175+
function changeTimelineIndex(newIndex: number) {
176+
// Synchronize timeline index with what is resuspended.
177+
if (rootID === null) {
178+
return;
179+
}
180+
const rendererID = store.getRendererIDForElement(rootID);
181+
if (rendererID === null) {
182+
console.error(
183+
`No renderer ID found for root element ${rootID} in suspense timeline.`,
184+
);
185+
return;
186+
}
187+
const suspendedSet = timeline.slice(timelineIndex);
188+
bridge.send('overrideSuspenseMilestone', {
189+
rendererID,
190+
rootID,
191+
suspendedSet,
192+
});
193+
}
194+
195+
useEffect(() => {
196+
changeTimelineIndex(timelineIndex);
197+
}, [timelineIndex]);
198+
192199
useEffect(() => {
193200
if (!playing) {
194201
return undefined;

0 commit comments

Comments
 (0)