[PR #544] [MERGED] fix: implement prefix-based invalidation for revalidatePath layout type #660

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

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/544
Author: @NathanDrake2406
Created: 3/15/2026
Status: Merged
Merged: 3/17/2026
Merged by: @james-elicx

Base: mainHead: fix/revalidate-path-layout


📝 Commits (9)

  • 7b1af3f fix: implement prefix-based invalidation for revalidatePath with type layout
  • f69263e fix: address review feedback for revalidatePath layout type
  • c047bd4 refactor: replace collectTagsByPathPrefix with revalidateByPathPrefix
  • 2cf1137 fix: address PR review feedback — remove dead code, harden tag matching, add tests
  • 46de344 refactor: replace O(n) prefix scanning with O(1) layout tag invalidation
  • 919bbbb fix: implement distinct page-type invalidation for revalidatePath
  • 3174332 fix: double-slash in root page cache tag breaks revalidatePath("/", "page")
  • d6defd0 refactor: simplify revalidatePath and reduce comment noise
  • ebecdba refactor: simplify tag construction — reuse stem, eliminate tagBase ternary

📊 Changes

4 files changed (+305 additions, -9 deletions)

View changed files

📝 packages/vinext/src/entries/app-rsc-entry.ts (+12 -0)
📝 packages/vinext/src/shims/cache.ts (+16 -8)
📝 tests/__snapshots__/entry-templates.test.ts.snap (+72 -0)
📝 tests/isr-cache.test.ts (+205 -1)

📄 Description

Summary

  • revalidatePath(path, 'layout') was ignoring the type parameter entirely — the _type param was declared but never read
  • In Next.js, type: "layout" invalidates the path AND all child pages beneath it (e.g., revalidatePath('/dashboard', 'layout') also invalidates /dashboard/settings, /dashboard/profile)
  • Added collectTagsByPathPrefix optional method to CacheHandler interface, implemented on MemoryCacheHandler
  • Added segment-aware _isPathChildOf helper (prevents false matches like /dashboard matching /dashboard-admin)
  • Added console.warn when layout invalidation degrades on handlers without prefix support (e.g., KVCacheHandler)
  • Added trailing slash normalization for the public API
  • Updated next-shims.d.ts type declarations

Test plan

  • 6 new tests: layout invalidation, page-only, backward compat, deep nesting, segment boundary, root path
  • All 38 ISR cache tests pass
  • All 3253 tests pass (including ecosystem)
  • Typecheck and lint clean
  • KVCacheHandler collectTagsByPathPrefix implementation (follow-up PR — KV's list() API supports prefix scanning)

🔄 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/544 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 3/15/2026 **Status:** ✅ Merged **Merged:** 3/17/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/revalidate-path-layout` --- ### 📝 Commits (9) - [`7b1af3f`](https://github.com/cloudflare/vinext/commit/7b1af3f0add044b6010bc394a2fe9a8c081c0ad5) fix: implement prefix-based invalidation for revalidatePath with type layout - [`f69263e`](https://github.com/cloudflare/vinext/commit/f69263e5fbb70bfa7c6358ea79d9984a45b592b2) fix: address review feedback for revalidatePath layout type - [`c047bd4`](https://github.com/cloudflare/vinext/commit/c047bd451463e75bdb00fe0a58614696e5bc7404) refactor: replace collectTagsByPathPrefix with revalidateByPathPrefix - [`2cf1137`](https://github.com/cloudflare/vinext/commit/2cf1137b2f606e42c324a523015d0fceecf0422e) fix: address PR review feedback — remove dead code, harden tag matching, add tests - [`46de344`](https://github.com/cloudflare/vinext/commit/46de3449e6a4b9dfb62c4a14ffb27807e3acb673) refactor: replace O(n) prefix scanning with O(1) layout tag invalidation - [`919bbbb`](https://github.com/cloudflare/vinext/commit/919bbbbb41401774f3fc399e9c5ba317cc86ae05) fix: implement distinct page-type invalidation for revalidatePath - [`3174332`](https://github.com/cloudflare/vinext/commit/31743329d67563ff71dd5d89abceceaf3abd40ff) fix: double-slash in root page cache tag breaks revalidatePath("/", "page") - [`d6defd0`](https://github.com/cloudflare/vinext/commit/d6defd0decf170bbc34bf9998a987b6a9d5eb804) refactor: simplify revalidatePath and reduce comment noise - [`ebecdba`](https://github.com/cloudflare/vinext/commit/ebecdba8a3120d28e18801c3a017b204384f27c8) refactor: simplify tag construction — reuse stem, eliminate tagBase ternary ### 📊 Changes **4 files changed** (+305 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/entries/app-rsc-entry.ts` (+12 -0) 📝 `packages/vinext/src/shims/cache.ts` (+16 -8) 📝 `tests/__snapshots__/entry-templates.test.ts.snap` (+72 -0) 📝 `tests/isr-cache.test.ts` (+205 -1) </details> ### 📄 Description ## Summary - `revalidatePath(path, 'layout')` was ignoring the `type` parameter entirely — the `_type` param was declared but never read - In Next.js, `type: "layout"` invalidates the path AND all child pages beneath it (e.g., `revalidatePath('/dashboard', 'layout')` also invalidates `/dashboard/settings`, `/dashboard/profile`) - Added `collectTagsByPathPrefix` optional method to `CacheHandler` interface, implemented on `MemoryCacheHandler` - Added segment-aware `_isPathChildOf` helper (prevents false matches like `/dashboard` matching `/dashboard-admin`) - Added `console.warn` when layout invalidation degrades on handlers without prefix support (e.g., KVCacheHandler) - Added trailing slash normalization for the public API - Updated `next-shims.d.ts` type declarations ## Test plan - [x] 6 new tests: layout invalidation, page-only, backward compat, deep nesting, segment boundary, root path - [x] All 38 ISR cache tests pass - [x] All 3253 tests pass (including ecosystem) - [x] Typecheck and lint clean - [ ] KVCacheHandler `collectTagsByPathPrefix` implementation (follow-up PR — KV's `list()` API supports prefix scanning) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:09:23 +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#660
No description provided.