Skip to content

renderJson: a path that renders the 404 page answers 200 with the not-found page envelope #651

Open

Description

@aline-pereira

What

GET /<unknown-path>?renderJson answers 200 with { name, path, sections } of the site's catch-all not-found page, while GET /<unknown-path> (HTML) answers 404.

The ?renderJson branch in packages/tanstack/src/sdk/workerEntry.ts calls resolveDecoPage(basePath, matcherCtx) and only emits the { status: 404, notFound: true } envelope when it returns null. A site with a catch-all page block (/*, the usual not-found page) always matches, so the resolver returns that page and the JSON goes out as 200. The HTML route gets its 404 from the site's catch-all route setting the status — a step the JSON path has no equivalent of.

Measured on deco-sites/oficina-tanstack: /this-does-not-exist?renderJson → 200 application/json with the not-found page's sections; same path without ?renderJson → 404 text/html. Production (Fresh) answers the JSON with the page's status.

Impact

The mobile app cannot distinguish a real page from the not-found page without inspecting section names, and a 200 JSON for an unknown path is cacheable by intermediaries with the page's Cache-Control.

Suggestion

Carry the page's status into the JSON response: if the matched page is the catch-all not-found page (the same signal the HTML route uses — e.g. the page's path being the wildcard, or an explicit not-found marker from the resolver), respond 404 with the envelope ({ status: 404, notFound: true, ...page }) so the app keeps the sections for rendering but the status is honest.

Found while validating deco-sites/oficina-tanstack#479.

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions