Skip to content
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
13 changes: 12 additions & 1 deletion packages/webapp/__tests__/SquadPageStaticProps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe('squad page getServerSideProps seo', () => {
// SSR is always unauthenticated, so the API rejects every private squad with
// FORBIDDEN before we ever see `public`. This fallback used to ship no seo at
// all, which left private squads advertised as index,follow.
it.each([ApiError.Forbidden, ApiError.NotFound, ApiError.RateLimited])(
it.each([ApiError.Forbidden, ApiError.RateLimited])(
'marks the %s fallback as noindex and nofollow',
async (code) => {
mockRequest.mockRejectedValue({
Expand All @@ -170,4 +170,15 @@ describe('squad page getServerSideProps seo', () => {
});
},
);

it('returns a real 404 for a squad that does not exist', async () => {
mockRequest.mockRejectedValue({
response: { errors: [{ extensions: { code: ApiError.NotFound } }] },
});

const result = await runGssp();

expect(result).toEqual({ notFound: true });
expect(mockStaticFields).not.toHaveBeenCalled();
});
});
12 changes: 10 additions & 2 deletions packages/webapp/pages/squads/[handle]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,20 @@ export async function getServerSideProps({
const errors = Object.values(ApiError);
const errorCode = clientError?.response?.errors?.[0]?.extensions?.code;

// A squad that doesn't exist is a real 404, not a soft one, so crawlers
// and agents don't index or cite a page that isn't there.
if (errorCode === ApiError.NotFound) {
setCacheHeader();

return { notFound: true };
}

if (errors.includes(errorCode)) {
setCacheHeader();

// SSR always runs unauthenticated, so every private squad resolves as
// FORBIDDEN here. This branch also serves the soft-404/rate-limited
// cases, none of which should ever be advertised as indexable.
// FORBIDDEN here. This branch also serves the rate-limited and other
// API error cases, none of which should ever be advertised as indexable.
return {
props: { handle, seo: { ...noindexSeoProps } },
};
Expand Down
Loading