Skip to content

Commit 50c390f

Browse files
authored
Merge pull request #1242 from GetStream/context-warnings
switch context error to console warnings
2 parents 8512fae + 551300b commit 50c390f

File tree

13 files changed

+40
-83
lines changed

13 files changed

+40
-83
lines changed

codecov.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ coverage:
33
project:
44
default:
55
target: 70% # the required coverage value
6-
threshold: 1% # the leniency in hitting the target
6+
threshold: 10% # the leniency in hitting the target
7+
patch:
8+
default:
9+
target: 70%
10+
threshold: 10%

examples/nextjs/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10733,10 +10733,10 @@ stream-browserify@^2.0.1:
1073310733
inherits "~2.0.1"
1073410734
readable-stream "^2.0.2"
1073510735

10736-
stream-chat-css@^1.0.15:
10737-
version "1.0.15"
10738-
resolved "https://registry.yarnpkg.com/stream-chat-css/-/stream-chat-css-1.0.15.tgz#dd22aca0c65d5a32fb50fb3ef17c8080669bdbc6"
10739-
integrity sha512-7fJq7HqB+6gUpsDdqPJJ7SvMoFzUCe37d7J8VWPYiUs3PWZHK2gs1PW28kQm8jVPL6PfZoX1ZwhgMMGOOsSo1w==
10736+
stream-chat-css@^1.0.17:
10737+
version "1.0.17"
10738+
resolved "https://registry.yarnpkg.com/stream-chat-css/-/stream-chat-css-1.0.17.tgz#aad79b5c8e6f62334305d73e8cffe8ad2ac46f0e"
10739+
integrity sha512-CgfqyWAqFa2QMBn3Srk4sBnMdjMhd/ufErplnGeYZFlzL/C1czRmr2MN/ZgxWwW5uLO7ArGyETRqslYZxFMN1Q==
1074010740

1074110741
"stream-chat-react@link:../..":
1074210742
version "0.0.0"

examples/typescript/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11115,10 +11115,10 @@ stream-browserify@^2.0.1:
1111511115
inherits "~2.0.1"
1111611116
readable-stream "^2.0.2"
1111711117

11118-
stream-chat-css@^1.0.15:
11119-
version "1.0.15"
11120-
resolved "https://registry.yarnpkg.com/stream-chat-css/-/stream-chat-css-1.0.15.tgz#dd22aca0c65d5a32fb50fb3ef17c8080669bdbc6"
11121-
integrity sha512-7fJq7HqB+6gUpsDdqPJJ7SvMoFzUCe37d7J8VWPYiUs3PWZHK2gs1PW28kQm8jVPL6PfZoX1ZwhgMMGOOsSo1w==
11118+
stream-chat-css@^1.0.17:
11119+
version "1.0.17"
11120+
resolved "https://registry.yarnpkg.com/stream-chat-css/-/stream-chat-css-1.0.17.tgz#aad79b5c8e6f62334305d73e8cffe8ad2ac46f0e"
11121+
integrity sha512-CgfqyWAqFa2QMBn3Srk4sBnMdjMhd/ufErplnGeYZFlzL/C1czRmr2MN/ZgxWwW5uLO7ArGyETRqslYZxFMN1Q==
1112211122

1112311123
"stream-chat-react@link:../..":
1112411124
version "0.0.0"

scripts/send-messages.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/context/ChannelActionContext.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,11 @@ export const useChannelActionContext = <
129129
const contextValue = useContext(ChannelActionContext);
130130

