fix(docs): Handle missing MDX source files correctly in Edge runtime - #18873
Open
sfanahata wants to merge 2 commits into
Open
fix(docs): Handle missing MDX source files correctly in Edge runtime#18873sfanahata wants to merge 2 commits into
sfanahata wants to merge 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Replace instanceof Error checks with duck-typed isExpectedMdxError() utility that works across Edge runtime VM context boundaries. The instanceof check fails when Error objects cross VM boundaries, causing expected 'file not found' errors to produce 500s instead of 404s. Changes: - Extract error classification into shared src/mdxErrors.ts - Update both catch blocks in page.tsx to use isExpectedMdxError() - Update include.tsx to use isExpectedMdxError() with typed catch - Add diagnostic logging on unexpected errors (re-throw path) - Add unit tests for isExpectedMdxError() covering all error shapes - Add error contract tests for getFileBySlug in mdx.spec.ts Fixes DOCS-9WN
sfanahata
force-pushed
the
fix/edge-mdx-error-handling-with-tests
branch
from
July 29, 2026 18:11
d95dc10 to
f32aaab
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DESCRIBE YOUR PR
This PR fixes an issue where requests for non-existent documentation pages (e.g.,
/docs/changelog) result in a 500 Internal Server Error instead of a 404 Not Found.Root Cause
The
isExpectedErrorcheck inapp/[[...path]]/page.tsxusede instanceof Errorto identify 'Failed to find a valid source file' errors. In Edge runtime environments,Errorobjects crossing VM context boundaries causeinstanceof Errorto returnfalse, preventing the error from being caught and producing a 500 instead of a 404.Fix
isExpectedMdxError()into a shared utility (src/mdxErrors.ts) that uses duck-typing (.codeproperty check + message-string fallback) instead ofinstanceof, which works correctly across Edge runtime VM boundaries.page.tsxand the catch block ininclude.tsxto use the shared function, eliminating code duplication.TODO(diagnostic)) to confirm the error shape in production Edge runtime.Tests Added
src/mdxErrors.spec.ts: Unit tests forisExpectedMdxError()covering all error shapes: standard Errors, plain objects (Edge runtime simulation), string/null/undefined throws.src/mdx.spec.ts: Error contract tests verifyinggetFileBySlugthrows errors with the correct.codeproperty (ENOENTandMDX_RUNTIME_ERROR), and thatisExpectedMdxError()recognizes them.Files Changed
src/mdxErrors.tsisExpectedMdxError()functionsrc/mdxErrors.spec.tsapp/[[...path]]/page.tsxsrc/components/include.tsxsrc/mdx.spec.tsapp/[[...path]]/page.spec.tsIS YOUR CHANGE URGENT?
Fixes DOCS-9WN
PRE-MERGE CHECKLIST
LEGAL BOILERPLATE
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.