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

gatsby-adapter-netlify not respecting "force" option passed to createRedirect #38541

Open
2 tasks done
dryan-FF opened this issue Sep 11, 2023 · 2 comments
Open
2 tasks done
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby

Comments

@dryan-FF
Copy link

Preliminary Checks

Description

The gatsby-adapter-netlify is not applying the force attribute as expected, according to the docs on Netlify and for Gatsby's createRedirects API. I also see that there is code which is meant to apply this attribute:

if (force) {
status = `${status}!`
}

Without the force attribute, we cannot complete some of our desired redirects. We also cannot re-write the default 200 status code for our /404 page to be an actual 404 status code, which we believe is more appropriate

The "Reproduction Link" below can be used to examine the resulting _redirects file, however in our Netlify site we are seeing the behavior we would expect from such a file

Reproduction Link

https://codesandbox.io/p/sandbox/gatsby-adapter-netlify-redirect-headers-missing-82qlk9?file=/public/_redirects:6,1

Steps to Reproduce

  1. Go to codesandbox.io site provided
  2. Examine the createRedirect call defined in gatsby-node.js, which has the option force: true set
  3. Examine the result in public/_redirects

Expected Result

With the force: true option set, the redirect should look like: /testpage /test-page 301! , as the force: true option should apply an ! to the status code and let Netlify know that the redirect should occur even if the fromPath defined already exists

Actual Result

the result in _redirects does not have the exclamation point, and so is not "forced"

Environment

[CODESANDBOX] Running command: npx gatsby info

  System:
    OS: Linux 6.1 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
    CPU: (2) x64 AMD EPYC
    Shell: Unknown
  Binaries:
    Node: 18.17.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.6.7 - /usr/local/bin/npm
  npmPackages:
    gatsby: ^5.8.1 => 5.12.4
    gatsby-adapter-netlify: ^1.0.0 => 1.0.0

Config Flags

No response

@dryan-FF dryan-FF added the type: bug An issue or pull request relating to a bug in Gatsby label Sep 11, 2023
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Sep 11, 2023
@dryan-FF
Copy link
Author

noticed this while reading this issue #38538 . thanks for reporting @techfg, and for the CodeSandbox i was able to fork for my issue!

@techfg
Copy link

techfg commented Sep 12, 2023

@dryan-FF -

Np on the sandbox, glad it helped! I actually found the force issue after posting #38538 and then a few other issues but took me a bit to collect all the info, create the repros and get an issue posted but appreciate you identifying the force and getting an issue created!

I just created #38542 as an umbrella issue since this seems to go much deeper. If you need a solution ASAP, you can look at the workarounds I mention there:

  1. Stay on a version of Gatsby < 5.12.0 - This is the simplest and recommended approach if any of the above would effect your site
  2. Implement the noop Adapter solution that I describe in the discussion
  3. Define your own redirects & headers via (_redirects/_headers) instead of relying on Gatsby adapter to generate. You can place these files in static directory and they will get copied over to public during the build. Gatsby adapter will merge in any changes it makes to these files for a combined output so you could define everything you need or just the redirects/rules that Gatsby adapter doesn't support properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

2 participants