Skip to content

Commit 11803b9

Browse files
useBackgroundQuery: remove promiseCache, work around race condition (#11366)
Co-authored-by: Jerel Miller <[email protected]> Co-authored-by: phryneas <[email protected]>
1 parent b112bcf commit 11803b9

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/testing/internal/profile/profile.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,8 @@ export interface ProfiledComponent<Snapshot extends ValidSnapshot, Props = {}>
9898
export function profile<Snapshot extends ValidSnapshot = void, Props = {}>({
9999
Component,
100100
...options
101-
}: {
102-
onRender?: (
103-
info: BaseRender & {
104-
snapshot: Snapshot;
105-
replaceSnapshot: ReplaceSnapshot<Snapshot>;
106-
mergeSnapshot: MergeSnapshot<Snapshot>;
107-
}
108-
) => void;
101+
}: Parameters<typeof createProfiler<Snapshot>>[0] & {
109102
Component: React.ComponentType<Props>;
110-
snapshotDOM?: boolean;
111-
initialSnapshot?: Snapshot;
112103
}): ProfiledComponent<Snapshot, Props> {
113104
const Profiler = createProfiler(options);
114105

@@ -140,6 +131,7 @@ export function createProfiler<Snapshot extends ValidSnapshot = void>({
140131
onRender,
141132
snapshotDOM = false,
142133
initialSnapshot,
134+
skipNonTrackingRenders,
143135
}: {
144136
onRender?: (
145137
info: BaseRender & {
@@ -150,6 +142,11 @@ export function createProfiler<Snapshot extends ValidSnapshot = void>({
150142
) => void;
151143
snapshotDOM?: boolean;
152144
initialSnapshot?: Snapshot;
145+
/**
146+
* This will skip renders during which no renders tracked by
147+
* `useTrackRenders` occured.
148+
*/
149+
skipNonTrackingRenders?: boolean;
153150
} = {}) {
154151
let nextRender: Promise<Render<Snapshot>> | undefined;
155152
let resolveNextRender: ((render: Render<Snapshot>) => void) | undefined;
@@ -194,6 +191,12 @@ export function createProfiler<Snapshot extends ValidSnapshot = void>({
194191
startTime,
195192
commitTime
196193
) => {
194+
if (
195+
skipNonTrackingRenders &&
196+
profilerContext.renderedComponents.length === 0
197+
) {
198+
return;
199+
}
197200
const baseRender = {
198201
id,
199202
phase,

0 commit comments

Comments
 (0)