fix: percent-encode search values in unstable_cache fetchUrl - #96954
Draft
icyJoseph wants to merge 1 commit into
Draft
fix: percent-encode search values in unstable_cache fetchUrl#96954icyJoseph wants to merge 1 commit into
icyJoseph wants to merge 1 commit into
Conversation
Contributor
Stats from current PR🔴 1 regression, 3 improvements
📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
Build Cache
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📝 Changed Files (33 files)Files with changes:
View diffsapp-page-exp..ntime.dev.jsfailed to diffapp-page-exp..time.prod.jsfailed to diffapp-page-tur..ntime.dev.jsfailed to diffapp-page-tur..time.prod.jsfailed to diffapp-page-tur..ntime.dev.jsfailed to diffapp-page-tur..time.prod.jsfailed to diffapp-page.runtime.dev.jsfailed to diffapp-page.runtime.prod.jsfailed to diffapp-route-ex..ntime.dev.jsDiff too large to display app-route-ex..time.prod.jsDiff too large to display app-route-tu..ntime.dev.jsDiff too large to display app-route-tu..time.prod.jsDiff too large to display app-route-tu..ntime.dev.jsDiff too large to display app-route-tu..time.prod.jsDiff too large to display app-route.runtime.dev.jsDiff too large to display app-route.ru..time.prod.jsDiff too large to display dev-validati..ntime.dev.jsfailed to diffdev-validati..ntime.dev.jsfailed to diffdev-validati..ntime.dev.jsfailed to diffdev-validati..ntime.dev.jsfailed to diffpages-api-tu..ntime.dev.jsDiff too large to display pages-api-tu..time.prod.jsDiff too large to display pages-api.runtime.dev.jsDiff too large to display pages-api.ru..time.prod.jsDiff too large to display pages-turbo...ntime.dev.jsDiff too large to display pages-turbo...time.prod.jsDiff too large to display pages.runtime.dev.jsDiff too large to display pages.runtime.prod.jsDiff too large to display server.runtime.prod.jsDiff too large to display use-cache-pr..ntime.dev.jsDiff too large to display use-cache-pr..ntime.dev.jsDiff too large to display use-cache-pr..ntime.dev.jsDiff too large to display use-cache-pr..ntime.dev.jsDiff too large to display 📎 Tarball URLCommit: fad26be |
Contributor
Failing CI jobsCommit: fad26be | About building and testing Next.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #76286
What?
unstable_cachebuildsfetchUrl, a label describing the current request, by interpolating decoded search values —.map((key) => `${key}=${searchParams.get(key)}`). This rebuilds that label withURLSearchParamsinstead, so the values come out percent-encoded and the label is always ASCII.Why?
fetchUrlis handed to the incremental cache.next.js/packages/next/src/server/lib/incremental-cache/index.ts
Lines 203 to 215 in d67e1f3
When a
FetchCacheis available, like on Vercel, the handler makes an HTTP request to the data cache and sendsfetchUrlas thex-vercel-cache-item-nameheader, and header values are ByteStrings, so a codepoint above U+00FF makesnew Headers()throw before the request is even sent.We see no errors and the request succeeds, so combined with the v14 history below, the likely explanation is that the throw is caught and returned as
null, which looks like a MISS, andset()fails the same way, so nothing is ever written either.The result is that
unstable_cachesilently stops caching for any URL carrying a non-Latin-1 query value, including one the app never reads.Under
next start,FileSystemCachethere's no such path forfetchUrl, all good.How?
Each value is appended to a
URLSearchParamsand serialized withtoString(), which percent-encodes.Using
getAll()also keeps repeated keys distinct —?a=1&a=2previously produceda=1&a=1.Verified on a Vercel deployment: https://issue-76286-patched-next.vercel.app/?key=bar&extra=%E4%B8%AD%E5%9C%8B%E4%BA%BA
Control without the patch: https://throwaway-phi.vercel.app/?key=bar&extra=%E4%B8%AD%E5%9C%8B%E4%BA%BA