From e75361fd03872b097e817634c049b3185f24cf56 Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Tue, 14 Dec 2021 20:52:37 +0100 Subject: [PATCH] Fix server data cache key (#32506) Currently we are using `location.href` which doesn't align with the other flight request's cache key (`pathname + search`). This fix unifies it. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `yarn lint` --- packages/next/client/index.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/next/client/index.tsx b/packages/next/client/index.tsx index 42b2d6e509a86cc..9ad4e7c63a0bcc5 100644 --- a/packages/next/client/index.tsx +++ b/packages/next/client/index.tsx @@ -644,6 +644,11 @@ const wrapApp = let RSCComponent: (props: any) => JSX.Element if (process.env.__NEXT_RSC) { + const getCacheKey = () => { + const { pathname, search } = location + return pathname + search + } + const { createFromFetch, } = require('next/dist/compiled/react-server-dom-webpack') @@ -651,9 +656,9 @@ if (process.env.__NEXT_RSC) { const encoder = new TextEncoder() const serverDataBuffer = new Map() const serverDataWriter = new Map() - const ssrCacheKey = location ? location.href : '' + const serverDataCacheKey = getCacheKey() function nextServerDataCallback(seg: [number, string, string]) { - const key = ssrCacheKey + ',' + seg[1] + const key = serverDataCacheKey + ',' + seg[1] if (seg[0] === 0) { serverDataBuffer.set(key, []) } else { @@ -715,11 +720,6 @@ if (process.env.__NEXT_RSC) { return fetch(url.toString()) } - const getCacheKey = () => { - const { pathname, search } = location - return pathname + search - } - function useServerResponse(cacheKey: string, serialized?: string) { const id = (React as any).useId()