Skip to content

fix: Error (500) and Not Found (404) routing logic #15584

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

Merged
merged 13 commits into from
Jun 6, 2025
Merged

Conversation

wackerow
Copy link
Member

@wackerow wackerow commented Jun 1, 2025

Description

Fixes logic surrounding 500 error and 404 not-found handing.

  • Disabled dyanamicParams = false since that meant encountering an unknown path (a dynamic param) would immediately fallback to Next.js 404. Removing enables our own custom 404 handling with notFound()
  • Removed any chance of throwing error when getting metadata; wraps in try/catch, if error then "not found" metadata returned to allow routing by the page component.
  • Wraps the root level NotFoundPage in LocaleLayout to enable the English site layout with header and footer elements
  • Updates the error page with refresh button

Examples:

Related Issue

Currently all 404's and 500's result in Next.js pages

wackerow added 6 commits June 1, 2025 13:52
checks for valid path before attempting to create metadata. if invalid, return not-found metadata title. Removes `export const dynamicParams = false` to allow custom 404 and 500 pages
defaults to English; shows not-found page within layout so header and footer remain
@github-actions github-actions bot added content 🖋️ This involves copy additions or edits tooling 🔧 Changes related to tooling of the project translation 🌍 This is related to our Translation Program labels Jun 1, 2025
Copy link

netlify bot commented Jun 1, 2025

Deploy Preview for ethereumorg ready!

Name Link
🔨 Latest commit f9262dc
🔍 Latest deploy log https://app.netlify.com/projects/ethereumorg/deploys/6840c6c971605a00083dcf79
😎 Deploy Preview https://deploy-preview-15584--ethereumorg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
7 paths audited
Performance: 41 (🔴 down 9 from production)
Accessibility: 95 (🟢 up 1 from production)
Best Practices: 91 (🔴 down 7 from production)
SEO: 99 (no change from production)
PWA: 59 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@wackerow wackerow changed the title 500 404 patches fix: Error (500) and Not Found (404) routing logic Jun 4, 2025
@wackerow wackerow marked this pull request as ready for review June 4, 2025 22:26
Copy link
Member

@pettinarip pettinarip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @wackerow good job! left a few comments to understand the logic with error handlers mainly and see if we can polish them

@@ -1,23 +1,21 @@
"use client"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to convert this to a client component? couldn't we keep the server component?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pettinarip Without this I was unable to gain any access to the translated versions, so /es/derp was loading English content. Took a few approaches to try and properly load the locale before the page rendered using server-side, but in the end the initial load of the page was always going to English—Switching this to "use client" fixed it.

return {
title: t("page-not-found"),
description: t("page-not-found-description"),
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to return this metadata because the 404 page can't handle metadata? or why?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the 404 page is a server component, we might be able to handle this in that component, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pettinarip Throwing errors from the metadata generation step will stop our logic in it's tracks and default to Next.js 500 page. If we want this to handle as a 404, we need to return valid metadata, not throw an error, and then let the page component handle the routing.

error
)
return []
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I follow this logic, why getPostSlugs("/") would fail in Netlify? if it fails means that we don't have any page to build statically and we should break the build, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, getPostSlugs is now internally handling the same error case, no?

Copy link
Member Author

@wackerow wackerow Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jun 4, 01:59:07 PM: 4b95411b ERROR Error: ENOENT: no such file or directory, scandir '/var/task/public/content/'
at async Object.readdir (node:internal/fs/promises:952:18)
at async h (/var/task/.next/server/app/[locale]/[...slug]/page.js:1:826446)
at async D (/var/task/.next/server/app/[locale]/[...slug]/page.js:1:549543)
at async j (/var/task/.next/server/app/[locale]/[...slug]/page.js:1:548863) {
errno: -2,
code: 'ENOENT',
syscall: 'scandir',
path: '/var/task/public/content/',
digest: '930804571'
}

From the Netlify logs it seems that something was triggering this ENOENT error where it couldn't read from this directory in Netlify's serverless environment. This Search suggested that any other hidden system files that end up in there from this environment could be causing this to break when our code attempts to parse...
Wasn't 100% clear, but this step did seem to again prevent us from being able to properly access our internal 404 route, and wrapping in try/catch resolved here, while all desired pages are still loading correctly.

Can play around a bit more to see if perhaps the error handling inside getPostSlugs would be enough for this; that's one thing I hadn't tried yet, but that was the reasoning for this approach.

Copy link
Member

@pettinarip pettinarip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see our error page again (and w i18n :P)! gj

@pettinarip pettinarip merged commit 94d2aaa into dev Jun 6, 2025
11 checks passed
@pettinarip pettinarip deleted the 500-404-patches branch June 6, 2025 17:26
This was referenced Jun 12, 2025
@corwintines corwintines mentioned this pull request Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content 🖋️ This involves copy additions or edits tooling 🔧 Changes related to tooling of the project translation 🌍 This is related to our Translation Program
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants