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 (#29692)

* fix(gatsby): render QoD overlay in its own root element to avoid hydration issues

* Update packages/gatsby/cache-dir/app.js

Co-authored-by: Ward Peeters <[email protected]>

* Update packages/gatsby/cache-dir/app.js

Co-authored-by: Ward Peeters <[email protected]>

* Fix linting

Co-authored-by: Ward Peeters <[email protected]>
  • Loading branch information
KyleAMathews and wardpeet authored Feb 23, 2021
1 parent 7319229 commit d3dd3e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
18 changes: 18 additions & 0 deletions packages/gatsby/cache-dir/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import DevLoader from "./dev-loader"
import asyncRequires from "$virtual/async-requires"
// Generated during bootstrap
import matchPaths from "$virtual/match-paths.json"
import { LoadingIndicatorEventHandler } from "./loading-indicator"

// ensure in develop we have at least some .css (even if it's empty).
// this is so there is no warning about not matching content-type when site doesn't include any regular css (for example when css-in-js is used)
Expand Down Expand Up @@ -168,6 +169,23 @@ apiRunnerAsync(`onClientEntry`).then(() => {

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

// Render query on demand overlay
if (
process.env.GATSBY_QUERY_ON_DEMAND_LOADING_INDICATOR &&
process.env.GATSBY_QUERY_ON_DEMAND_LOADING_INDICATOR === `true`
) {
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 @@ -12,7 +12,6 @@ import loader from "./loader"
import { PageQueryStore, StaticQueryStore } from "./query-result-store"
import EnsureResources from "./ensure-resources"
import FastRefreshOverlay from "./fast-refresh-overlay"
import { LoadingIndicatorEventHandler } from "./loading-indicator"

navigationInit()

Expand Down Expand Up @@ -116,9 +115,5 @@ const WrappedRoot = apiRunner(
export default () => (
<FastRefreshOverlay>
<StaticQueryStore>{WrappedRoot}</StaticQueryStore>
{process.env.GATSBY_EXPERIMENTAL_QUERY_ON_DEMAND &&
process.env.GATSBY_QUERY_ON_DEMAND_LOADING_INDICATOR === `true` && (
<LoadingIndicatorEventHandler />
)}
</FastRefreshOverlay>
)

0 comments on commit d3dd3e1

Please sign in to comment.