Skip to content

Commit

Permalink
fix(gatsby): render QoD overlay in its own root element to avoid hydr…
Browse files Browse the repository at this point in the history
…ation issues
  • Loading branch information
KyleAMathews committed Feb 24, 2021
1 parent 662fe41 commit 203220e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 15 additions & 0 deletions packages/gatsby/cache-dir/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import emitter from "./emitter"
import { apiRunner, apiRunnerAsync } from "./api-runner-browser"
import { setLoader, publicLoader } from "./loader"
import { Indicator } from "./loading-indicator/indicator"
import { LoadingIndicatorEventHandler } from "./loading-indicator"
import DevLoader from "./dev-loader"
import syncRequires from "$virtual/sync-requires"
// Generated during bootstrap
Expand Down Expand Up @@ -164,6 +165,20 @@ apiRunnerAsync(`onClientEntry`).then(() => {

renderer(<Root />, rootElement, () => {
apiRunner(`onInitialClientRender`)

// Render query on demand overlay
if (process.env.GATSBY_QUERY_ON_DEMAND_LOADING_INDICATOR) {
const indicatorMountElement = document.createElement(`div`)
indicatorMountElement.setAttribute(
`id`,
`query-on-demand-indicator-element`
)
document.body.append(indicatorMountElement)
ReactDOM.render(
<LoadingIndicatorEventHandler />,
indicatorMountElement
)
}
})
})
})
Expand Down
5 changes: 0 additions & 5 deletions packages/gatsby/cache-dir/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import EnsureResources from "./ensure-resources"
import FastRefreshOverlay from "./fast-refresh-overlay"

import { reportError, clearError } from "./error-overlay-handler"
import { LoadingIndicatorEventHandler } from "./loading-indicator"

// TODO: Remove entire block when we make fast-refresh the default
// In fast-refresh, this logic is all moved into the `error-overlay-handler`
Expand Down Expand Up @@ -148,9 +147,5 @@ const ConditionalFastRefreshOverlay = ({ children }) => {
export default () => (
<ConditionalFastRefreshOverlay>
<StaticQueryStore>{WrappedRoot}</StaticQueryStore>
{process.env.GATSBY_EXPERIMENTAL_QUERY_ON_DEMAND &&
process.env.GATSBY_QUERY_ON_DEMAND_LOADING_INDICATOR === `true` && (
<LoadingIndicatorEventHandler />
)}
</ConditionalFastRefreshOverlay>
)

0 comments on commit 203220e

Please sign in to comment.