Skip to content

Commit ff68a85

Browse files
committed
remove validation effect and related tests
1 parent 0f8a352 commit ff68a85

2 files changed

Lines changed: 0 additions & 129 deletions

File tree

lib/useOnyx.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import usePrevious from './usePrevious';
1111
import decorateWithMetrics from './metrics';
1212
import onyxSnapshotCache from './OnyxSnapshotCache';
1313
import useLiveRef from './useLiveRef';
14-
import * as Logger from './Logger';
1514

1615
type UseOnyxSelector<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>> = (data: OnyxValue<TKey> | undefined) => TReturnValue;
1716

@@ -143,29 +142,6 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
143142

144143
useEffect(() => () => onyxSnapshotCache.deregisterConsumer(key, cacheKey), [key, cacheKey]);
145144

146-
useEffect(() => {
147-
if (previousKey === key) {
148-
return;
149-
}
150-
151-
try {
152-
const previousCollectionKey = OnyxUtils.splitCollectionMemberKey(previousKey)[0];
153-
const collectionKey = OnyxUtils.splitCollectionMemberKey(key)[0];
154-
155-
if (OnyxUtils.isCollectionMemberKey(previousCollectionKey, previousKey) && OnyxUtils.isCollectionMemberKey(collectionKey, key) && previousCollectionKey === collectionKey) {
156-
return;
157-
}
158-
} catch (e) {
159-
throw new Error(
160-
`'${previousKey}' key can't be changed to '${key}'. useOnyx() only supports dynamic keys if they are both collection member keys from the same collection e.g. from 'collection_id1' to 'collection_id2'.`,
161-
);
162-
}
163-
164-
if (process.env.NODE_ENV === 'development') {
165-
Logger.logAlert(`useOnyx: key changed from '${previousKey}' to '${key}' across collections.`);
166-
}
167-
}, [previousKey, key]);
168-
169145
// Track previous dependencies to prevent infinite loops
170146
const previousDependenciesRef = useRef<DependencyList>([]);
171147

tests/unit/useOnyxTest.ts

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -35,111 +35,6 @@ beforeEach(async () => {
3535
});
3636

3737
describe('useOnyx', () => {
38-
describe('dynamic key', () => {
39-
const error = (key1: string, key2: string) =>
40-
`'${key1}' key can't be changed to '${key2}'. useOnyx() only supports dynamic keys if they are both collection member keys from the same collection e.g. from 'collection_id1' to 'collection_id2'.`;
41-
42-
beforeEach(() => {
43-
jest.spyOn(console, 'error').mockImplementation(jest.fn);
44-
});
45-
46-
afterEach(() => {
47-
(console.error as unknown as jest.SpyInstance<void, Parameters<typeof console.error>>).mockRestore();
48-
});
49-
50-
it('should throw an error when changing from a non-collection key to another one', async () => {
51-
const {rerender} = renderHook((key: string) => useOnyx(key), {initialProps: ONYXKEYS.TEST_KEY});
52-
53-
try {
54-
await act(async () => {
55-
rerender(ONYXKEYS.TEST_KEY_2);
56-
});
57-
58-
fail('Expected to throw an error.');
59-
} catch (e) {
60-
expect((e as Error).message).toBe(error(ONYXKEYS.TEST_KEY, ONYXKEYS.TEST_KEY_2));
61-
}
62-
});
63-
64-
it('should throw an error when changing from a collection key to another one', async () => {
65-
const {rerender} = renderHook((key: string) => useOnyx(key), {initialProps: ONYXKEYS.COLLECTION.TEST_KEY});
66-
67-
try {
68-
await act(async () => {
69-
rerender(ONYXKEYS.COLLECTION.TEST_KEY_2);
70-
});
71-
72-
fail('Expected to throw an error.');
73-
} catch (e) {
74-
expect((e as Error).message).toBe(error(ONYXKEYS.COLLECTION.TEST_KEY, ONYXKEYS.COLLECTION.TEST_KEY_2));
75-
}
76-
});
77-
78-
it('should throw an error when changing from a collection key to a collectiom member key', async () => {
79-
const {rerender} = renderHook((key: string) => useOnyx(key), {initialProps: ONYXKEYS.COLLECTION.TEST_KEY});
80-
81-
try {
82-
await act(async () => {
83-
rerender(`${ONYXKEYS.COLLECTION.TEST_KEY}1`);
84-
});
85-
86-
fail('Expected to throw an error.');
87-
} catch (e) {
88-
expect((e as Error).message).toBe(error(ONYXKEYS.COLLECTION.TEST_KEY, `${ONYXKEYS.COLLECTION.TEST_KEY}1`));
89-
}
90-
});
91-
92-
it('should not throw any errors when changing from a collection member key to another one', async () => {
93-
const {rerender} = renderHook((key: string) => useOnyx(key), {initialProps: `${ONYXKEYS.COLLECTION.TEST_KEY}1` as string});
94-
95-
try {
96-
await act(async () => {
97-
rerender(`${ONYXKEYS.COLLECTION.TEST_KEY}2`);
98-
});
99-
} catch (e) {
100-
fail("Expected to don't throw any errors.");
101-
}
102-
});
103-
104-
it('should not throw an error when changing from a non-collection key to another one if allowDynamicKey is true', async () => {
105-
const {rerender} = renderHook((key: string) => useOnyx(key, {allowDynamicKey: true}), {initialProps: ONYXKEYS.TEST_KEY});
106-
107-
try {
108-
await act(async () => {
109-
rerender(ONYXKEYS.TEST_KEY_2);
110-
});
111-
} catch (e) {
112-
fail("Expected to don't throw any errors.");
113-
}
114-
});
115-
116-
it('should throw an error when changing from a non-collection key to another one if allowDynamicKey is false', async () => {
117-
const {rerender} = renderHook((key: string) => useOnyx(key, {allowDynamicKey: false}), {initialProps: ONYXKEYS.TEST_KEY});
118-
119-
try {
120-
await act(async () => {
121-
rerender(ONYXKEYS.TEST_KEY_2);
122-
});
123-
124-
fail('Expected to throw an error.');
125-
} catch (e) {
126-
expect((e as Error).message).toBe(error(ONYXKEYS.TEST_KEY, ONYXKEYS.TEST_KEY_2));
127-
}
128-
});
129-
130-
it('should not throw an error when changing from a collection member key to another one if allowDynamicKey is true', async () => {
131-
const {rerender} = renderHook((key: string) => useOnyx(key, {allowDynamicKey: true}), {initialProps: `${ONYXKEYS.COLLECTION.TEST_KEY}` as string});
132-
133-
try {
134-
await act(async () => {
135-
rerender(`${ONYXKEYS.COLLECTION.TEST_KEY_2}`);
136-
});
137-
} catch (e) {
138-
fail("Expected to don't throw any errors.");
139-
}
140-
});
141-
});
142-
14338
describe('misc', () => {
14439
it('should initially return loading state while loading non-existent key, and then return `undefined` and loaded state', async () => {
14540
const {result} = renderHook(() => useOnyx(ONYXKEYS.TEST_KEY));

0 commit comments

Comments
 (0)