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

One more idea for the profiler #11379

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
562c3bb
Make profile return wrapper component without taking internal component
jerelmiller Nov 22, 2023
841a9ef
Rename profile to createTestProfiler
jerelmiller Nov 22, 2023
ed0d2fc
Fix error fallback in default creation
jerelmiller Nov 22, 2023
895792c
Convert additional test to updated API
jerelmiller Nov 22, 2023
ee44633
Rename ProfiledComponent type to Profiler
jerelmiller Nov 22, 2023
2a433a4
Remove unneeded wrapper for tracking renders
jerelmiller Nov 22, 2023
e5efcc9
Don't require args to createTestProfiler
jerelmiller Nov 22, 2023
c39cba0
Fix types on profiled hook
jerelmiller Nov 22, 2023
1e64614
Track component function instead of component name for rendered compo…
jerelmiller Nov 22, 2023
02aa46c
Fix type on matchers
jerelmiller Nov 22, 2023
61443bd
Move render context into own file and add all of context to render in…
jerelmiller Nov 22, 2023
d8c129e
Copy context before passing to RenderInstance
jerelmiller Nov 22, 2023
4914048
Throw if render context is not found
jerelmiller Nov 22, 2023
87bcbb9
Rename useTrackComponentRender to useTrackRender
jerelmiller Nov 22, 2023
a683081
Go back to renderedComponents directly on RenderInstance
jerelmiller Nov 22, 2023
5c562e4
Remove eslint disable
jerelmiller Nov 22, 2023
5e8aadc
Update another test to use new pattern
jerelmiller Nov 22, 2023
79e00f5
Fix usage of profileHook with updates to profiler
jerelmiller Nov 22, 2023
659f884
Fix matchers with updates to profiler
jerelmiller Nov 22, 2023
2a5a487
Update test that checks context to use updated API
jerelmiller Nov 22, 2023
836c1c4
Update another test that checks client overriden to new API
jerelmiller Nov 22, 2023
4d27a07
Update test that checks for cache update
jerelmiller Nov 22, 2023
2b64982
Rename render context to profiler context
jerelmiller Nov 22, 2023
5df75f9
Extract helper to create default profiler for the tests
jerelmiller Nov 22, 2023
c408bed
Convert test that checks for canonical results to new API
jerelmiller Nov 22, 2023
554ecac
Update cache-and-network test to new API
jerelmiller Nov 22, 2023
891183c
Update test that checks for rendered error boundary when refetch throws
jerelmiller Nov 22, 2023
ce05f8a
Update multiple refetch test to use new API
jerelmiller Nov 22, 2023
ccde7cb
Rename createTestProfiler to createProfiler
jerelmiller Nov 27, 2023
0d141df
Recreate profile helper by using createProfiler
jerelmiller Nov 27, 2023
4b9a0ec
Use profile export in tests that previously used it
jerelmiller Nov 27, 2023
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
496 changes: 337 additions & 159 deletions src/react/hooks/__tests__/useLoadableQuery.test.tsx

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/testing/internal/profile/Render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface Render<Snapshot> extends BaseRender {
*/
withinDOM: () => SyncScreen;

renderedComponents: string[];
renderedComponents: React.ComponentType[];
}

/** @internal */
Expand All @@ -80,7 +80,7 @@ export class RenderInstance<Snapshot> implements Render<Snapshot> {
baseRender: BaseRender,
public snapshot: Snapshot,
private stringifiedDOM: string | undefined,
public renderedComponents: string[]
public renderedComponents: React.ComponentType[]
) {
this.id = baseRender.id;
this.phase = baseRender.phase;
Expand Down
33 changes: 33 additions & 0 deletions src/testing/internal/profile/context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as React from "react";

export interface ProfilerContextValue {
renderedComponents: React.ComponentType[];
}

const ProfilerContext = React.createContext<ProfilerContextValue | undefined>(
undefined
);

export function ProfilerContextProvider({
children,
value,
}: {
children: React.ReactNode;
value: ProfilerContextValue;
}) {
const parentContext = useProfilerContext();

if (parentContext) {
throw new Error("Profilers should not be nested in the same tree");
}

return (
<ProfilerContext.Provider value={value}>
{children}
</ProfilerContext.Provider>
);
}

export function useProfilerContext() {
return React.useContext(ProfilerContext);
}
9 changes: 8 additions & 1 deletion src/testing/internal/profile/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
export type {
NextRenderOptions,
Profiler,
ProfiledComponent,
ProfiledHook,
} from "./profile.js";
export { profile, profileHook, WaitForRenderTimeoutError } from "./profile.js";
export {
createProfiler,
profile,
profileHook,
useTrackRender,
WaitForRenderTimeoutError,
} from "./profile.js";

export type { SyncScreen } from "./Render.js";
Loading
Loading