Skip to content

Commit

Permalink
Ingore react-invalid-hook-call on SSR
Browse files Browse the repository at this point in the history
The plain Component(props) doesn't support hooks on
ssr, so the prepare method will crash if a component
use hooks. This doesn't matter as long as we don't use hooks
before using prepare(). THen the warning can be ignored.
  • Loading branch information
odinuge committed May 13, 2019
1 parent 5a2ef2f commit 9b07a08
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion server/ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class TimeoutError {
this.error = new Error(msg);
}
}
const isTimeoutError = (error: Error) => error instanceof TimeoutError;
const isReactHooksError = (error: Object) =>
typeof error === 'object' &&
error.name === 'Invariant Violation' &&
error.stack.includes('https://fb.me/react-invalid-hook-call');

const prepareWithTimeout = app =>
Promise.race([
Expand Down Expand Up @@ -108,10 +113,13 @@ const createServerSideRenderer = (
.then(
() => respond(),
error => {
if (error instanceof TimeoutError) {
if (isTimeoutError(error)) {
reportError(error.error);
return render();
}
if (isReactHooksError(error)) {
return respond();
}
reportError(error);
respond();
}
Expand Down

0 comments on commit 9b07a08

Please sign in to comment.