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

Redirect breaks server rendering #7718

Closed
m-allanson opened this issue Aug 29, 2018 · 0 comments · Fixed by #8130
Closed

Redirect breaks server rendering #7718

m-allanson opened this issue Aug 29, 2018 · 0 comments · Fixed by #8130
Labels
help wanted Issue with a clear description that the community can help with. status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. type: bug An issue or pull request relating to a bug in Gatsby

Comments

@m-allanson
Copy link
Contributor

Description

Gatsby does not handle @reach/router's <Redirect> component when server rendering, resulting in a build error on sites that use <Redirect>. The current workaround is to use the noThrow prop on the redirect.

The fix is to use @reach/router's isRedirect method to check errors in static-entry.js.

Importing isRedirect and replacing this block with something like:

  // If no one stepped up, we'll handle it.
  if (!bodyHtml) {
    try {
      bodyHtml = renderToString(bodyComponent)
    } catch (error) {
      // ignore @reach/router redirect errors
      if (!isRedirect(error)) throw error
    }
  }

Should fix the issue.

Steps to reproduce

See related PR for workaround: gatsbyjs/store.gatsbyjs.org#111

Expected result

The site should build

Actual result

The site build fails with errors.

Environment

  System:
    OS: macOS High Sierra 10.13.6
    CPU: x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 8.11.3 - ~/.nvm/versions/node/v8.11.3/bin/node
    Yarn: 1.9.4 - /usr/local/bin/yarn
    npm: 5.6.0 - ~/.nvm/versions/node/v8.11.3/bin/npm
  Browsers:
    Firefox: 61.0.2
    Safari: 11.1.2
  npmPackages:
    gatsby: ^2.0.0-beta.7 => 2.0.0-rc.0
    gatsby-image: ^2.0.0-beta.2 => 2.0.0-rc.0
    gatsby-plugin-emotion: ^2.0.0-beta.2 => 2.0.0-rc.0
    gatsby-plugin-react-helmet: ^3.0.0-beta.2 => 3.0.0-rc.0
    gatsby-plugin-sharp: ^2.0.0-beta.2 => 2.0.0-rc.0
    gatsby-source-filesystem: ^2.0.1-beta.3 => 2.0.1-rc.0
    gatsby-transformer-sharp: ^2.1.1-beta.3 => 2.1.1-rc.0
  npmGlobalPackages:
    gatsby-cli: 1.1.58
    gatsby-dev-cli: 2.0.0-alpha.80a21f04
@m-allanson m-allanson added type: bug An issue or pull request relating to a bug in Gatsby help wanted Issue with a clear description that the community can help with. status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. labels Aug 29, 2018
@gatsbot gatsbot bot added help wanted Issue with a clear description that the community can help with. type: bug An issue or pull request relating to a bug in Gatsby labels Aug 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issue with a clear description that the community can help with. status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant