Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from gatsbyjs:master #486

Merged
merged 4 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 39 additions & 12 deletions docs/docs/debugging-html-builds.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
title: Debugging HTML Builds
---

Errors while building static HTML files generally happen for one of the following reasons:

1. Some of your code references "browser globals" like `window` or `document`. If
this is your problem you should see an error above like "window is not
defined". To fix this, find the offending code and either a) check before
calling the code if window is defined so the code doesn't run while Gatsby is
building (see code sample below) or b) if the code is in the render function
of a React.js component, move that code into a [`componentDidMount` lifecycle](https://reactjs.org/docs/react-component.html#componentdidmount) or into a [`useEffect` hook](https://reactjs.org/docs/hooks-reference.html#useeffect), which
Errors while building static HTML files (The build-time React SSR process) generally happen for one of the following reasons:

1. Some of your code references "browser globals" like `window` or `document`
that aren't available in Node.js. If this is your problem you should see an
error above like "window is not defined". To fix this, find the offending
code and either a) check before calling the code if window is defined so the
code doesn't run while Gatsby is building (see code sample below) or b) if
the code is in the render function of a React.js component, move that code
into a [`componentDidMount`
lifecycle](https://reactjs.org/docs/react-component.html#componentdidmount)
or into a [`useEffect`
hook](https://reactjs.org/docs/hooks-reference.html#useeffect), which
ensures the code doesn't run unless it's in the browser.

2. Check that each of your JS files listed in your `pages` directory (and any
Expand All @@ -22,18 +26,41 @@ Errors while building static HTML files generally happen for one of the followin
is stricter than v3](/docs/reference/release-notes/migrating-from-v1-to-v2/#convert-to-either-pure-commonjs-or-pure-es6).
The solution is to only use `import` and this also extends to `gatsby-ssr` and `gatsby-browser` files.

4. Your app is not correctly [hydrated](https://reactjs.org/docs/react-dom.html), which results in gatsby develop and gatsby
build being inconsistent. It's possible that a change in a file like `gatsby-ssr` or `gatsby-browser` has a structure that is
not reflected in the other file, meaning that there is a mismatch between client and server output.
4. Your app doesn't correctly
[hydrate](https://reactjs.org/docs/react-dom.html) in the client, which
results in gatsby develop and gatsby build being inconsistent. It's possible
that a change in a file like `gatsby-ssr` or `gatsby-browser` has
a structure that is not reflected in the other file, meaning that there is
a mismatch between client and server output.

5. Some other reason :-) #1 is the most common reason building static files
fail. If it's another reason, you have to be a bit more creative in figuring
out the problem.

## How to check if `window` is defined

When referencing `window` in a React component.

```jsx
import * as React from "react"

// Check if window is defined (so if in the browser or in node.js).
const isBrowser = typeof window !== "undefined"

export default function MyComponent() {
let loggedIn = false
if (isBrowser) {
window.localstorage.getItem("isLoggedIn") === "true"
}

return <div>Am I logged in? {loggedIn}</div>
}
```
When requiring a module:
```javascript
// Requiring function causes error during builds
// Requiring a function causes an error during builds
// as the code tries to reference window
const module = require("module") // Error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ The following errors are related to styles in your site, using CSS, preprocessor

### Inconsistent CSS styles between develop and build using styled-components or emotion

_NOTE: We're in process of adding SSR support to the develop server. To use it now, enable the `DEV_SSR` flag in your gatsby-config.js — https://github.com/gatsbyjs/gatsby/discussions/28138_

A common problem that trips up users that install and begin to use styled-components or emotion is not including the related plugin in the config. Because `gatsby develop` doesn't run server-side rendering, the build may look different if the plugin is not included to tell Gatsby to server-side render the styles for the CSS-in-JS solution being used.

Adding `gatsby-plugin-styled-components` (in the case of styled-components) or `gatsby-plugin-emotion` (in the case of emotion) to `gatsby-config.js` will inform Gatsby to process the styles server-side so they display correctly in the final build.
Expand Down
4 changes: 4 additions & 0 deletions packages/babel-plugin-remove-graphql-queries/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [3.3.0-next.1](https://github.com/gatsbyjs/gatsby/compare/babel-plugin-remove-graphql-queries@[email protected]) (2021-04-07)

**Note:** Version bump only for package babel-plugin-remove-graphql-queries

# [3.3.0-next.0](https://github.com/gatsbyjs/gatsby/compare/babel-plugin-remove-graphql-queries@[email protected]) (2021-03-25)

**Note:** Version bump only for package babel-plugin-remove-graphql-queries
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-plugin-remove-graphql-queries/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-plugin-remove-graphql-queries",
"version": "3.3.0-next.0",
"version": "3.3.0-next.1",
"author": "Jason Quense <[email protected]>",
"repository": {
"type": "git",
Expand All @@ -11,9 +11,9 @@
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"babel-preset-gatsby-package": "^1.3.0-next.0",
"babel-preset-gatsby-package": "^1.3.0-next.1",
"cross-env": "^7.0.3",
"gatsby-core-utils": "^2.3.0-next.0"
"gatsby-core-utils": "^2.3.0-next.1"
},
"peerDependencies": {
"@babel/core": "^7.0.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/babel-preset-gatsby-package/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [1.3.0-next.1](https://github.com/gatsbyjs/gatsby/compare/babel-preset-gatsby-package@[email protected]) (2021-04-07)

### Bug Fixes

- **deps:** update minor and patch for babel-preset-gatsby-package ([#29852](https://github.com/gatsbyjs/gatsby/issues/29852)) ([5fd8f33](https://github.com/gatsbyjs/gatsby/commit/5fd8f33371a699578e5ffbd39be3ccd9e2c438f6))

# [1.3.0-next.0](https://github.com/gatsbyjs/gatsby/compare/babel-preset-gatsby-package@[email protected]) (2021-03-25)

**Note:** Version bump only for package babel-preset-gatsby-package
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-preset-gatsby-package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-preset-gatsby-package",
"version": "1.3.0-next.0",
"version": "1.3.0-next.1",
"author": "Philipp Spiess <[email protected]>",
"repository": {
"type": "git",
Expand Down
4 changes: 4 additions & 0 deletions packages/babel-preset-gatsby/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [1.3.0-next.2](https://github.com/gatsbyjs/gatsby/compare/[email protected]@1.3.0-next.2) (2021-04-07)

**Note:** Version bump only for package babel-preset-gatsby

# [1.3.0-next.1](https://github.com/gatsbyjs/gatsby/compare/[email protected]@1.3.0-next.1) (2021-03-30)

**Note:** Version bump only for package babel-preset-gatsby
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-preset-gatsby/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-preset-gatsby",
"version": "1.3.0-next.1",
"version": "1.3.0-next.2",
"author": "Philipp Spiess <[email protected]>",
"repository": {
"type": "git",
Expand All @@ -22,7 +22,7 @@
"babel-plugin-dynamic-import-node": "^2.3.3",
"babel-plugin-macros": "^2.8.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"gatsby-core-utils": "^2.3.0-next.0",
"gatsby-core-utils": "^2.3.0-next.1",
"gatsby-legacy-polyfills": "^1.3.0-next.1"
},
"peerDependencies": {
Expand All @@ -38,7 +38,7 @@
},
"devDependencies": {
"@babel/cli": "^7.12.1",
"babel-preset-gatsby-package": "^1.3.0-next.0",
"babel-preset-gatsby-package": "^1.3.0-next.1",
"cross-env": "^7.0.3",
"slash": "^3.0.0"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/create-gatsby/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [1.3.0-next.1](https://github.com/gatsbyjs/gatsby/compare/[email protected]@1.3.0-next.1) (2021-04-07)

**Note:** Version bump only for package create-gatsby

# [1.3.0-next.0](https://github.com/gatsbyjs/gatsby/compare/[email protected]@1.3.0-next.0) (2021-03-25)

**Note:** Version bump only for package create-gatsby
Expand Down
4 changes: 2 additions & 2 deletions packages/create-gatsby/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-gatsby",
"version": "1.3.0-next.0",
"version": "1.3.0-next.1",
"main": "lib/index.js",
"bin": "cli.js",
"license": "MIT",
Expand All @@ -27,7 +27,7 @@
"eslint": "^7.18.0",
"execa": "^4.1.0",
"fs-extra": "^9.0.1",
"gatsby-plugin-utils": "^1.3.0-next.0",
"gatsby-plugin-utils": "^1.3.0-next.1",
"joi": "^17.2.1",
"microbundle": "^0.13.0",
"node-fetch": "^2.6.1",
Expand Down
4 changes: 4 additions & 0 deletions packages/gatsby-admin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.13.0-next.2](https://github.com/gatsbyjs/gatsby/compare/[email protected]@0.13.0-next.2) (2021-04-07)

**Note:** Version bump only for package gatsby-admin

# [0.13.0-next.1](https://github.com/gatsbyjs/gatsby/compare/[email protected]@0.13.0-next.1) (2021-03-30)

**Note:** Version bump only for package gatsby-admin
Expand Down
8 changes: 4 additions & 4 deletions packages/gatsby-admin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatsby-admin",
"version": "0.13.0-next.1",
"version": "0.13.0-next.2",
"main": "index.js",
"author": "Max Stoiber",
"license": "MIT",
Expand All @@ -20,11 +20,11 @@
"@typescript-eslint/parser": "^4.14.2",
"csstype": "^2.6.14",
"formik": "^2.2.6",
"gatsby": "^3.3.0-next.1",
"gatsby": "^3.3.0-next.2",
"gatsby-interface": "^0.0.244",
"gatsby-plugin-typescript": "^3.3.0-next.0",
"gatsby-plugin-typescript": "^3.3.0-next.1",
"gatsby-plugin-webfonts": "^1.1.4",
"gatsby-source-graphql": "^3.3.0-next.0",
"gatsby-source-graphql": "^3.3.0-next.1",
"lodash-es": "^4.17.21",
"ncp": "^2.0.0",
"nodemon": "^2.0.7",
Expand Down
7 changes: 7 additions & 0 deletions packages/gatsby-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [3.3.0-next.1](https://github.com/gatsbyjs/gatsby/compare/[email protected]@3.3.0-next.1) (2021-04-07)

### Bug Fixes

- **docs:** edit copy for gatsby cli docs ([#30692](https://github.com/gatsbyjs/gatsby/issues/30692)) ([30789d9](https://github.com/gatsbyjs/gatsby/commit/30789d95e44d7abd74a717a765abc357bd259668))
- **gatsby-cli:** Update docs links in error-map ([#30493](https://github.com/gatsbyjs/gatsby/issues/30493)) ([a777367](https://github.com/gatsbyjs/gatsby/commit/a7773678cd5c8e492e047193b20451eeb1ade541))

# [3.3.0-next.0](https://github.com/gatsbyjs/gatsby/compare/[email protected]@3.3.0-next.0) (2021-03-25)

### Bug Fixes
Expand Down
12 changes: 6 additions & 6 deletions packages/gatsby-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gatsby-cli",
"description": "Gatsby command-line interface for creating new sites and running Gatsby commands",
"version": "3.3.0-next.0",
"version": "3.3.0-next.1",
"author": "Kyle Mathews <[email protected]>",
"bin": {
"gatsby": "cli.js"
Expand All @@ -18,14 +18,14 @@
"common-tags": "^1.8.0",
"configstore": "^5.0.1",
"convert-hrtime": "^3.0.0",
"create-gatsby": "^1.3.0-next.0",
"create-gatsby": "^1.3.0-next.1",
"envinfo": "^7.7.3",
"execa": "^3.4.0",
"fs-exists-cached": "^1.0.0",
"fs-extra": "^8.1.0",
"gatsby-core-utils": "^2.3.0-next.0",
"gatsby-recipes": "^0.14.0-next.0",
"gatsby-telemetry": "^2.3.0-next.0",
"gatsby-core-utils": "^2.3.0-next.1",
"gatsby-recipes": "^0.14.0-next.1",
"gatsby-telemetry": "^2.3.0-next.1",
"hosted-git-info": "^3.0.6",
"is-valid-path": "^0.1.1",
"joi": "^17.4.0",
Expand Down Expand Up @@ -59,7 +59,7 @@
"@rollup/plugin-replace": "^2.3.3",
"@types/hosted-git-info": "^3.0.1",
"@types/yargs": "^15.0.8",
"babel-preset-gatsby-package": "^1.3.0-next.0",
"babel-preset-gatsby-package": "^1.3.0-next.1",
"cross-env": "^7.0.3",
"ink": "^3.0.8",
"ink-spinner": "^4.0.1",
Expand Down
4 changes: 4 additions & 0 deletions packages/gatsby-codemods/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [2.3.0-next.1](https://github.com/gatsbyjs/gatsby/compare/[email protected]@2.3.0-next.1) (2021-04-07)

**Note:** Version bump only for package gatsby-codemods

# [2.3.0-next.0](https://github.com/gatsbyjs/gatsby/compare/[email protected]@2.3.0-next.0) (2021-03-25)

**Note:** Version bump only for package gatsby-codemods
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-codemods/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatsby-codemods",
"version": "2.3.0-next.0",
"version": "2.3.0-next.1",
"description": "A collection of codemod scripts for use with JSCodeshift that help migrate to newer versions of Gatsby.",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -36,7 +36,7 @@
},
"devDependencies": {
"@babel/cli": "^7.12.1",
"babel-preset-gatsby-package": "^1.3.0-next.0",
"babel-preset-gatsby-package": "^1.3.0-next.1",
"cross-env": "^7.0.3"
},
"engines": {
Expand Down
4 changes: 4 additions & 0 deletions packages/gatsby-core-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [2.3.0-next.1](https://github.com/gatsbyjs/gatsby/compare/[email protected]@2.3.0-next.1) (2021-04-07)

**Note:** Version bump only for package gatsby-core-utils

# [2.3.0-next.0](https://github.com/gatsbyjs/gatsby/compare/[email protected]@2.3.0-next.0) (2021-03-25)

**Note:** Version bump only for package gatsby-core-utils
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-core-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatsby-core-utils",
"version": "2.3.0-next.0",
"version": "2.3.0-next.1",
"description": "A collection of gatsby utils used in different gatsby packages",
"keywords": [
"gatsby",
Expand Down Expand Up @@ -42,7 +42,7 @@
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@types/ci-info": "2.0.0",
"babel-preset-gatsby-package": "^1.3.0-next.0",
"babel-preset-gatsby-package": "^1.3.0-next.1",
"cross-env": "^7.0.3",
"typescript": "^4.1.5"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/gatsby-cypress/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [1.3.0-next.1](https://github.com/gatsbyjs/gatsby/compare/[email protected]@1.3.0-next.1) (2021-04-07)

**Note:** Version bump only for package gatsby-cypress

# [1.3.0-next.0](https://github.com/gatsbyjs/gatsby/compare/[email protected]@1.3.0-next.0) (2021-03-25)

**Note:** Version bump only for package gatsby-cypress
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-cypress/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatsby-cypress",
"version": "1.3.0-next.0",
"version": "1.3.0-next.1",
"description": "Cypress tools for Gatsby projects",
"main": "index.js",
"repository": {
Expand All @@ -20,7 +20,7 @@
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"babel-preset-gatsby-package": "^1.3.0-next.0",
"babel-preset-gatsby-package": "^1.3.0-next.1",
"cross-env": "^7.0.3"
},
"keywords": [
Expand Down
6 changes: 6 additions & 0 deletions packages/gatsby-dev-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [3.3.0-next.1](https://github.com/gatsbyjs/gatsby/compare/[email protected]@3.3.0-next.1) (2021-04-07)

### Bug Fixes

- **deps:** update minor and patch for gatsby-dev-cli ([#29174](https://github.com/gatsbyjs/gatsby/issues/29174)) ([4f8ae3c](https://github.com/gatsbyjs/gatsby/commit/4f8ae3c1087f36619a8c6fecc0e2cc0187b02930))

# [3.3.0-next.0](https://github.com/gatsbyjs/gatsby/compare/[email protected]@3.3.0-next.0) (2021-03-25)

**Note:** Version bump only for package gatsby-dev-cli
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-dev-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gatsby-dev-cli",
"description": "CLI helpers for contributors working on Gatsby",
"version": "3.3.0-next.0",
"version": "3.3.0-next.1",
"author": "Kyle Mathews <[email protected]>",
"bin": {
"gatsby-dev": "./dist/index.js"
Expand All @@ -27,7 +27,7 @@
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"babel-preset-gatsby-package": "^1.3.0-next.0",
"babel-preset-gatsby-package": "^1.3.0-next.1",
"cross-env": "^7.0.3"
},
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-dev-cli#readme",
Expand Down
Loading