Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current behavior of "What caused this update?" to point to host root after a ping #29735

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
DevTools: Fix "unknown" updater in profiler when a component unsuspends
  • Loading branch information
eps1lon committed Jun 2, 2024
commit dcc5ca6c84ea7c998a844a678e79ca8d8231be92
24 changes: 23 additions & 1 deletion packages/react-reconciler/src/ReactFiberLane.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,27 @@ export function markRootUpdated(root: FiberRoot, updateLane: Lane) {
// idle updates until after all the regular updates have finished; there's no
// way it could unblock a transition.
if (updateLane !== IdleLane) {
if (enableUpdaterTracking) {
if (isDevToolsPresent) {
// transfer pending updaters from pingedLanes to updateLane
const pendingUpdatersLaneMap = root.pendingUpdatersLaneMap;
const updaters = pendingUpdatersLaneMap[laneToIndex(updateLane)];
let lanes = root.pingedLanes;
while (lanes > 0) {
const index = laneToIndex(lanes);
const lane = 1 << index;

const pingedUpdaters = pendingUpdatersLaneMap[index];
pingedUpdaters.forEach(pingedUpdater => {
updaters.add(pingedUpdater);
});
pingedUpdaters.clear();

lanes &= ~lane;
}
}
}

root.suspendedLanes = NoLanes;
root.pingedLanes = NoLanes;
}
Expand Down Expand Up @@ -656,7 +677,8 @@ export function markRootSuspended(
}

export function markRootPinged(root: FiberRoot, pingedLanes: Lanes) {
root.pingedLanes |= root.suspendedLanes & pingedLanes;
// TODO: When would we ever ping lanes that we aren't suspended on?
root.pingedLanes |= pingedLanes;
}

export function markRootFinished(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ describe('updaters', () => {
schedulerTags.push(fiber.tag);
schedulerTypes.push(fiber.elementType);
});
fiberRoot.pendingUpdatersLaneMap.forEach((pendingUpdaters, index) => {
if (pendingUpdaters.size > 0) {
const lane = 1 << index;
throw new Error(
`Lane ${lane} has pending updaters. Either you didn't assert on all updates in your test or React is leaking updaters.`,
);
}
});
allSchedulerTags.push(schedulerTags);
allSchedulerTypes.push(schedulerTypes);
}),
Expand Down Expand Up @@ -266,9 +274,6 @@ describe('updaters', () => {
await waitForAll([]);
});

// This test should be convertable to createRoot but the allScheduledTypes assertions are no longer the same
// So I'm leaving it in legacy mode for now and just disabling if legacy mode is turned off
// @gate !disableLegacyMode
it('should cover suspense pings', async () => {
let data = null;
let resolver = null;
Expand Down Expand Up @@ -323,7 +328,7 @@ describe('updaters', () => {
return promise;
});
assertLog(['onCommitRoot']);
expect(allSchedulerTypes).toEqual([[null], [Suspender], []]);
expect(allSchedulerTypes).toEqual([[null], [Suspender], [Suspender]]);

// Verify no outstanding flushes
await waitForAll([]);
Expand Down