Skip to content

fix(tanstack): serve /live/invoke as an alias of /deco/invoke, 400 on malformed JSON - #645

Merged
guitavano merged 2 commits into
mainfrom
fix/live-invoke-alias
Oct 9, 2026
Merged

guitavano merged 2 commits into
mainfrom
fix/live-invoke-alias

Conversation

@aline-pereira

@aline-pereira aline-pereira commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem

deco-runtime (Fresh) served the invoke endpoint under both prefixes — runtime/handler.tsx: paths: ["/live/invoke", "/deco/invoke"] and ["/live/invoke/*", "/deco/invoke/*"]. Clients built against a Fresh site keep calling /live/invoke/... (the oficina mobile app: Apple sign-in exchange/userinfo, addresses, cards). On @decocms/tanstack only /deco/invoke/$ exists, so /live/invoke/... falls through to the CMS router and answers a 404 HTML page.

Reproduction (measured on the site)

POST https://<staging>/live/invoke/vtex/loaders/user.ts → 404 text/html (the not-found page); the same body on /deco/invoke/vtex/loaders/user.ts → 200 application/json. The site works around it in src/worker-entry.ts (liveInvokeAlias).

Fix

  • aliasLiveInvoke(request) (exported, workerEntry.ts): /live/invoke → /deco/invoke, /live/invoke/* → /deco/invoke/*. Applied at the top of handleRequest, before admin routes, bypass paths and the site's route tree read the path. Same Request reference for every other path (no allocation on the hot path). The rewritten request keeps method, headers, body, query, signal and cf (built field by field — the new Request(url, request) form does not carry cf on every runtime, same reasoning as revalidationRequest).
  • handleInvoke (blocks-admin/src/admin/invoke.ts): a body that declares application/json and does not parse now answers 400 { "error": "Invalid JSON" } instead of running the handler with {} (an action executing without its input). This mirrors deco-runtime's json parsing strategy (runtime/routes/invoke.ts, propsParsers.json throws) and the site's Fresh middleware (routes/_middleware.ts: return new Response("Invalid JSON", { status: 400 }) for POST /live/invoke/*). Compatibility kept where it matters: an empty body is still {} (bodiless POST = no props), and a body without a JSON content-type keeps the lenient try-json behavior ({} on failure).

Tests

  • packages/tanstack/src/sdk/workerEntry.test.ts — aliasLiveInvoke leaves other paths untouched (same reference); rewrites exact and splat paths keeping query/method/headers/body/cf; end-to-end through createDecoWorkerEntry the server entry receives the /deco/invoke/... URL.
  • packages/blocks-admin/src/admin/invoke.test.ts — declared-JSON malformed body → 400 and the handler never runs; empty declared-JSON body → handler runs with {}; no content-type + malformed → lenient {}.

vitest run on both files: new tests pass (invoke.test.ts 11/11; the 3 pre-existing failures in workerEntry.test.ts — draft preview (pull-based) ×2, CDN-Cache-Control … defaults to no-store — are the same on a clean main). tsc --noEmit clean for packages/tanstack and packages/blocks-admin; biome check clean on the touched files.

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

🤖 Generated with Claude Code


Summary by cubic

Makes @decocms/tanstack workers serve /live/invoke and /live/invoke/* as aliases of /deco/invoke, so Fresh-built clients keep working, and answers 400 on malformed JSON in invoke bodies instead of silently running the handler with {}.

  • aliasLiveInvoke rewrites the path at the top of the worker's request handling, preserving method, headers, body, query and cf; other paths keep the same Request reference with no allocation.
  • handleInvoke returns 400 { error: "Invalid JSON" } for bodies that declare application/json but don't parse; an empty body still becomes {}, and a body without a JSON content-type keeps the lenient try-json behavior.

Written for commit a12aa9d. Summary will update on new commits.

View guided diff Turn on auto-fix

… malformed JSON

deco-runtime registered `/live/invoke[/*]` and `/deco/invoke[/*]` for the
same handler (runtime/handler.tsx). Clients built against a Fresh site —
the mobile app, partner integrations — still call `/live/invoke/...`; on
`@decocms/tanstack` that path fell through to the CMS router and answered
a 404 HTML page.

`aliasLiveInvoke` rewrites the request at the top of the worker's
`handleRequest`, before admin routes, bypass paths or the site's
`/deco/invoke/$` route read the path. Method, headers, body, query and
`cf` are preserved.

`handleInvoke` (blocks-admin) now answers 400 `{ error: "Invalid JSON" }`
for a body that declares `application/json` and does not parse, instead
of running the handler with `{}` — mirroring deco-runtime's `json`
strategy, which throws on invalid JSON. An empty body is still `{}`, and
a body without a JSON content-type keeps the lenient `try-json` path.

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

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@aline-pereira
aline-pereira requested a review from a team October 9, 2026 00:24
# Conflicts:
#	packages/tanstack/src/sdk/workerEntry.test.ts
@guitavano
guitavano merged commit 0434d5e into main Oct 9, 2026
1 check passed
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 7.77.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants