Verified Solution[facebook/react] Bug: ReactProfilerTimer transition timers are global, causing conflicts with concurrent transitions
Sponsored Content
### ROOT CAUSE
The global variables in `ReactProfilerTimer.js` are shared across all transition lanes, leading to data conflicts when multiple transitions occur concurrently. This causes inaccurate profiling data and potential race conditions.
### CODE FIX
To fix this issue, we refactor the `ReactProfilerTimer.js` module to use a `Map` where each lane ID maps to its specific timing data. Here's how the code can be updated:
```javascript
import {Lane} from 'react-reconciler/src/ReactTypes';
const transitionTimers = new Map();
export function recordTransitionStart(lane: Lane) {
if (!transitionTimers.has(lane)) {
transitionTimers.set(lane, {
startTime: -1,
updateTime: -1,
updateType: null,
clampTime: -0,
});
}
const timers = transitionTimers.get(lane);
timers.startTime = Date.now();
}
export function recordTransitionUpdate(lane: Lane, type: string) {
const timers = transitionTimers.get(lane);
timers.updateTime = Date.now();
timers.updateType = type;
}
export function recordTransitionClamp(lane: Lane, clampTime: number) {
const timers = transitionTimers.get(lane);
timers.clampTime = clampTime;
}
export function getTransitionTimer(lane: Lane): any {
return transitionTimers.get(lane);
}
```
This solution ensures each lane's timing data is isolated, preventing conflicts and ensuring accurate profiling.
Deploy on DigitalOcean ($200 Credit)
Related Fixes
[gitlab-org/gitlab] Provider indexed cache + CachedType delegator
[microsoft/vscode] 【Bug】为什么在VSCode中,ClaudeCode可以调用Pencil,而Cline却不能调用Pencil?
[golang/go] crypto/x509: overly broad excluded constraints [1.25 backport]