I’m running a Gatsby website that’s deployed on Netlify, and I’m running into an issue where opening the website in Incognito mode triggers a file download instead of rendering the website. Strangely, the website works as expected in a normal browsing session, and I haven’t made any recent updates to the Gatsby site.
Has anyone else experienced this issue or have any suggestions for how I might troubleshoot it?
@zamson It always triggers a download for me, regardless of it being a normal or incognito window.
So it may be that you currently have a cached response when not in incognito, or that the request is being handled by a function that is checking cookies (which wouldn’t be there in an incognito session).
Thanks for checking. I do have a Netlify function for checking the visitor country cookie but it has not been a problem in the past. Will try to remove it and see if the problem persists.
// netlify/edge-functions/country.tsx
import type { Context } from "https://edge.netlify.com";
export default async (request: Request, context: Context) => {
// Set a cookie
if (!context.cookies.get('country')) {
context.cookies.set({
name: "country",
value: context.geo.country?.code || '',
path: '/',
sameSite: 'None',
secure: true
});
}
};
I removed the edge function and now the website is rendering properly. It was working fine before. The function was simple - it checked and set the country cookie based on Netlify’s geo-location features.
Will have to revise my code, something might have changed on Netlify’s side
My edge function was missing a return function. I’m not sure why this was needed, some examples on the netlify edge github does not have a return functions and I did not have one before either.
Just returned a rewrite to the request URL and now the page loads again instead of downloading a file. What’s the best practice here?
Here is my working code:
If I remove the return statement, the website will trigger a download.