[PR #736] [MERGED] fix(tpr): use correct KV cache key format matching runtime #807

Closed
opened 2026-05-06 13:10:12 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/736
Author: @NathanDrake2406
Created: 4/1/2026
Status: Merged
Merged: 4/1/2026
Merged by: @james-elicx

Base: mainHead: fix/tpr-kv-key-format


📝 Commits (5)

  • 00b3972 fix(tpr): use correct KV cache key format matching runtime
  • d1a0527 fix(tpr): read buildId from BUILD_ID file instead of prerender manifest
  • bc1d548 address bonk review comments
  • 4f2da9d address second bonk review round
  • 7fadefe fix(build-id): write BUILD_ID once per build via closeBundle, not per-environment

📊 Changes

4 files changed (+192 additions, -43 deletions)

View changed files

📝 packages/vinext/src/cloudflare/kv-cache-handler.ts (+1 -1)
📝 packages/vinext/src/cloudflare/tpr.ts (+59 -29)
📝 packages/vinext/src/index.ts (+50 -13)
tests/tpr-kv-keys.test.ts (+82 -0)

📄 Description

Summary

  • TPR's uploadToKV wrote KV keys as cache:<pathname> but the runtime KVCacheHandler.get() reads cache:app:<buildId>:<pathname>:html — every TPR-seeded entry was a dead key (guaranteed cache miss)
  • Extracted buildTprKVPairs() as an exported pure function that delegates key construction to the shared isrCacheKey() from server/isr-cache.ts
  • Reads buildId from the prerender manifest (vinext-prerender.json) at upload time so keys include the build identifier

Before

cache:/blog/hello          ← TPR writes this
cache:app:abc123:/blog/hello:html  ← runtime expects this

Never matches → every TPR page is a cold miss.

After

cache:app:abc123:/blog/hello:html  ← TPR writes this
cache:app:abc123:/blog/hello:html  ← runtime expects this

Test plan

  • 7 unit tests covering key format parity, header-based revalidate, TTL clamping (min 60s, max 30d), no-buildId backward compat, KVCacheEntry serialization
  • 216 existing deploy tests pass
  • 42 ISR cache tests pass
  • vp check clean

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/736 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 4/1/2026 **Status:** ✅ Merged **Merged:** 4/1/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/tpr-kv-key-format` --- ### 📝 Commits (5) - [`00b3972`](https://github.com/cloudflare/vinext/commit/00b3972ea9d136ac83ce5ef2ca629ed563d0aba4) fix(tpr): use correct KV cache key format matching runtime - [`d1a0527`](https://github.com/cloudflare/vinext/commit/d1a05276257ce0a70a2cae6f4c5e6790cc58069f) fix(tpr): read buildId from BUILD_ID file instead of prerender manifest - [`bc1d548`](https://github.com/cloudflare/vinext/commit/bc1d548df0248488687ea03c2e93f56e36ac8869) address bonk review comments - [`4f2da9d`](https://github.com/cloudflare/vinext/commit/4f2da9dc549cf0e979fbe048aa1b0796a3d92c75) address second bonk review round - [`7fadefe`](https://github.com/cloudflare/vinext/commit/7fadefedaffeadbbf6770d103daf5972fc088833) fix(build-id): write BUILD_ID once per build via closeBundle, not per-environment ### 📊 Changes **4 files changed** (+192 additions, -43 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/cloudflare/kv-cache-handler.ts` (+1 -1) 📝 `packages/vinext/src/cloudflare/tpr.ts` (+59 -29) 📝 `packages/vinext/src/index.ts` (+50 -13) ➕ `tests/tpr-kv-keys.test.ts` (+82 -0) </details> ### 📄 Description ## Summary - TPR's `uploadToKV` wrote KV keys as `cache:<pathname>` but the runtime `KVCacheHandler.get()` reads `cache:app:<buildId>:<pathname>:html` — every TPR-seeded entry was a dead key (guaranteed cache miss) - Extracted `buildTprKVPairs()` as an exported pure function that delegates key construction to the shared `isrCacheKey()` from `server/isr-cache.ts` - Reads `buildId` from the prerender manifest (`vinext-prerender.json`) at upload time so keys include the build identifier ### Before ``` cache:/blog/hello ← TPR writes this cache:app:abc123:/blog/hello:html ← runtime expects this ``` Never matches → every TPR page is a cold miss. ### After ``` cache:app:abc123:/blog/hello:html ← TPR writes this cache:app:abc123:/blog/hello:html ← runtime expects this ``` ## Test plan - [x] 7 unit tests covering key format parity, header-based revalidate, TTL clamping (min 60s, max 30d), no-buildId backward compat, KVCacheEntry serialization - [x] 216 existing deploy tests pass - [x] 42 ISR cache tests pass - [x] `vp check` clean --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:10:12 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#807
No description provided.