Skip to content

Commit 7818bfb

Browse files
James Friendfacebook-github-bot
James Friend
authored andcommittedSep 16, 2020
Add Relay log event for when an EntryPointContainer uses an entrypoint component resource
Reviewed By: jstejada Differential Revision: D23402346 fbshipit-source-id: 51befac08ae41495ec55d78ea8c740d3bf0ca029
1 parent 96bc50d commit 7818bfb

7 files changed

+56
-3
lines changed
 

‎packages/relay-experimental/EntryPointContainer.react.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313

1414
'use strict';
1515

16+
const ProfilerContext = require('./ProfilerContext');
1617
const React = require('react');
1718

19+
const useRelayEnvironment = require('./useRelayEnvironment');
1820
const warning = require('warning');
1921

22+
const {useContext, useEffect} = require('react');
23+
2024
import type {
2125
EntryPointComponent,
2226
PreloadedEntryPoint,
@@ -47,8 +51,23 @@ function EntryPointContainer<
4751
'collection, and as such may no longer be present in the Relay store. ' +
4852
'In the future, this will become a hard error.',
4953
);
50-
const {getComponent, queries, entryPoints, extraProps} = entryPointReference;
54+
const {
55+
getComponent,
56+
queries,
57+
entryPoints,
58+
extraProps,
59+
rootModuleReference,
60+
} = entryPointReference;
5161
const Component = getComponent();
62+
const profilerContext = useContext(ProfilerContext);
63+
const environment = useRelayEnvironment();
64+
useEffect(() => {
65+
environment.__log({
66+
name: 'entrypoint.root.consume',
67+
profilerContext,
68+
rootModuleID: rootModuleReference.getModuleId(),
69+
});
70+
}, [environment, profilerContext, rootModuleReference]);
5271
return (
5372
<Component
5473
entryPoints={entryPoints}

‎packages/relay-experimental/EntryPointTypes.flow.js

+1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ export type PreloadedEntryPoint<TEntryPointComponent> = $ReadOnly<{|
207207
getComponent: () => TEntryPointComponent,
208208
isDisposed: boolean,
209209
queries: $PropertyType<ElementConfig<TEntryPointComponent>, 'queries'>,
210+
rootModuleReference: JSResourceReference<TEntryPointComponent>,
210211
|}>;
211212

212213
export type ThinQueryParams<

‎packages/relay-experimental/LazyLoadEntryPointContainer_DEPRECATED.react.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313

1414
'use strict';
1515

16+
const ProfilerContext = require('./ProfilerContext');
1617
const React = require('react');
1718

1819
const preloadQuery_DEPRECATED = require('./preloadQuery_DEPRECATED');
1920
const useRelayEnvironment = require('./useRelayEnvironment');
2021

21-
const {useMemo} = require('react');
22+
const {useContext, useEffect, useMemo} = require('react');
2223
const {stableCopy} = require('relay-runtime');
2324

25+
import type {JSResourceReference} from 'JSResourceReference';
26+
2427
type PreloadedEntryPoint<TEntryPointComponent> = $ReadOnly<{|
2528
entryPoints: $PropertyType<
2629
React.ElementConfig<TEntryPointComponent>,
@@ -32,6 +35,7 @@ type PreloadedEntryPoint<TEntryPointComponent> = $ReadOnly<{|
3235
>,
3336
getComponent: () => TEntryPointComponent,
3437
queries: $PropertyType<React.ElementConfig<TEntryPointComponent>, 'queries'>,
38+
rootModuleReference: JSResourceReference<TEntryPointComponent>,
3539
|}>;
3640

3741
import type {
@@ -150,6 +154,8 @@ function prepareEntryPoint<
150154
return (component: TEntryPointComponent);
151155
},
152156
queries: (preloadedQueries: TPreloadedQueries),
157+
// $FlowFixMe[incompatible-cast] - trust me Flow, its entryPoint component
158+
rootModuleReference: (entryPoint.root: JSResourceReference<TEntryPointComponent>),
153159
};
154160
}
155161

