Skip to content

Commit

Permalink
fix(gatsby): rehydration issue in Dev404Page with DEV_SSR (#30581)
Browse files Browse the repository at this point in the history
Co-authored-by: Lennart <lekoarts@gmail.com>
  • Loading branch information
kimbaudi and LekoArts committed May 3, 2021
1 parent 257de93 commit 5005588
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Dev404Page extends React.Component {
const initialPagePathSearchTerms = urlState.filter ? urlState.filter : ``

this.state = {
hasMounted: false,
showCustom404: false,
initPagePaths: pagePaths,
pagePathSearchTerms: initialPagePathSearchTerms,
Expand All @@ -32,6 +33,12 @@ class Dev404Page extends React.Component {
this.handleSearchTermChange = this.handleSearchTermChange.bind(this)
}

componentDidMount() {
this.setState({
hasMounted: true,
})
}

showCustom404() {
this.setState({ showCustom404: true })
}
Expand Down Expand Up @@ -78,6 +85,10 @@ class Dev404Page extends React.Component {
}

render() {
if (!this.state.hasMounted) {
return null
}

// Detect when the query returns the default function node that's added when functions
// are *not* enabled. That seems the simplest way to communicate whether
// functions are enabled or not to this page.
Expand Down

0 comments on commit 5005588

Please sign in to comment.