-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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 Adapters causes regressions & issues with headers & redirects for NETLIFY builds on >=5.12.0 #38542
Comments
I'm getting |
Found a couple more issues...
|
After upgrading one of our sites to 5.12.0: (time period is between "clean" builds, about 26 days)
Yikes! Not sure where to go with this other than to downgrade... |
Ever since Netlify started automatically installing The page is created in
Can resolve this by renaming the However, both of these solutions are quite hacky and not ideal in long run |
We were hit by this as well and only found this in production when we discovered that all URLs which supported clientside routes were delivered with 404 status codes instead of 200 when accessed via URL. Simple repro with latest versions of gatsby (5.13.1) and gatsby-adapter-netlify (1.1.1): The settings page (which is not even a client-only page) and all client-only pages below it respond with a 404 status code when directly accessed. Workaround: Downgrade to gatsby 5.11.x and gatsby-plugin netlify: The settings pages of the deploy preview are delivered with a 200 status code, as they should be. |
Adding our tale and some some keywords in here to help others, we were seeing builds intermittently failing on Netlify with Gatsby 5.12. We had a JSON file imported in Clearing the Netlify build cache solved this temporarily, but it appears that downgrading to 5.11 has resolved it. I have no idea if it's related to this plugin, but can't find a more relevant place to leave this comment and am unsure how to reproduce in order to open a separate issue. |
Query on redirects are not honored -> https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-adapter-netlify/src/route-handler.ts#L9C4-L9C9
Expected (behavior on Gatsby <v5.12)
Current (behavior on Gatsby >=v5.12)
|
Hi, I'm also experiencing issues with the netlify adapter. The data for the website comes from mongoDB through the plugin. I configure the relationships between collections in exports.createSchemaCustomization = ({ actions }: any) => {
const { createTypes } = actions;
// id creation
const mongoIdTypeDefs = collections
.map(
(c) =>
`type mongodb${capitalizeFirstLetter(c)} implements Node {
_id: String @proxy(from: "mongodb_id")
}`
)
.join("\n");
createTypes(mongoIdTypeDefs);
const typeDefs1 = `
type mongodbActivities implements Node {
place: mongodbPlaces @link(by: "mongodb_id")
profiles: [mongodbProfiles] @link(by: "mongodb_id")
contacts: [mongodbContacts] @link(by: "mongodb_id")
}
type mongodbCounters implements Node {
catalog: mongodbCatalogs @link(by: "mongodb_id")
place: mongodbPlaces @link(by: "mongodb_id")
profiles: [mongodbProfiles] @link(by: "mongodb_id")
actions: [mongodbActions] @link(by:"subject.counter", from: "mongodb_id")
}
// ...
`;
createTypes(typeDefs1);
};
exports.createPages = async function ({ actions, graphql }: any) {
const { data: marketplacesQuery } = await graphql(`
query {
allMongodbCounters(filter: { type: { eq: "marketplace" } }) {
nodes {
_id
name
}
}
}
`);
marketplacesQuery.allMongodbCounters.nodes.forEach((node: any) => {
const _id = node._id;
const component = path.resolve(`./src/templates/marketplace.tsx`);
actions.createPage({
path: "/marketplace/" + _id,
component: component,
context: { id: _id },
});
}); |
Preliminary Checks
Description
The forced usage of Gatsby Adapters has caused several regressions and issues related to headers & redirects for builds running on NETLIFY. As of v5.12.0, Gatsby will detect that the build is running on NETLIFY and add the gatsby-adapter-netlify adapter to the build and remove the
gatsby-plugin-netlify
plugin without anystock
way to "opt-out" of the behavior.Unfortunately, the
gatsby-adapter-netlify
does not have feature parity withgatsby-plugin-netlify
and also contains a few bugs. The combination of these two things results in build output being different for anyone building on NETLIFY.A couple of references to bugs/issues already filed:
gatsby-adapter-netlify
not respecting"force"
option passed tocreateRedirect
#38541gatsby-adapter-netlify
not generating headers for redirects #38538After digging through the output and code some more, I believe this is a much broader set of issues than those two issues alone so creating this issue as an umbrella. If the preference is to have a single issue for each individual item identified, please just let me know.
The issues discovered are:
force
is not honored (needs to include!
)/
added to the beginning of them (Netlify supports domain redirects - example: domain alias to redirect to primary site).Conditions
on redirects are not honoredgatsby-plugin-netlify
are not available and therefore have no effect:Link
paths are not converted to their corresponding hashpathPrefix
&assetPrefix
gatsby-plugin-netlify
had some issues in this area as well).asset
routes even be passed through to the adapter in RoutesManifest when assetPrefix is an absolute URL?_headers
file size could become significantly large, especially on larger sites -gatsby-adapter-netlify
emits explicit headers for each route path as opposed to passing wildcards, etc. through to the adapter. This comes with three potential downsides:_redirects
&netlify.toml
is too large, it could fail the deploy. While it doesn't mention this for_headers
, the same is likely true (would require validation). In the repro, the file size of_headers
usinggatsby-plugin-netlify
is 2,408 bytes while the file size usinggatsby-adapter-netlify
is 59,515 bytes (using theextrapages
build which has ~105 pages), nearly a 25x increase.All of the above (and possibly some more I missed), will impact customers relying on any of these as soon as they build on Netlify with a version >= 5.12.0.
As mentioned here as it relates to builds breaking, 5.12.0 likely should have been a major version update as all of these are breaking changes and since most likely have a semver of
^5.x.x
, customers relying on any of these features/functionality will be impacted if building on NETLIFY.Most of the above issues are problems/missing functionality in the core Gatsby Adapter logic, not in the
gatsby-adapter-netlify
adapter itself. For example, when IRedirectRoute is created,force
is not passed through so the adapter doesn't receive the value even though there is code in the adapter to process it - same holds true for the conditions property. Additionally, createRedirect allows for any set of[key: string]: unknown
which aren't passed through (they wouldn't be used in this case but they should be passed through since createRedirect API and IRedirectRoute support it).I had created feature requests for the ability to disable adapters and add allPageHeaders & transformHeaders, however the more that I've run up against, after thinking it through, I believe these aren't features but regression defects given Adapters was a
minor
release version and not a major. At the very least, adding a way to disable adapters as soon as possible is likely warranted.Workarounds
In the meantime, for those that come across this, there are a few options to avoid the above issues:
static
directory and they will get copied over topublic
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.Note
For any anyone (especially Gatsby cloud customers moving over) moving to Netlify and planning on using
transformHeaders
ingatsby-plugin-netlify
(same existed ingatsby-plugin-gatsby-cloud
), note that there is a bug where the path parameter is not passed as expected. Assuming the PR I submitted gets merged, then workaround 1 or 2 will achieve the equivalent output as something likegatsby-plugin-gatsby-cloud
would have.I have created a full-set of repros that demonstrate three scenarios related to the output of headers & redirects - again, this only impacts builds on NETLIFY:
gatsby-plugin-netlify
is configuredNo Adapter
would generate for headers & redirectsheaders
config to replicate some of the functionality that is lost with Adapters compared togatsby-plugin-netlify
Each branch has the following files in root directory:
npm run build
- Standard sitenpm run build:pathprefix
- Includes a path prefixnpm run build:assetprefix
- Includes a path & asset prefixnpm run build:extrapages
- Standard site with 100 extra pagesI have manually adjusted these files from their original to align sort order some. The output between using an adapter & gatsby-plugin-netlify is quite different (e.g., plugin uses
/*
, adapter emits same headers for each path when/*
is used) but hoping this makes it a little more readable. You can review the PRs to see the differences between building with justgatsby-plugin-netlify
Reproduction Link
https://github.com/techfg/gatsby-adapter-issues
Steps to Reproduce
Run one of the four builds in all three branches and compare the output of
public/_headers
andpublic/_redirects
.Expected Result
The headers & redirects in a build that uses
gatsby-adapter-netlify
should be same as build usinggatsby-plugin-netlify
(or better in some cases like security improvements & issues with prefix paths).Actual Result
The headers & redirects are not identical resulting in different build output without any changes to code/config of the site due to Adapters not being an "opt-in" feature.
Environment
Config Flags
N/A
The text was updated successfully, but these errors were encountered: