@apollo/client 3.12.0-alpha.0 → 3.12.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.changeset/cold-apes-bow.md +5 -0
- package/.changeset/early-bobcats-eat.md +5 -0
- package/.changeset/flat-beans-knock.md +15 -0
- package/.changeset/kind-toys-tie.md +5 -0
- package/.changeset/nervous-owls-hear.md +5 -0
- package/.changeset/pre.json +7 -2
- package/CHANGELOG.md +34 -0
- package/apollo-client.cjs +133 -77
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +30 -20
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +30 -20
- package/cache/inmemory/policies.js +12 -9
- package/cache/inmemory/policies.js.map +1 -1
- package/config/jest/setup.js +5 -0
- package/config/jest/setup.js.map +1 -1
- package/core/ApolloClient.js +7 -3
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.js +2 -0
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryManager.d.ts +4 -1
- package/core/QueryManager.js +26 -2
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +57 -20
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +57 -20
- package/core/masking.d.ts +6 -0
- package/core/masking.js +33 -15
- package/core/masking.js.map +1 -1
- package/dev/dev.cjs +66 -62
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +66 -62
- package/invariantErrorCodes.js +66 -61
- package/link/core/ApolloLink.js +2 -2
- package/link/core/core.cjs +2 -2
- package/link/core/core.cjs.map +1 -1
- package/link/core/core.cjs.native.js +2 -2
- package/link/http/checkFetcher.js +1 -1
- package/link/http/createHttpLink.js +1 -1
- package/link/http/http.cjs +3 -3
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +3 -3
- package/link/http/serializeFetchParameter.js +1 -1
- package/link/persisted-queries/index.js +2 -2
- package/link/persisted-queries/index.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs +2 -2
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
- package/link/utils/toPromise.js +1 -1
- package/link/utils/utils.cjs +2 -2
- package/link/utils/utils.cjs.map +1 -1
- package/link/utils/utils.cjs.native.js +2 -2
- package/link/utils/validateOperation.js +1 -1
- package/masking/types.d.ts +2 -2
- package/masking/types.js.map +1 -1
- package/package.json +4 -3
- package/react/context/ApolloConsumer.js +1 -1
- package/react/context/ApolloContext.js +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/context/context.cjs +3 -3
- package/react/context/context.cjs.map +1 -1
- package/react/context/context.cjs.native.js +3 -3
- package/react/hoc/hoc-utils.js +1 -1
- package/react/hoc/hoc.cjs +2 -2
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/hoc.cjs.native.js +2 -2
- package/react/hoc/withApollo.js +1 -1
- package/react/hooks/hooks.cjs +9 -9
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +9 -9
- package/react/hooks/useApolloClient.js +1 -1
- package/react/hooks/useLoadableQuery.js +2 -2
- package/react/hooks/useSubscription.js +3 -3
- package/react/hooks/useSuspenseQuery.js +2 -2
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/internal/cache/QueryReference.js +2 -2
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/internal/internal.cjs +3 -3
- package/react/internal/internal.cjs.map +1 -1
- package/react/internal/internal.cjs.native.js +3 -3
- package/react/parser/index.js +5 -5
- package/react/parser/parser.cjs +5 -5
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +5 -5
- package/testing/core/core.cjs +2 -2
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +2 -2
- package/testing/core/mocking/mockLink.js +2 -2
- package/testing/internal/ObservableStream.d.ts +11 -15
- package/testing/internal/ObservableStream.js +18 -62
- package/testing/internal/ObservableStream.js.map +1 -1
- package/testing/internal/index.d.ts +1 -2
- package/testing/internal/index.js +1 -2
- package/testing/internal/index.js.map +1 -1
- package/testing/internal/renderHelpers.d.ts +13 -2
- package/testing/internal/renderHelpers.js +20 -12
- package/testing/internal/renderHelpers.js.map +1 -1
- package/testing/matchers/index.js +0 -3
- package/testing/matchers/index.js.map +1 -1
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +1 -1
- package/utilities/graphql/DocumentTransform.js +1 -1
- package/utilities/graphql/directives.js +7 -7
- package/utilities/graphql/fragments.d.ts +1 -0
- package/utilities/graphql/fragments.js +18 -3
- package/utilities/graphql/fragments.js.map +1 -1
- package/utilities/graphql/getFromAST.js +8 -8
- package/utilities/graphql/storeUtils.js +1 -1
- package/utilities/graphql/transform.js +8 -2
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/index.d.ts +1 -1
- package/utilities/index.js +1 -1
- package/utilities/index.js.map +1 -1
- package/utilities/utilities.cjs +41 -22
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +41 -22
- package/version.js +1 -1
- package/testing/internal/profile/Render.d.ts +0 -69
- package/testing/internal/profile/Render.js +0 -144
- package/testing/internal/profile/Render.js.map +0 -1
- package/testing/internal/profile/context.d.ts +0 -10
- package/testing/internal/profile/context.js +0 -14
- package/testing/internal/profile/context.js.map +0 -1
- package/testing/internal/profile/index.d.ts +0 -4
- package/testing/internal/profile/index.js +0 -2
- package/testing/internal/profile/index.js.map +0 -1
- package/testing/internal/profile/profile.d.ts +0 -109
- package/testing/internal/profile/profile.js +0 -304
- package/testing/internal/profile/profile.js.map +0 -1
- package/testing/internal/profile/traces.d.ts +0 -7
- package/testing/internal/profile/traces.js +0 -30
- package/testing/internal/profile/traces.js.map +0 -1
- package/testing/matchers/ProfiledComponent.d.ts +0 -8
- package/testing/matchers/ProfiledComponent.js +0 -110
- package/testing/matchers/ProfiledComponent.js.map +0 -1
|
@@ -22,7 +22,7 @@ function shouldInclude(_a, variables) {
|
|
|
22
22
|
if (ifArgument.value.kind === "Variable") {
|
|
23
23
|
evaledValue =
|
|
24
24
|
variables && variables[ifArgument.value.name.value];
|
|
25
|
-
globals.invariant(evaledValue !== void 0,
|
|
25
|
+
globals.invariant(evaledValue !== void 0, 78, directive.name.value);
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
28
|
evaledValue = ifArgument.value.value;
|
|
@@ -72,12 +72,12 @@ function getInclusionDirectives(directives) {
|
|
|
72
72
|
return;
|
|
73
73
|
var directiveArguments = directive.arguments;
|
|
74
74
|
var directiveName = directive.name.value;
|
|
75
|
-
globals.invariant(directiveArguments && directiveArguments.length === 1,
|
|
75
|
+
globals.invariant(directiveArguments && directiveArguments.length === 1, 79, directiveName);
|
|
76
76
|
var ifArgument = directiveArguments[0];
|
|
77
|
-
globals.invariant(ifArgument.name && ifArgument.name.value === "if",
|
|
77
|
+
globals.invariant(ifArgument.name && ifArgument.name.value === "if", 80, directiveName);
|
|
78
78
|
var ifValue = ifArgument.value;
|
|
79
79
|
globals.invariant(ifValue &&
|
|
80
|
-
(ifValue.kind === "Variable" || ifValue.kind === "BooleanValue"),
|
|
80
|
+
(ifValue.kind === "Variable" || ifValue.kind === "BooleanValue"), 81, directiveName);
|
|
81
81
|
result.push({ directive: directive, ifArgument: ifArgument });
|
|
82
82
|
});
|
|
83
83
|
}
|
|
@@ -99,13 +99,13 @@ function getFragmentMaskMode(fragment) {
|
|
|
99
99
|
if (globalThis.__DEV__ !== false) {
|
|
100
100
|
if (modeArg) {
|
|
101
101
|
if (modeArg.value.kind === graphql.Kind.VARIABLE) {
|
|
102
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
102
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(82);
|
|
103
103
|
}
|
|
104
104
|
else if (modeArg.value.kind !== graphql.Kind.STRING) {
|
|
105
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
105
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(83);
|
|
106
106
|
}
|
|
107
107
|
else if (modeArg.value.value !== "migrate") {
|
|
108
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
108
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(84, modeArg.value.value);
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
}
|
|
@@ -144,7 +144,7 @@ function getFragmentQueryDocument(document, fragmentName) {
|
|
|
144
144
|
document.definitions.forEach(function (definition) {
|
|
145
145
|
if (definition.kind === "OperationDefinition") {
|
|
146
146
|
throw globals.newInvariantError(
|
|
147
|
-
|
|
147
|
+
85,
|
|
148
148
|
definition.operation,
|
|
149
149
|
definition.name ? " named '".concat(definition.name.value, "'") : ""
|
|
150
150
|
);
|
|
@@ -154,7 +154,7 @@ function getFragmentQueryDocument(document, fragmentName) {
|
|
|
154
154
|
}
|
|
155
155
|
});
|
|
156
156
|
if (typeof actualFragmentName === "undefined") {
|
|
157
|
-
globals.invariant(fragments.length === 1,
|
|
157
|
+
globals.invariant(fragments.length === 1, 86, fragments.length);
|
|
158
158
|
actualFragmentName = fragments[0].name.value;
|
|
159
159
|
}
|
|
160
160
|
var query = tslib.__assign(tslib.__assign({}, document), { definitions: tslib.__spreadArray([
|
|
@@ -195,13 +195,27 @@ function getFragmentFromSelection(selection, fragmentMap) {
|
|
|
195
195
|
return fragmentMap(fragmentName);
|
|
196
196
|
}
|
|
197
197
|
var fragment = fragmentMap && fragmentMap[fragmentName];
|
|
198
|
-
globals.invariant(fragment,
|
|
198
|
+
globals.invariant(fragment, 87, fragmentName);
|
|
199
199
|
return fragment || null;
|
|
200
200
|
}
|
|
201
201
|
default:
|
|
202
202
|
return null;
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
|
+
function isFullyUnmaskedOperation(document) {
|
|
206
|
+
var isUnmasked = true;
|
|
207
|
+
graphql.visit(document, {
|
|
208
|
+
FragmentSpread: function (node) {
|
|
209
|
+
isUnmasked =
|
|
210
|
+
!!node.directives &&
|
|
211
|
+
node.directives.some(function (directive) { return directive.name.value === "unmask"; });
|
|
212
|
+
if (!isUnmasked) {
|
|
213
|
+
return graphql.BREAK;
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
return isUnmasked;
|
|
218
|
+
}
|
|
205
219
|
|
|
206
220
|
var scheduledCleanup = new WeakSet();
|
|
207
221
|
function schedule(cache) {
|
|
@@ -354,7 +368,7 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
|
|
|
354
368
|
argObj[name.value] = null;
|
|
355
369
|
}
|
|
356
370
|
else {
|
|
357
|
-
throw globals.newInvariantError(
|
|
371
|
+
throw globals.newInvariantError(96, name.value, value.kind);
|
|
358
372
|
}
|
|
359
373
|
}
|
|
360
374
|
function storeKeyNameFromField(field, variables) {
|
|
@@ -488,16 +502,16 @@ function isInlineFragment(selection) {
|
|
|
488
502
|
}
|
|
489
503
|
|
|
490
504
|
function checkDocument(doc) {
|
|
491
|
-
globals.invariant(doc && doc.kind === "Document",
|
|
505
|
+
globals.invariant(doc && doc.kind === "Document", 88);
|
|
492
506
|
var operations = doc.definitions
|
|
493
507
|
.filter(function (d) { return d.kind !== "FragmentDefinition"; })
|
|
494
508
|
.map(function (definition) {
|
|
495
509
|
if (definition.kind !== "OperationDefinition") {
|
|
496
|
-
throw globals.newInvariantError(
|
|
510
|
+
throw globals.newInvariantError(89, definition.kind);
|
|
497
511
|
}
|
|
498
512
|
return definition;
|
|
499
513
|
});
|
|
500
|
-
globals.invariant(operations.length <= 1,
|
|
514
|
+
globals.invariant(operations.length <= 1, 90, operations.length);
|
|
501
515
|
return doc;
|
|
502
516
|
}
|
|
503
517
|
function getOperationDefinition(doc) {
|
|
@@ -520,14 +534,14 @@ function getFragmentDefinitions(doc) {
|
|
|
520
534
|
}
|
|
521
535
|
function getQueryDefinition(doc) {
|
|
522
536
|
var queryDef = getOperationDefinition(doc);
|
|
523
|
-
globals.invariant(queryDef && queryDef.operation === "query",
|
|
537
|
+
globals.invariant(queryDef && queryDef.operation === "query", 91);
|
|
524
538
|
return queryDef;
|
|
525
539
|
}
|
|
526
540
|
function getFragmentDefinition(doc) {
|
|
527
|
-
globals.invariant(doc.kind === "Document",
|
|
528
|
-
globals.invariant(doc.definitions.length <= 1,
|
|
541
|
+
globals.invariant(doc.kind === "Document", 92);
|
|
542
|
+
globals.invariant(doc.definitions.length <= 1, 93);
|
|
529
543
|
var fragmentDef = doc.definitions[0];
|
|
530
|
-
globals.invariant(fragmentDef.kind === "FragmentDefinition",
|
|
544
|
+
globals.invariant(fragmentDef.kind === "FragmentDefinition", 94);
|
|
531
545
|
return fragmentDef;
|
|
532
546
|
}
|
|
533
547
|
function getMainDefinition(queryDoc) {
|
|
@@ -550,7 +564,7 @@ function getMainDefinition(queryDoc) {
|
|
|
550
564
|
if (fragmentDefinition) {
|
|
551
565
|
return fragmentDefinition;
|
|
552
566
|
}
|
|
553
|
-
throw globals.newInvariantError(
|
|
567
|
+
throw globals.newInvariantError(95);
|
|
554
568
|
}
|
|
555
569
|
function getDefaultValues(definition) {
|
|
556
570
|
var defaultValues = Object.create(null);
|
|
@@ -601,7 +615,7 @@ var DocumentTransform = (function () {
|
|
|
601
615
|
makeCacheKey: function (document) {
|
|
602
616
|
var cacheKeys = _this.getCacheKey(document);
|
|
603
617
|
if (cacheKeys) {
|
|
604
|
-
globals.invariant(Array.isArray(cacheKeys),
|
|
618
|
+
globals.invariant(Array.isArray(cacheKeys), 77);
|
|
605
619
|
return stableCacheKeys_1.lookupArray(cacheKeys);
|
|
606
620
|
}
|
|
607
621
|
},
|
|
@@ -731,7 +745,7 @@ function removeDirectivesFromDocument(directives, doc) {
|
|
|
731
745
|
return getInUseByFragmentName(ancestor.name.value);
|
|
732
746
|
}
|
|
733
747
|
}
|
|
734
|
-
globalThis.__DEV__ !== false && globals.invariant.error(
|
|
748
|
+
globalThis.__DEV__ !== false && globals.invariant.error(97);
|
|
735
749
|
return null;
|
|
736
750
|
};
|
|
737
751
|
var operationCount = 0;
|
|
@@ -921,7 +935,7 @@ var connectionRemoveConfig = {
|
|
|
921
935
|
if (willRemove) {
|
|
922
936
|
if (!directive.arguments ||
|
|
923
937
|
!directive.arguments.some(function (arg) { return arg.name.value === "key"; })) {
|
|
924
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
938
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(98);
|
|
925
939
|
}
|
|
926
940
|
}
|
|
927
941
|
return willRemove;
|
|
@@ -1021,6 +1035,10 @@ function addNonReactiveToNamedFragments(document) {
|
|
|
1021
1035
|
checkDocument(document);
|
|
1022
1036
|
return graphql.visit(document, {
|
|
1023
1037
|
FragmentSpread: function (node) {
|
|
1038
|
+
var _a;
|
|
1039
|
+
if ((_a = node.directives) === null || _a === void 0 ? void 0 : _a.some(function (directive) { return directive.name.value === "unmask"; })) {
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1024
1042
|
return tslib.__assign(tslib.__assign({}, node), { directives: tslib.__spreadArray(tslib.__spreadArray([], (node.directives || []), true), [
|
|
1025
1043
|
{
|
|
1026
1044
|
kind: graphql.Kind.DIRECTIVE,
|
|
@@ -1753,6 +1771,7 @@ exports.isExecutionPatchIncrementalResult = isExecutionPatchIncrementalResult;
|
|
|
1753
1771
|
exports.isExecutionPatchInitialResult = isExecutionPatchInitialResult;
|
|
1754
1772
|
exports.isExecutionPatchResult = isExecutionPatchResult;
|
|
1755
1773
|
exports.isField = isField;
|
|
1774
|
+
exports.isFullyUnmaskedOperation = isFullyUnmaskedOperation;
|
|
1756
1775
|
exports.isInlineFragment = isInlineFragment;
|
|
1757
1776
|
exports.isMutationOperation = isMutationOperation;
|
|
1758
1777
|
exports.isNonEmptyArray = isNonEmptyArray;
|
package/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export var version = "3.12.0-
|
|
1
|
+
export var version = "3.12.0-rc.0";
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { screen } from "@testing-library/dom";
|
|
2
|
-
/** @internal */
|
|
3
|
-
export interface BaseRender {
|
|
4
|
-
id: string;
|
|
5
|
-
phase: "mount" | "update" | "nested-update";
|
|
6
|
-
actualDuration: number;
|
|
7
|
-
baseDuration: number;
|
|
8
|
-
startTime: number;
|
|
9
|
-
commitTime: number;
|
|
10
|
-
/**
|
|
11
|
-
* The number of renders that have happened so far (including this render).
|
|
12
|
-
*/
|
|
13
|
-
count: number;
|
|
14
|
-
}
|
|
15
|
-
type Screen = typeof screen;
|
|
16
|
-
/** @internal */
|
|
17
|
-
export type SyncScreen = {
|
|
18
|
-
[K in keyof Screen]: K extends `find${string}` ? {
|
|
19
|
-
/** @deprecated A snapshot is static, so avoid async queries! */
|
|
20
|
-
(...args: Parameters<Screen[K]>): ReturnType<Screen[K]>;
|
|
21
|
-
} : Screen[K];
|
|
22
|
-
};
|
|
23
|
-
/** @internal */
|
|
24
|
-
export interface Render<Snapshot> extends BaseRender {
|
|
25
|
-
/**
|
|
26
|
-
* The snapshot, as returned by the `takeSnapshot` option of `profile`.
|
|
27
|
-
* (If using `profileHook`, this is the return value of the hook.)
|
|
28
|
-
*/
|
|
29
|
-
snapshot: Snapshot;
|
|
30
|
-
/**
|
|
31
|
-
* A DOM snapshot of the rendered component, if the `snapshotDOM`
|
|
32
|
-
* option of `profile` was enabled.
|
|
33
|
-
*/
|
|
34
|
-
readonly domSnapshot: HTMLElement;
|
|
35
|
-
/**
|
|
36
|
-
* Returns a callback to receive a `screen` instance that is scoped to the
|
|
37
|
-
* DOM snapshot of this `Render` instance.
|
|
38
|
-
* Note: this is used as a callback to prevent linter errors.
|
|
39
|
-
* @example
|
|
40
|
-
* ```diff
|
|
41
|
-
* const { withinDOM } = RenderedComponent.takeRender();
|
|
42
|
-
* -expect(screen.getByText("foo")).toBeInTheDocument();
|
|
43
|
-
* +expect(withinDOM().getByText("foo")).toBeInTheDocument();
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
withinDOM: () => SyncScreen;
|
|
47
|
-
renderedComponents: Array<string | React.ComponentType>;
|
|
48
|
-
}
|
|
49
|
-
/** @internal */
|
|
50
|
-
export declare class RenderInstance<Snapshot> implements Render<Snapshot> {
|
|
51
|
-
snapshot: Snapshot;
|
|
52
|
-
private stringifiedDOM;
|
|
53
|
-
renderedComponents: Array<string | React.ComponentType>;
|
|
54
|
-
id: string;
|
|
55
|
-
phase: "mount" | "update" | "nested-update";
|
|
56
|
-
actualDuration: number;
|
|
57
|
-
baseDuration: number;
|
|
58
|
-
startTime: number;
|
|
59
|
-
commitTime: number;
|
|
60
|
-
count: number;
|
|
61
|
-
constructor(baseRender: BaseRender, snapshot: Snapshot, stringifiedDOM: string | undefined, renderedComponents: Array<string | React.ComponentType>);
|
|
62
|
-
private _domSnapshot;
|
|
63
|
-
get domSnapshot(): HTMLElement;
|
|
64
|
-
get withinDOM(): () => SyncScreen;
|
|
65
|
-
}
|
|
66
|
-
/** @internal */
|
|
67
|
-
export declare function errorOnDomInteraction(): void;
|
|
68
|
-
export {};
|
|
69
|
-
//# sourceMappingURL=Render.d.ts.map
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/* istanbul ignore file */
|
|
2
|
-
import { __spreadArray } from "tslib";
|
|
3
|
-
/*
|
|
4
|
-
Something in this file does not compile correctly while measuring code coverage
|
|
5
|
-
and will lead to a
|
|
6
|
-
Uncaught [ReferenceError: cov_1zb8w312au is not defined]
|
|
7
|
-
if we do not ignore this file in code coverage.
|
|
8
|
-
|
|
9
|
-
As we only use this file in our internal tests, we can safely ignore it.
|
|
10
|
-
*/
|
|
11
|
-
import { within, screen } from "@testing-library/dom";
|
|
12
|
-
import { JSDOM, VirtualConsole } from "jsdom";
|
|
13
|
-
import { applyStackTrace, captureStackTrace } from "./traces.js";
|
|
14
|
-
/** @internal */
|
|
15
|
-
var RenderInstance = /** @class */ (function () {
|
|
16
|
-
function RenderInstance(baseRender, snapshot, stringifiedDOM, renderedComponents) {
|
|
17
|
-
this.snapshot = snapshot;
|
|
18
|
-
this.stringifiedDOM = stringifiedDOM;
|
|
19
|
-
this.renderedComponents = renderedComponents;
|
|
20
|
-
this.id = baseRender.id;
|
|
21
|
-
this.phase = baseRender.phase;
|
|
22
|
-
this.actualDuration = baseRender.actualDuration;
|
|
23
|
-
this.baseDuration = baseRender.baseDuration;
|
|
24
|
-
this.startTime = baseRender.startTime;
|
|
25
|
-
this.commitTime = baseRender.commitTime;
|
|
26
|
-
this.count = baseRender.count;
|
|
27
|
-
}
|
|
28
|
-
Object.defineProperty(RenderInstance.prototype, "domSnapshot", {
|
|
29
|
-
get: function () {
|
|
30
|
-
if (this._domSnapshot)
|
|
31
|
-
return this._domSnapshot;
|
|
32
|
-
if (!this.stringifiedDOM) {
|
|
33
|
-
throw new Error("DOM snapshot is not available - please set the `snapshotDOM` option");
|
|
34
|
-
}
|
|
35
|
-
var virtualConsole = new VirtualConsole();
|
|
36
|
-
var stackTrace = captureStackTrace("RenderInstance.get");
|
|
37
|
-
virtualConsole.on("jsdomError", function (error) {
|
|
38
|
-
throw applyStackTrace(error, stackTrace);
|
|
39
|
-
});
|
|
40
|
-
var snapDOM = new JSDOM(this.stringifiedDOM, {
|
|
41
|
-
runScripts: "dangerously",
|
|
42
|
-
virtualConsole: virtualConsole,
|
|
43
|
-
});
|
|
44
|
-
var document = snapDOM.window.document;
|
|
45
|
-
var body = document.body;
|
|
46
|
-
var script = document.createElement("script");
|
|
47
|
-
script.type = "text/javascript";
|
|
48
|
-
script.text = "\n ".concat(errorOnDomInteraction.toString(), ";\n ").concat(errorOnDomInteraction.name, "();\n ");
|
|
49
|
-
body.appendChild(script);
|
|
50
|
-
body.removeChild(script);
|
|
51
|
-
return (this._domSnapshot = body);
|
|
52
|
-
},
|
|
53
|
-
enumerable: false,
|
|
54
|
-
configurable: true
|
|
55
|
-
});
|
|
56
|
-
Object.defineProperty(RenderInstance.prototype, "withinDOM", {
|
|
57
|
-
get: function () {
|
|
58
|
-
var _this = this;
|
|
59
|
-
var snapScreen = Object.assign(within(this.domSnapshot), {
|
|
60
|
-
debug: function () {
|
|
61
|
-
var _a = [];
|
|
62
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
63
|
-
_a[_i] = arguments[_i];
|
|
64
|
-
}
|
|
65
|
-
var _b = _a[0], dom = _b === void 0 ? _this.domSnapshot : _b, rest = _a.slice(1);
|
|
66
|
-
return screen.debug.apply(screen, __spreadArray([dom], rest, false));
|
|
67
|
-
},
|
|
68
|
-
logTestingPlaygroundURL: function () {
|
|
69
|
-
var _a = [];
|
|
70
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
71
|
-
_a[_i] = arguments[_i];
|
|
72
|
-
}
|
|
73
|
-
var _b = _a[0], dom = _b === void 0 ? _this.domSnapshot : _b, rest = _a.slice(1);
|
|
74
|
-
return screen.logTestingPlaygroundURL.apply(screen, __spreadArray([dom], rest, false));
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
return function () { return snapScreen; };
|
|
78
|
-
},
|
|
79
|
-
enumerable: false,
|
|
80
|
-
configurable: true
|
|
81
|
-
});
|
|
82
|
-
return RenderInstance;
|
|
83
|
-
}());
|
|
84
|
-
export { RenderInstance };
|
|
85
|
-
/** @internal */
|
|
86
|
-
export function errorOnDomInteraction() {
|
|
87
|
-
var events = [
|
|
88
|
-
"auxclick",
|
|
89
|
-
"blur",
|
|
90
|
-
"change",
|
|
91
|
-
"click",
|
|
92
|
-
"copy",
|
|
93
|
-
"cut",
|
|
94
|
-
"dblclick",
|
|
95
|
-
"drag",
|
|
96
|
-
"dragend",
|
|
97
|
-
"dragenter",
|
|
98
|
-
"dragleave",
|
|
99
|
-
"dragover",
|
|
100
|
-
"dragstart",
|
|
101
|
-
"drop",
|
|
102
|
-
"focus",
|
|
103
|
-
"focusin",
|
|
104
|
-
"focusout",
|
|
105
|
-
"input",
|
|
106
|
-
"keydown",
|
|
107
|
-
"keypress",
|
|
108
|
-
"keyup",
|
|
109
|
-
"mousedown",
|
|
110
|
-
"mouseenter",
|
|
111
|
-
"mouseleave",
|
|
112
|
-
"mousemove",
|
|
113
|
-
"mouseout",
|
|
114
|
-
"mouseover",
|
|
115
|
-
"mouseup",
|
|
116
|
-
"paste",
|
|
117
|
-
"pointercancel",
|
|
118
|
-
"pointerdown",
|
|
119
|
-
"pointerenter",
|
|
120
|
-
"pointerleave",
|
|
121
|
-
"pointermove",
|
|
122
|
-
"pointerout",
|
|
123
|
-
"pointerover",
|
|
124
|
-
"pointerup",
|
|
125
|
-
"scroll",
|
|
126
|
-
"select",
|
|
127
|
-
"selectionchange",
|
|
128
|
-
"selectstart",
|
|
129
|
-
"submit",
|
|
130
|
-
"toggle",
|
|
131
|
-
"touchcancel",
|
|
132
|
-
"touchend",
|
|
133
|
-
"touchmove",
|
|
134
|
-
"touchstart",
|
|
135
|
-
"wheel",
|
|
136
|
-
];
|
|
137
|
-
function warnOnDomInteraction() {
|
|
138
|
-
throw new Error("\n DOM interaction with a snapshot detected in test.\n Please don't interact with the DOM you get from `withinDOM`,\n but still use `screen' to get elements for simulating user interaction.\n ");
|
|
139
|
-
}
|
|
140
|
-
events.forEach(function (event) {
|
|
141
|
-
document.addEventListener(event, warnOnDomInteraction);
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
//# sourceMappingURL=Render.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Render.js","sourceRoot":"","sources":["../../../../src/testing/internal/profile/Render.tsx"],"names":[],"mappings":"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","sourcesContent":["/* istanbul ignore file */\n\n/*\nSomething in this file does not compile correctly while measuring code coverage\nand will lead to a\n Uncaught [ReferenceError: cov_1zb8w312au is not defined]\nif we do not ignore this file in code coverage.\n\nAs we only use this file in our internal tests, we can safely ignore it.\n*/\n\nimport { within, screen } from \"@testing-library/dom\";\nimport { JSDOM, VirtualConsole } from \"jsdom\";\nimport { applyStackTrace, captureStackTrace } from \"./traces.js\";\n\n/** @internal */\nexport interface BaseRender {\n id: string;\n phase: \"mount\" | \"update\" | \"nested-update\";\n actualDuration: number;\n baseDuration: number;\n startTime: number;\n commitTime: number;\n /**\n * The number of renders that have happened so far (including this render).\n */\n count: number;\n}\n\ntype Screen = typeof screen;\n/** @internal */\nexport type SyncScreen = {\n [K in keyof Screen]: K extends `find${string}` ?\n {\n /** @deprecated A snapshot is static, so avoid async queries! */\n (...args: Parameters<Screen[K]>): ReturnType<Screen[K]>;\n }\n : Screen[K];\n};\n\n/** @internal */\nexport interface Render<Snapshot> extends BaseRender {\n /**\n * The snapshot, as returned by the `takeSnapshot` option of `profile`.\n * (If using `profileHook`, this is the return value of the hook.)\n */\n snapshot: Snapshot;\n /**\n * A DOM snapshot of the rendered component, if the `snapshotDOM`\n * option of `profile` was enabled.\n */\n readonly domSnapshot: HTMLElement;\n /**\n * Returns a callback to receive a `screen` instance that is scoped to the\n * DOM snapshot of this `Render` instance.\n * Note: this is used as a callback to prevent linter errors.\n * @example\n * ```diff\n * const { withinDOM } = RenderedComponent.takeRender();\n * -expect(screen.getByText(\"foo\")).toBeInTheDocument();\n * +expect(withinDOM().getByText(\"foo\")).toBeInTheDocument();\n * ```\n */\n withinDOM: () => SyncScreen;\n\n renderedComponents: Array<string | React.ComponentType>;\n}\n\n/** @internal */\nexport class RenderInstance<Snapshot> implements Render<Snapshot> {\n id: string;\n phase: \"mount\" | \"update\" | \"nested-update\";\n actualDuration: number;\n baseDuration: number;\n startTime: number;\n commitTime: number;\n count: number;\n\n constructor(\n baseRender: BaseRender,\n public snapshot: Snapshot,\n private stringifiedDOM: string | undefined,\n public renderedComponents: Array<string | React.ComponentType>\n ) {\n this.id = baseRender.id;\n this.phase = baseRender.phase;\n this.actualDuration = baseRender.actualDuration;\n this.baseDuration = baseRender.baseDuration;\n this.startTime = baseRender.startTime;\n this.commitTime = baseRender.commitTime;\n this.count = baseRender.count;\n }\n\n private _domSnapshot: HTMLElement | undefined;\n get domSnapshot() {\n if (this._domSnapshot) return this._domSnapshot;\n if (!this.stringifiedDOM) {\n throw new Error(\n \"DOM snapshot is not available - please set the `snapshotDOM` option\"\n );\n }\n\n const virtualConsole = new VirtualConsole();\n const stackTrace = captureStackTrace(\"RenderInstance.get\");\n virtualConsole.on(\"jsdomError\", (error) => {\n throw applyStackTrace(error, stackTrace);\n });\n\n const snapDOM = new JSDOM(this.stringifiedDOM, {\n runScripts: \"dangerously\",\n virtualConsole,\n });\n const document = snapDOM.window.document;\n const body = document.body;\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n script.text = `\n ${errorOnDomInteraction.toString()};\n ${errorOnDomInteraction.name}();\n `;\n body.appendChild(script);\n body.removeChild(script);\n\n return (this._domSnapshot = body);\n }\n\n get withinDOM(): () => SyncScreen {\n const snapScreen = Object.assign(within(this.domSnapshot), {\n debug: (\n ...[dom = this.domSnapshot, ...rest]: Parameters<typeof screen.debug>\n ) => screen.debug(dom, ...rest),\n logTestingPlaygroundURL: (\n ...[dom = this.domSnapshot, ...rest]: Parameters<\n typeof screen.logTestingPlaygroundURL\n >\n ) => screen.logTestingPlaygroundURL(dom, ...rest),\n });\n return () => snapScreen;\n }\n}\n/** @internal */\nexport function errorOnDomInteraction() {\n const events: Array<keyof DocumentEventMap> = [\n \"auxclick\",\n \"blur\",\n \"change\",\n \"click\",\n \"copy\",\n \"cut\",\n \"dblclick\",\n \"drag\",\n \"dragend\",\n \"dragenter\",\n \"dragleave\",\n \"dragover\",\n \"dragstart\",\n \"drop\",\n \"focus\",\n \"focusin\",\n \"focusout\",\n \"input\",\n \"keydown\",\n \"keypress\",\n \"keyup\",\n \"mousedown\",\n \"mouseenter\",\n \"mouseleave\",\n \"mousemove\",\n \"mouseout\",\n \"mouseover\",\n \"mouseup\",\n \"paste\",\n \"pointercancel\",\n \"pointerdown\",\n \"pointerenter\",\n \"pointerleave\",\n \"pointermove\",\n \"pointerout\",\n \"pointerover\",\n \"pointerup\",\n \"scroll\",\n \"select\",\n \"selectionchange\",\n \"selectstart\",\n \"submit\",\n \"toggle\",\n \"touchcancel\",\n \"touchend\",\n \"touchmove\",\n \"touchstart\",\n \"wheel\",\n ];\n function warnOnDomInteraction() {\n throw new Error(`\n DOM interaction with a snapshot detected in test.\n Please don't interact with the DOM you get from \\`withinDOM\\`,\n but still use \\`screen\\' to get elements for simulating user interaction.\n `);\n }\n events.forEach((event) => {\n document.addEventListener(event, warnOnDomInteraction);\n });\n}\n"]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
export interface ProfilerContextValue {
|
|
3
|
-
renderedComponents: Array<React.ComponentType | string>;
|
|
4
|
-
}
|
|
5
|
-
export declare function ProfilerContextProvider({ children, value, }: {
|
|
6
|
-
children: React.ReactNode;
|
|
7
|
-
value: ProfilerContextValue;
|
|
8
|
-
}): React.JSX.Element;
|
|
9
|
-
export declare function useProfilerContext(): ProfilerContextValue | undefined;
|
|
10
|
-
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
var ProfilerContext = React.createContext(undefined);
|
|
3
|
-
export function ProfilerContextProvider(_a) {
|
|
4
|
-
var children = _a.children, value = _a.value;
|
|
5
|
-
var parentContext = useProfilerContext();
|
|
6
|
-
if (parentContext) {
|
|
7
|
-
throw new Error("Profilers should not be nested in the same tree");
|
|
8
|
-
}
|
|
9
|
-
return (React.createElement(ProfilerContext.Provider, { value: value }, children));
|
|
10
|
-
}
|
|
11
|
-
export function useProfilerContext() {
|
|
12
|
-
return React.useContext(ProfilerContext);
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../../src/testing/internal/profile/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,IAAM,eAAe,GAAG,KAAK,CAAC,aAAa,CACzC,SAAS,CACV,CAAC;AAEF,MAAM,UAAU,uBAAuB,CAAC,EAMvC;QALC,QAAQ,cAAA,EACR,KAAK,WAAA;IAKL,IAAM,aAAa,GAAG,kBAAkB,EAAE,CAAC;IAE3C,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IAED,OAAO,CACL,oBAAC,eAAe,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IACnC,QAAQ,CACgB,CAC5B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,KAAK,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import * as React from \"react\";\n\nexport interface ProfilerContextValue {\n renderedComponents: Array<React.ComponentType | string>;\n}\n\nconst ProfilerContext = React.createContext<ProfilerContextValue | undefined>(\n undefined\n);\n\nexport function ProfilerContextProvider({\n children,\n value,\n}: {\n children: React.ReactNode;\n value: ProfilerContextValue;\n}) {\n const parentContext = useProfilerContext();\n\n if (parentContext) {\n throw new Error(\"Profilers should not be nested in the same tree\");\n }\n\n return (\n <ProfilerContext.Provider value={value}>\n {children}\n </ProfilerContext.Provider>\n );\n}\n\nexport function useProfilerContext() {\n return React.useContext(ProfilerContext);\n}\n"]}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export type { NextRenderOptions, Profiler, ProfiledComponent, ProfiledHook, } from "./profile.js";
|
|
2
|
-
export { createProfiler, profile, profileHook, useTrackRenders, WaitForRenderTimeoutError, } from "./profile.js";
|
|
3
|
-
export type { SyncScreen } from "./Render.js";
|
|
4
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/testing/internal/profile/index.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,cAAc,EACd,OAAO,EACP,WAAW,EACX,eAAe,EACf,yBAAyB,GAC1B,MAAM,cAAc,CAAC","sourcesContent":["export type {\n NextRenderOptions,\n Profiler,\n ProfiledComponent,\n ProfiledHook,\n} from \"./profile.js\";\nexport {\n createProfiler,\n profile,\n profileHook,\n useTrackRenders,\n WaitForRenderTimeoutError,\n} from \"./profile.js\";\n\nexport type { SyncScreen } from \"./Render.js\";\n"]}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import type { Render, BaseRender } from "./Render.js";
|
|
3
|
-
type ValidSnapshot = void | (object & {
|
|
4
|
-
call?: never;
|
|
5
|
-
});
|
|
6
|
-
/** only used for passing around data internally */
|
|
7
|
-
declare const _stackTrace: unique symbol;
|
|
8
|
-
/** @internal */
|
|
9
|
-
export interface NextRenderOptions {
|
|
10
|
-
timeout?: number;
|
|
11
|
-
[_stackTrace]?: string;
|
|
12
|
-
}
|
|
13
|
-
/** @internal */
|
|
14
|
-
interface ProfilerProps {
|
|
15
|
-
children: React.ReactNode;
|
|
16
|
-
}
|
|
17
|
-
/** @internal */
|
|
18
|
-
export interface Profiler<Snapshot> extends React.FC<ProfilerProps>, ProfiledComponentFields<Snapshot>, ProfiledComponentOnlyFields<Snapshot> {
|
|
19
|
-
}
|
|
20
|
-
interface ReplaceSnapshot<Snapshot> {
|
|
21
|
-
(newSnapshot: Snapshot): void;
|
|
22
|
-
(updateSnapshot: (lastSnapshot: Readonly<Snapshot>) => Snapshot): void;
|
|
23
|
-
}
|
|
24
|
-
interface MergeSnapshot<Snapshot> {
|
|
25
|
-
(partialSnapshot: Partial<Snapshot>): void;
|
|
26
|
-
(updatePartialSnapshot: (lastSnapshot: Readonly<Snapshot>) => Partial<Snapshot>): void;
|
|
27
|
-
}
|
|
28
|
-
interface ProfiledComponentOnlyFields<Snapshot> {
|
|
29
|
-
mergeSnapshot: MergeSnapshot<Snapshot>;
|
|
30
|
-
replaceSnapshot: ReplaceSnapshot<Snapshot>;
|
|
31
|
-
}
|
|
32
|
-
interface ProfiledComponentFields<Snapshot> {
|
|
33
|
-
/**
|
|
34
|
-
* An array of all renders that have happened so far.
|
|
35
|
-
* Errors thrown during component render will be captured here, too.
|
|
36
|
-
*/
|
|
37
|
-
renders: Array<Render<Snapshot> | {
|
|
38
|
-
phase: "snapshotError";
|
|
39
|
-
count: number;
|
|
40
|
-
error: unknown;
|
|
41
|
-
}>;
|
|
42
|
-
/**
|
|
43
|
-
* Peeks the next render from the current iterator position, without advancing the iterator.
|
|
44
|
-
* If no render has happened yet, it will wait for the next render to happen.
|
|
45
|
-
* @throws {WaitForRenderTimeoutError} if no render happens within the timeout
|
|
46
|
-
*/
|
|
47
|
-
peekRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;
|
|
48
|
-
/**
|
|
49
|
-
* Iterates to the next render and returns it.
|
|
50
|
-
* If no render has happened yet, it will wait for the next render to happen.
|
|
51
|
-
* @throws {WaitForRenderTimeoutError} if no render happens within the timeout
|
|
52
|
-
*/
|
|
53
|
-
takeRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;
|
|
54
|
-
/**
|
|
55
|
-
* Returns the total number of renders.
|
|
56
|
-
*/
|
|
57
|
-
totalRenderCount(): number;
|
|
58
|
-
/**
|
|
59
|
-
* Returns the current render.
|
|
60
|
-
* @throws {Error} if no render has happened yet
|
|
61
|
-
*/
|
|
62
|
-
getCurrentRender(): Render<Snapshot>;
|
|
63
|
-
/**
|
|
64
|
-
* Waits for the next render to happen.
|
|
65
|
-
* Does not advance the render iterator.
|
|
66
|
-
*/
|
|
67
|
-
waitForNextRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;
|
|
68
|
-
}
|
|
69
|
-
export interface ProfiledComponent<Snapshot extends ValidSnapshot, Props = {}> extends React.FC<Props>, ProfiledComponentFields<Snapshot>, ProfiledComponentOnlyFields<Snapshot> {
|
|
70
|
-
}
|
|
71
|
-
/** @internal */
|
|
72
|
-
export declare function profile<Snapshot extends ValidSnapshot = void, Props = {}>({ Component, ...options }: Parameters<typeof createProfiler<Snapshot>>[0] & {
|
|
73
|
-
Component: React.ComponentType<Props>;
|
|
74
|
-
}): ProfiledComponent<Snapshot, Props>;
|
|
75
|
-
/** @internal */
|
|
76
|
-
export declare function createProfiler<Snapshot extends ValidSnapshot = void>({ onRender, snapshotDOM, initialSnapshot, skipNonTrackingRenders, }?: {
|
|
77
|
-
onRender?: (info: BaseRender & {
|
|
78
|
-
snapshot: Snapshot;
|
|
79
|
-
replaceSnapshot: ReplaceSnapshot<Snapshot>;
|
|
80
|
-
mergeSnapshot: MergeSnapshot<Snapshot>;
|
|
81
|
-
}) => void;
|
|
82
|
-
snapshotDOM?: boolean;
|
|
83
|
-
initialSnapshot?: Snapshot;
|
|
84
|
-
/**
|
|
85
|
-
* This will skip renders during which no renders tracked by
|
|
86
|
-
* `useTrackRenders` occured.
|
|
87
|
-
*/
|
|
88
|
-
skipNonTrackingRenders?: boolean;
|
|
89
|
-
}): Profiler<Snapshot>;
|
|
90
|
-
/** @internal */
|
|
91
|
-
export declare class WaitForRenderTimeoutError extends Error {
|
|
92
|
-
constructor();
|
|
93
|
-
}
|
|
94
|
-
type StringReplaceRenderWithSnapshot<T extends string> = T extends `${infer Pre}Render${infer Post}` ? `${Pre}Snapshot${Post}` : T;
|
|
95
|
-
type ResultReplaceRenderWithSnapshot<T> = T extends (...args: infer Args) => Render<infer Snapshot> ? (...args: Args) => Snapshot : T extends (...args: infer Args) => Promise<Render<infer Snapshot>> ? (...args: Args) => Promise<Snapshot> : T;
|
|
96
|
-
type ProfiledHookFields<ReturnValue> = ProfiledComponentFields<ReturnValue> extends infer PC ? {
|
|
97
|
-
[K in keyof PC as StringReplaceRenderWithSnapshot<K & string>]: ResultReplaceRenderWithSnapshot<PC[K]>;
|
|
98
|
-
} : never;
|
|
99
|
-
/** @internal */
|
|
100
|
-
export interface ProfiledHook<Props, ReturnValue> extends React.FC<Props>, ProfiledHookFields<ReturnValue> {
|
|
101
|
-
Profiler: Profiler<ReturnValue>;
|
|
102
|
-
}
|
|
103
|
-
/** @internal */
|
|
104
|
-
export declare function profileHook<ReturnValue extends ValidSnapshot, Props>(renderCallback: (props: Props) => ReturnValue): ProfiledHook<Props, ReturnValue>;
|
|
105
|
-
export declare function useTrackRenders({ name }?: {
|
|
106
|
-
name?: string;
|
|
107
|
-
}): void;
|
|
108
|
-
export {};
|
|
109
|
-
//# sourceMappingURL=profile.d.ts.map
|