Skip to content

Commit

Permalink
fix: prevent calls to setState when disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
yhkaplan committed May 26, 2023
1 parent cd7d8f9 commit 482b814
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ export const ReactNavigationPerformanceView = (props: Props) => {
);

useEffect(() => {
if (!isStack) {
if (!isStack || !stateController.isEnabled) {
return;
}
return addListener('transitionEnd', () => {
setTransitionEnded(true);
});
}, [addListener, isStack]);
}, [addListener, isStack, stateController.isEnabled]);

let shouldReportTransitionEnd = false;
if (isStack && transitionEnded && transitionEndReported.current === false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ const createAddListenerMock = () => {
describe('ReactNavigationPerformanceView', () => {
beforeEach(() => {
jest.clearAllMocks();
useStateControllerMock.mockReturnValue({
isEnabled: true,
});
});

describe('when screen is interactive on mount', () => {
Expand Down Expand Up @@ -276,4 +279,25 @@ describe('ReactNavigationPerformanceView', () => {
});
});
});

describe('when disabled', () => {
beforeEach(() => {
useStateControllerMock.mockReturnValue({
isEnabled: false,
});
});

it('does not add a listener with setState for transitionEnd', () => {
const {wrapper, triggerTransitionEnd} = mountReactNavigationPerformanceView({
renderPassName: LOADING,
interactive: true,
});

wrapper.act(() => {
triggerTransitionEnd();
});

expect(wrapper.context.navigation.addListener).not.toBeCalledWith('transitionEnd', expect.anything());
});
});
});

0 comments on commit 482b814

Please sign in to comment.