Skip to content

Commit d5352a2

Browse files
potetofacebook-github-bot
authored andcommittedJul 23, 2020
Dispose nested entrypoints when calling dispose()
Reviewed By: josephsavona Differential Revision: D22679210 fbshipit-source-id: 61a2826e5dac0d59feb4042c0a84d4c8b3d80d7c
1 parent dbbb2ed commit d5352a2

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed
 

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

+78
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,84 @@ test('it should preload entry point with both queries and nested entry points',
356356
});
357357
});
358358

359+
test('it should dispose nested entry points', () => {
360+
const env = createMockEnvironment();
361+
const nestedEntryPoint = {
362+
getPreloadProps(params) {
363+
return {
364+
queries: {
365+
myNestedQuery: {
366+
parameters: {
367+
kind: 'PreloadableConcreteRequest',
368+
params: {
369+
operationKind: 'query',
370+
name: 'MyNestedQuery',
371+
id: 'nested-query-id',
372+
text: null,
373+
metadata: {},
374+
},
375+
},
376+
variables: {
377+
id: params.id,
378+
},
379+
},
380+
},
381+
};
382+
},
383+
root: (new FakeJSResource(null): $FlowFixMe),
384+
};
385+
const entryPoint = {
386+
getPreloadProps(params) {
387+
return {
388+
queries: {
389+
myTestQuery: {
390+
parameters: {
391+
kind: 'PreloadableConcreteRequest',
392+
params: {
393+
operationKind: 'query',
394+
name: 'MyPreloadedQuery',
395+
id: 'root-query-id',
396+
text: null,
397+
metadata: {},
398+
},
399+
},
400+
variables: {
401+
id: params.id,
402+
},
403+
},
404+
},
405+
entryPoints: {
406+
myNestedEntryPoint: {
407+
entryPoint: nestedEntryPoint,
408+
entryPointParams: {
409+
id: 'nested-' + params.id,
410+
},
411+
},
412+
},
413+
};
414+
},
415+
root: (new FakeJSResource(null): $FlowFixMe),
416+
};
417+
const preloadedEntryPoint = loadEntryPoint(
418+
{
419+
getEnvironment: () => env,
420+
},
421+
entryPoint,
422+
{},
423+
);
424+
const {dispose} = preloadedEntryPoint;
425+
const nestedEntryPointDisposeSpy = jest.spyOn(
426+
preloadedEntryPoint.entryPoints.myNestedEntryPoint,
427+
'dispose',
428+
);
429+
expect(dispose).toBeDefined();
430+
if (dispose) {
431+
expect(nestedEntryPointDisposeSpy).not.toHaveBeenCalled();
432+
dispose();
433+
expect(nestedEntryPointDisposeSpy).toHaveBeenCalled();
434+
}
435+
});
436+
359437
test('with `getEnvironment` function', () => {
360438
const env = createMockEnvironment();
361439
const networkSpy = jest.spyOn(env.getNetwork(), 'execute');

‎packages/relay-experimental/loadEntryPoint.js

+7
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ function loadEntryPoint<
102102
},
103103
);
104104
}
105+
if (preloadedEntryPoints != null) {
106+
Object.values(preloadedEntryPoints).forEach(
107+
({dispose: innerDispose}: $FlowFixMe) => {
108+
innerDispose();
109+
},
110+
);
111+
}
105112
};
106113

107114
return {

0 commit comments

Comments
 (0)
Please sign in to comment.