Unverified Commit e75361fd authored by Shu Ding's avatar Shu Ding Committed by GitHub

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`
parent e8977bc3
...@@ -644,6 +644,11 @@ const wrapApp = ...@@ -644,6 +644,11 @@ const wrapApp =
let RSCComponent: (props: any) => JSX.Element let RSCComponent: (props: any) => JSX.Element
if (process.env.__NEXT_RSC) { if (process.env.__NEXT_RSC) {
const getCacheKey = () => {
const { pathname, search } = location
return pathname + search
}
const { const {
createFromFetch, createFromFetch,
} = require('next/dist/compiled/react-server-dom-webpack') } = require('next/dist/compiled/react-server-dom-webpack')
...@@ -651,9 +656,9 @@ if (process.env.__NEXT_RSC) { ...@@ -651,9 +656,9 @@ if (process.env.__NEXT_RSC) {
const encoder = new TextEncoder() const encoder = new TextEncoder()
const serverDataBuffer = new Map<string, string[]>() const serverDataBuffer = new Map<string, string[]>()
const serverDataWriter = new Map<string, WritableStreamDefaultWriter>() const serverDataWriter = new Map<string, WritableStreamDefaultWriter>()
const ssrCacheKey = location ? location.href : '' const serverDataCacheKey = getCacheKey()
function nextServerDataCallback(seg: [number, string, string]) { function nextServerDataCallback(seg: [number, string, string]) {
const key = ssrCacheKey + ',' + seg[1] const key = serverDataCacheKey + ',' + seg[1]
if (seg[0] === 0) { if (seg[0] === 0) {
serverDataBuffer.set(key, []) serverDataBuffer.set(key, [])
} else { } else {
...@@ -715,11 +720,6 @@ if (process.env.__NEXT_RSC) { ...@@ -715,11 +720,6 @@ if (process.env.__NEXT_RSC) {
return fetch(url.toString()) return fetch(url.toString())
} }
const getCacheKey = () => {
const { pathname, search } = location
return pathname + search
}
function useServerResponse(cacheKey: string, serialized?: string) { function useServerResponse(cacheKey: string, serialized?: string) {
const id = (React as any).useId() const id = (React as any).useId()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment