Skip to content

fix(nextjs): actionable diagnostic when the RSC preview page is not mounted - #446

Open
guitavano wants to merge 1 commit into
mainfrom
guitavano/next-preview-broken
Open

fix(nextjs): actionable diagnostic when the RSC preview page is not mounted#446
guitavano wants to merge 1 commit into
mainfrom
guitavano/next-preview-broken

Conversation

@guitavano

@guitavano guitavano commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Contexto

Vários sites Next migrados perderam silenciosamente o preview de seção, retornando:

{"error":"Unknown deco route: /deco/preview/website%2Fpages%2FPage.tsx"}

A causa nesses sites é o site não montar app/deco/preview/[[...path]]/page.tsx. O @decocms/nextjs faz 307 de todo preview GET pra /deco/preview/*; sem a página RSC, o redirect cai no catch-all /deco/[[...deco]], cujo resolveAction() não reconhece preview/* → o 404 críptico acima. (Fix do site é adicionar a página; este PR é só de DX no framework.)

Mudança

Quando um GET /deco/preview/* chega no route handler — o que acontece quando a página RSC não está montada (com ela presente, o segmento estático preview tem prioridade sobre o catch-all opcional e o handler nunca é chamado) — retorna um 501 acionável nomeando o arquivo que falta e como criá-lo, em vez do Unknown deco route.

Explicitamente não cai pra handleRender aqui: este handler roda no grafo react-server, onde renderToString não consegue invocar os client-reference proxies de componentes "use client" — que é justamente o motivo da página RSC dedicada existir.

Por que é seguro

Zero mudança de comportamento pra sites configurados certo: eles nunca roteiam /deco/preview/* pra este handler.

Verificação

  • Reproduzido em next build && next start limpo: com a página montada, /deco/preview/* (com %2F e com barras reais) cai na página (200); sem ela, cai no handler.
  • Testes novos (encoded key, sem key, e que /deco/previews plural continua 307). Suíte completa: 76 passando, typecheck limpo.

🤖 Generated with Claude Code


Summary by cubic

Add an actionable 501 diagnostic when /deco/preview/* hits the catch-all, guiding users to mount app/deco/preview/[[...path]]/page.tsx. This replaces the cryptic 404 and helps restore section previews for Next.js sites using @decocms/nextjs.

  • Bug Fixes
    • Return 501 JSON with a clear message and path when the RSC preview page is missing, instead of "Unknown deco route".
    • Preserve behavior for correctly configured sites; /deco/previews/* still 307s.
    • Add tests for encoded key, missing key, and plural path routing.

Written for commit 821327b. Summary will update on new commits.

Review in cubic

…ounted

A GET for /deco/preview/* reaches the catch-all route handler ONLY when
app/deco/preview/[[...path]]/page.tsx is absent — with the page present,
Next's static `preview` segment out-specifies the optional [[...deco]]
catch-all and the handler never sees the request (verified against a real
next build && next start, for both real-slash and %2F-encoded keys).

Previously a missing page degraded to a cryptic
`{"error":"Unknown deco route: /deco/preview/..."}` 404 — this is exactly
how several migrated Next sites silently lost section previews. Return a
501 that names the missing file and how to create it instead. No behavior
change for correctly-configured sites.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@guitavano
guitavano requested a review from a team August 6, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant