Skip to content

Commit 43ce111

Browse files
committed
fix: allow renderStart to occur multiple times
1 parent 62a17b2 commit 43ce111

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/v3/hooks.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,29 @@ export const generateUseBeacon =
6565

6666
traceManager.processSpan(renderStartTaskEntry)
6767

68+
// React's concurrent rendering might pause and discard a render,
69+
// which would mean that an effect scheduled for that render does not execute because the render itself was not committed to the DOM.
70+
// we want to store the first time that the render was scheduled as the start time of rendering
71+
const renderStartRef = useRef<Timestamp | undefined>()
72+
if (!renderStartRef.current) {
73+
renderStartRef.current = renderStartTaskEntry.startTime
74+
}
75+
6876
// Beacon effect for tracking 'component-render'. This will fire after every render as it does not have any dependencies:
6977
useEffect(() => {
7078
traceManager.processSpan(
7179
makeEntry({
7280
...config,
81+
startTime: renderStartRef.current!,
7382
type: 'component-render',
74-
duration: performance.now() - renderStartTaskEntry.startTime.now,
83+
duration: performance.now() - renderStartRef.current!.now,
7584
status,
7685
attributes,
7786
renderCount: renderCountRef.current,
7887
isIdle,
7988
}),
8089
)
90+
renderStartRef.current = undefined
8191
})
8292

8393
// Beacon effect for tracking 'component-unmount' entries

0 commit comments

Comments
 (0)