@@ -177,7 +183,13 @@ function LazyLoadEntryPointContainer_DEPRECATED<
177183
// *must* be computed first to fetch the component's data-dependencies in
178184
// parallel with the component itself (the code).
179185
const entryPointParamsHash = stableStringify(entryPointParams);
180-
const {getComponent, queries, entryPoints, extraProps} = useMemo(() => {
186+
const {
187+
getComponent,
188+
queries,
189+
entryPoints,
190+
extraProps,
191+
rootModuleReference,
192+
} = useMemo(() => {
181193
return prepareEntryPoint(
182194
environmentProvider ?? {
183195
getEnvironment: () => environment,
@@ -191,6 +203,15 @@ function LazyLoadEntryPointContainer_DEPRECATED<
191203
const Component = useMemo(() => {
192204
return getComponent();
193205
}, [getComponent]);
206+
207+
const profilerContext = useContext(ProfilerContext);
208+
useEffect(() => {
209+
environment.__log({
210+
name: 'entrypoint.root.consume',
211+
profilerContext,
212+
rootModuleID: rootModuleReference.getModuleId(),
213+
});
214+
}, [environment, profilerContext, rootModuleReference]);
194215
return (
195216
<Component
196217
entryPoints={entryPoints}

‎packages/relay-experimental/__tests__/EntryPointContainer-test.js

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ let nestedEntryPointResource;
7777
class FakeJSResource<T> {
7878
_resolve: (T => mixed) | null;
7979
_resource: T | null;
80+
getModuleId: () => string;
8081
getModuleIfRequired: () => T | null;
8182
load: () => Promise<T>;
8283
resolve: T => void;
@@ -85,6 +86,7 @@ class FakeJSResource<T> {
8586
this._resolve = null;
8687
this._resource = resource;
8788

89+
this.getModuleId = jest.fn(() => 'TheModuleID');
8890
this.getModuleIfRequired = jest.fn(() => this._resource);
8991
this.load = jest.fn(() => {
9092
return new Promise(resolve => {

‎packages/relay-experimental/__tests__/LazyLoadEntryPointContainer_DEEPRECATED-test.js

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ let params;
6969
class FakeJSResource<T> {
7070
_resolve: (T => mixed) | null;
7171
_resource: T | null;
72+
getModuleId: () => string;
7273
getModuleIfRequired: () => T | null;
7374
load: () => Promise<T>;
7475
resolve: T => void;
@@ -77,6 +78,7 @@ class FakeJSResource<T> {
7778
this._resolve = null;
7879
this._resource = resource;
7980

81+
this.getModuleId = jest.fn(() => 'TheModuleID');
8082
this.getModuleIfRequired = jest.fn(() => this._resource);
8183
this.load = jest.fn(() => {
8284
return new Promise(resolve => {

‎packages/relay-experimental/loadEntryPoint.js

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
const {loadQuery} = require('./loadQuery');
1515

16+
import type {JSResourceReference} from 'JSResourceReference';
1617
import type {
1718
EntryPoint,
1819
EntryPointComponent,
@@ -132,6 +133,8 @@ function loadEntryPoint<
132133
return isDisposed;
133134
},
134135
queries: (preloadedQueries: TPreloadedQueries),
136+
// $FlowFixMe[incompatible-cast] - trust me Flow, its entryPoint component
137+
rootModuleReference: (entryPoint.root: JSResourceReference<TEntryPointComponent>),
135138
};
136139
}
137140

‎packages/relay-runtime/store/RelayStoreTypes.js

+5
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,11 @@ export type LogEvent =
489489
+name: 'read.missing_required_field',
490490
+owner: string,
491491
+fieldPath: string,
492+
|}
493+
| {|
494+
+name: 'entrypoint.root.consume',
495+
+profilerContext: mixed,
496+
+rootModuleID: string,
492497
|};
493498

494499
export type LogFunction = LogEvent => void;

0 commit comments

Comments
 (0)
Please sign in to comment.