Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Commit 4e260da

Browse files
committed
Prevent calls to setState when disabled
1 parent cd7d8f9 commit 4e260da

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

packages/react-native-performance-navigation/src/ReactNavigationPerformanceView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ export const ReactNavigationPerformanceView = (props: Props) => {
3333
);
3434

3535
useEffect(() => {
36-
if (!isStack) {
36+
if (!isStack || !stateController.isEnabled) {
3737
return;
3838
}
3939
return addListener('transitionEnd', () => {
4040
setTransitionEnded(true);
4141
});
42-
}, [addListener, isStack]);
42+
}, [addListener, isStack, stateController.isEnabled]);
4343

4444
let shouldReportTransitionEnd = false;
4545
if (isStack && transitionEnded && transitionEndReported.current === false) {

packages/react-native-performance-navigation/src/__tests__/ReactNavigationPerformanceView.test.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ const createAddListenerMock = () => {
7373
describe('ReactNavigationPerformanceView', () => {
7474
beforeEach(() => {
7575
jest.clearAllMocks();
76+
useStateControllerMock.mockReturnValue({
77+
isEnabled: true,
78+
});
7679
});
7780

7881
describe('when screen is interactive on mount', () => {
@@ -276,4 +279,25 @@ describe('ReactNavigationPerformanceView', () => {
276279
});
277280
});
278281
});
282+
283+
describe('when disabled', () => {
284+
beforeEach(() => {
285+
useStateControllerMock.mockReturnValue({
286+
isEnabled: false,
287+
});
288+
});
289+
290+
it('does not add a listener with setState for transitionEnd', () => {
291+
const {wrapper, triggerTransitionEnd} = mountReactNavigationPerformanceView({
292+
renderPassName: LOADING,
293+
interactive: true,
294+
});
295+
296+
wrapper.act(() => {
297+
triggerTransitionEnd();
298+
});
299+
300+
expect(wrapper.context.navigation.addListener).not.toBeCalledWith('transitionEnd', expect.anything());
301+
});
302+
});
279303
});

0 commit comments

Comments
 (0)