fix(next): re-throw unhandled errors in DocumentView to prevent blank edit views#16124
Open
litlmike wants to merge 1 commit intopayloadcms:mainfrom
Open
fix(next): re-throw unhandled errors in DocumentView to prevent blank edit views#16124litlmike wants to merge 1 commit intopayloadcms:mainfrom
litlmike wants to merge 1 commit intopayloadcms:mainfrom
Conversation
… edit views When renderDocument throws an error that is neither 'NEXT_REDIRECT' nor 'not-found', the catch block in DocumentView logs the error but returns undefined. React renders this as an empty Suspense boundary, producing a completely blank edit view with no visible error message. This is especially prevalent on edge runtimes (Cloudflare Workers/Pages) where auth-context failures, streaming issues, or missing Node.js APIs cause errors that fall through to the unhandled path. The fix re-throws unhandled errors so they propagate to Next.js error boundaries, which render a visible error instead of a blank page. Fixes payloadcms#15712 Relates to payloadcms#14656
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.
Description
When
renderDocumentthrows an error that is neitherNEXT_REDIRECTnornot-found, the catch block inDocumentView(packages/next/src/views/Document/index.tsx) logs the error but returnsundefined. React rendersundefinedas empty content inside the Suspense boundary, producing a completely blank edit view with no visible error.The Fix
Add
throw errorat the end of the catch block so unhandled errors propagate to Next.js error boundaries instead of rendering blank.This is a one-line fix. The comment block explains why it exists for future maintainers.
Impact
not-foundorNEXT_REDIRECTRoot Cause Analysis
On Cloudflare Workers,
renderDocumentdoes heavy async work — twoPromise.allcalls fetching permissions, lock state, versions, and form state. Any of these can fail on edge runtimes due to:These errors are neither
not-foundnorNEXT_REDIRECT, so they hit the unhandled path and the function silently returnsundefined.Testing
Added
DocumentView.spec.tswith vitest cases verifying:NEXT_REDIRECTerrors propagate correctlyundefinedRelated Issues
Fixes #15712 — Edit views render blank on Cloudflare Pages (empty RSC Suspense boundaries)
Relates to #14656 — Server Actions lose authentication in Cloudflare Workers environment
Relates to opennextjs/opennextjs-cloudflare#544 — PayloadCMS not working with opennextjs