131131
if (!contextValue) {
132-
if (process.env.NODE_ENV === 'test') {
133-
return {} as ChannelActionContextValue<At, Ch, Co, Ev, Me, Re, Us>;
134-
}
135-
136-
throw new Error(
132+
console.warn(
137133
`The useChannelActionContext hook was called outside of the ChannelActionContext provider. Make sure this hook is called within a child of the Channel component. The errored call is located in the ${componentName} component.`,
138134
);
135+
136+
return {} as ChannelActionContextValue<At, Ch, Co, Ev, Me, Re, Us>;
139137
}
140138

141139
return (contextValue as unknown) as ChannelActionContextValue<At, Ch, Co, Ev, Me, Re, Us>;

src/context/ChannelStateContext.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,11 @@ export const useChannelStateContext = <
121121
const contextValue = useContext(ChannelStateContext);
122122

123123
if (!contextValue) {
124-
if (process.env.NODE_ENV === 'test') {
125-
return {} as ChannelStateContextValue<At, Ch, Co, Ev, Me, Re, Us>;
126-
}
127-
128-
throw new Error(
124+
console.warn(
129125
`The useChannelStateContext hook was called outside of the ChannelStateContext provider. Make sure this hook is called within a child of the Channel component. The errored call is located in the ${componentName} component.`,
130126
);
127+
128+
return {} as ChannelStateContextValue<At, Ch, Co, Ev, Me, Re, Us>;
131129
}
132130

133131
return (contextValue as unknown) as ChannelStateContextValue<At, Ch, Co, Ev, Me, Re, Us>;

src/context/ChatContext.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,11 @@ export const useChatContext = <
8989
const contextValue = useContext(ChatContext);
9090

9191
if (!contextValue) {
92-
if (process.env.NODE_ENV === 'test') {
93-
return {} as ChatContextValue<At, Ch, Co, Ev, Me, Re, Us>;
94-
}
95-
96-
throw new Error(
92+
console.warn(
9793
`The useChatContext hook was called outside of the ChatContext provider. Make sure this hook is called within a child of the Chat component. The errored call is located in the ${componentName} component.`,
9894
);
95+
96+
return {} as ChatContextValue<At, Ch, Co, Ev, Me, Re, Us>;
9997
}
10098

10199
return (contextValue as unknown) as ChatContextValue<At, Ch, Co, Ev, Me, Re, Us>;

src/context/ComponentContext.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,11 @@ export const useComponentContext = <
127127
const contextValue = useContext(ComponentContext);
128128

129129
if (!contextValue) {
130-
if (process.env.NODE_ENV === 'test') {
131-
return {} as ComponentContextValue<At, Ch, Co, Ev, Me, Re, Us, V>;
132-
}
133-
134-
throw new Error(
130+
console.warn(
135131
`The useComponentContext hook was called outside of the ComponentContext provider. Make sure this hook is called within a child of the Channel component. The errored call is located in the ${componentName} component.`,
136132
);
133+
134+
return {} as ComponentContextValue<At, Ch, Co, Ev, Me, Re, Us, V>;
137135
}
138136

139137
return contextValue as ComponentContextValue<At, Ch, Co, Ev, Me, Re, Us, V>;

src/context/EmojiContext.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ export const useEmojiContext = (componentName?: string) => {
9090
const contextValue = useContext(EmojiContext);
9191

9292
if (!contextValue) {
93-
if (process.env.NODE_ENV === 'test') return {} as Required<EmojiContextValue>;
94-
95-
throw new Error(
93+
console.warn(
9694
`The useEmojiContext hook was called outside of the EmojiContext provider. Make sure this hook is called within a child of the Channel component. The errored call is located in the ${componentName} component.`,
9795
);
96+
97+
return {} as Required<EmojiContextValue>;
9898
}
9999

100100
return contextValue as Required<EmojiContextValue>;

src/context/MessageContext.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,11 @@ export const useMessageContext = <
172172
const contextValue = useContext(MessageContext);
173173

174174
if (!contextValue) {
175-
if (process.env.NODE_ENV === 'test') {
176-
return {} as MessageContextValue<At, Ch, Co, Ev, Me, Re, Us>;
177-
}
178-
179-
throw new Error(
175+
console.warn(
180176
`The useMessageContext hook was called outside of the MessageContext provider. Make sure this hook is called within the Message's UI component. The errored call is located in the ${componentName} component.`,
181177
);
178+
179+
return {} as MessageContextValue<At, Ch, Co, Ev, Me, Re, Us>;
182180
}
183181

184182
return (contextValue as unknown) as MessageContextValue<At, Ch, Co, Ev, Me, Re, Us>;

0 commit comments

Comments
 (0)