Skip to content

Commit 5f404ff

Browse files
ref(js): Remove enforceActOnUseLegacyStoreHook hack (#42370)
1 parent 0c5b080 commit 5f404ff

File tree

4 files changed

+1
-44
lines changed

4 files changed

+1
-44
lines changed

static/app/stores/useLegacyStore.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,6 @@ import {CommonStoreDefinition} from './types';
55

66
interface LegacyStoreShape extends Store, CommonStoreDefinition<any> {}
77

8-
/**
9-
* This wrapper exists because we have many old-style enzyme tests that trigger
10-
* updates to stores without being wrapped in act.
11-
*
12-
* Wrting tests with React Testing Library typically circumvents the need for
13-
* this. See [0].
14-
*
15-
* [0]: https://javascript.plainenglish.io/you-probably-dont-need-act-in-your-react-tests-2a0bcd2ad65c
16-
*/
17-
window._legacyStoreHookUpdate = update => update();
18-
198
/**
209
* Returns the state of a reflux store. Automatically unsubscribes when destroyed
2110
*
@@ -29,7 +18,7 @@ export function useLegacyStore<T extends LegacyStoreShape>(
2918
const [state, setState] = useState(store.getState());
3019

3120
// Not all stores emit the new state, call get on change
32-
const callback = () => window._legacyStoreHookUpdate(() => setState(store.getState()));
21+
const callback = () => setState(store.getState());
3322

3423
// If we setup the listener in useEffect, there is a small race condition
3524
// where the store may emit an event before we're listening (since useEffect

static/app/types/system.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,6 @@ declare global {
7373
* Assets public location
7474
*/
7575
__sentryGlobalStaticPrefix: string;
76-
/**
77-
* This is used for testing purposes as an interem while we translate tests
78-
* to React Testing Library.
79-
*
80-
* See the useLegacyStore hook for more unformation about this.
81-
*/
82-
_legacyStoreHookUpdate: (update: () => void) => void;
8376
// typing currently used for demo add on
8477
// TODO: improve typing
8578
SentryApp?: {

static/app/views/performance/trends/index.spec.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ function initializeTrendsData(
182182

183183
describe('Performance > Trends', function () {
184184
let trendsStatsMock;
185-
// const originalHook = window._legacyStoreHookUpdate;
186185
beforeEach(function () {
187186
browserHistory.push = jest.fn();
188187
MockApiClient.addMockResponse({

tests/js/sentry-test/enzyme.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import {cache} from '@emotion/css'; // eslint-disable-line @emotion/no-vanilla
22
import {CacheProvider, ThemeProvider} from '@emotion/react';
33
import {mount, shallow as enzymeShallow} from 'enzyme'; // eslint-disable-line no-restricted-imports
44

5-
import {act} from 'sentry-test/reactTestingLibrary';
6-
75
import {lightTheme} from 'sentry/utils/theme';
86

97
/**
@@ -33,25 +31,3 @@ export function mountWithTheme(tree, opts = {}) {
3331
* please avoid using `sentry-test/enzyme/shallow` and use `sentry-test/reactTestingLibrary/render` instead.
3432
*/
3533
export const shallow = enzymeShallow;
36-
37-
/**
38-
* @deprecated
39-
* Force the useLegacyStore setState updates to be wrapped in act.
40-
*
41-
* This is useful for old-style enzyme tests where enzyme does not correctly
42-
* wrap things in `act()` for you.
43-
*
44-
* Do NOT use this in RTL tests, as setState's triggered by store updates
45-
* should be captured with RTL style tests.
46-
*/
47-
export function enforceActOnUseLegacyStoreHook() {
48-
const originalHook = window._legacyStoreHookUpdate;
49-
50-
beforeEach(() => {
51-
window._legacyStoreHookUpdate = update => act(update);
52-
});
53-
54-
afterEach(() => {
55-
window._legacyStoreHookUpdate = originalHook;
56-
});
57-
}

0 commit comments

Comments
 (0)