@decocms/tanstack 7.83.1 → 7.83.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/tanstack",
3
- "version": "7.83.1",
3
+ "version": "7.83.2",
4
4
  "type": "module",
5
5
  "description": "Deco framework binding for TanStack Start + Cloudflare Workers",
6
6
  "repository": {
@@ -27,9 +27,9 @@
27
27
  "lint:unused": "knip"
28
28
  },
29
29
  "dependencies": {
30
- "@decocms/blocks": "7.83.1",
31
- "@decocms/blocks-admin": "7.83.1",
32
- "@decocms/blocks-cli": "7.83.1",
30
+ "@decocms/blocks": "7.83.2",
31
+ "@decocms/blocks-admin": "7.83.2",
32
+ "@decocms/blocks-cli": "7.83.2",
33
33
  "@deco-cx/warp-node": "^0.3.16",
34
34
  "fast-json-patch": "^3.1.0",
35
35
  "ws": "^8.18.0"
@@ -35,6 +35,15 @@ describe("lookupExactRedirect", () => {
35
35
  });
36
36
  });
37
37
 
38
+ it("only navigations read KV: POST/PUT skip the lookup entirely", async () => {
39
+ const kv = makeKV({ [`redirect:${ID}:/old`]: '{"to":"/new","status":301}' });
40
+ await expect(lookupExactRedirect(enabled(kv), "/old", "POST")).resolves.toBeNull();
41
+ await expect(lookupExactRedirect(enabled(kv), "/old", "PUT")).resolves.toBeNull();
42
+ expect(kv.get).not.toHaveBeenCalled();
43
+ await expect(lookupExactRedirect(enabled(kv), "/old", "HEAD")).resolves.toMatchObject({ to: "/new" });
44
+ expect(kv.get).toHaveBeenCalledTimes(1);
45
+ });
46
+
38
47
  it("returns null for a missing key", async () => {
39
48
  await expect(lookupExactRedirect(enabled(makeKV()), "/nope")).resolves.toBeNull();
40
49
  });
@@ -91,11 +91,27 @@ export function clearRedirectCache(): void {
91
91
  * cannot run (fast-deploy off, no deployment id, KV error). A KV failure must
92
92
  * not 5xx a page that would otherwise render: the worst outcome is the request
93
93
  * proceeds and the URL serves its normal response.
94
+ *
95
+ * Only navigations (GET/HEAD) read KV. A content redirect is a navigation
96
+ * concept, and the rest of the traffic — the commerce proxy's cart/checkout
97
+ * POSTs above all — has a fresh path per request (`/orderForm/<id>/…`), so the
98
+ * isolate memo never hits and every one paid a serial KV miss (p75 ~160ms on
99
+ * a production storefront) before reaching its handler. In-memory rules
100
+ * (exact and glob) still apply to every method; only the KV read is gated.
101
+ *
102
+ * Trade-off: a temporary rule is served as 307, which browsers follow with the
103
+ * original method, so a KV-only 307 on a form/webhook path used to forward the
104
+ * POST and now lets it reach that path's handler. On a non-fast-deploy site
105
+ * the same rule is in memory and still redirects POSTs — the behaviour differs
106
+ * by deploy mode for that one case. Content redirects are navigation-only in
107
+ * practice; a site that redirects POST endpoints should do it in code.
94
108
  */
95
109
  export async function lookupExactRedirect(
96
110
  env: Record<string, unknown>,
97
111
  pathname: string,
112
+ method = "GET",
98
113
  ): Promise<Redirect | null> {
114
+ if (method !== "GET" && method !== "HEAD") return null;
99
115
  const kv = getFastDeployKV(env);
100
116
  if (!kv) return null;
101
117
 
@@ -2492,9 +2492,12 @@ export function createDecoWorkerEntry(
2492
2492
  // glob win over an exact rule, inverting the precedence.
2493
2493
  // Query-scoped rules (`/x?map=ft`) live in memory only, so the KV lookup
2494
2494
  // stays one read, keyed by pathname.
2495
+ // That precedence holds for navigations (GET/HEAD) only: other methods
2496
+ // skip the KV read (see `lookupExactRedirect`), so for a POST a glob can
2497
+ // answer where a KV-only exact rule would have.
2495
2498
  const cmsRedirect =
2496
2499
  matchExactRedirect(url.pathname, _redirectMap!, url.search) ??
2497
- (await lookupExactRedirect(env as Record<string, unknown>, url.pathname)) ??
2500
+ (await lookupExactRedirect(env as Record<string, unknown>, url.pathname, request.method)) ??
2498
2501
  matchPatternRedirect(url.pathname, _redirectMap!);
2499
2502
  if (cmsRedirect) {
2500
2503
  return new Response(null, {