Skip to content

Commit

Permalink
fix(react): do not set state after FeatureAppContainer has been unmou…
Browse files Browse the repository at this point in the history
…nted (#613)
  • Loading branch information
unstubbable authored Nov 13, 2020
1 parent 3e89e75 commit ba42b6a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 16 additions & 0 deletions packages/react/src/__tests__/feature-app-container.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,22 @@ describe('FeatureAppContainer', () => {
});
});
});

describe('when unmounted before loading promise is resolved', () => {
it('does not try to set state', async () => {
const testRenderer = renderWithFeatureHubContext(
<FeatureAppContainer
featureAppId="testId"
featureAppDefinition={mockFeatureAppDefinition}
/>
);

testRenderer.unmount();
await resolveLoadingPromise();

expect(consoleErrorSpy).not.toHaveBeenCalled();
});
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ export class InternalFeatureAppContainer<

featureApp.loadingPromise
.then(() => {
this.setState({loading: false});
if (this.mounted) {
this.setState({loading: false});
}
})
.catch((loadingError) => {
try {
Expand Down

0 comments on commit ba42b6a

Please sign in to comment.