Skip to content

Commit

Permalink
Fix server data cache key (#32506)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
shuding committed Dec 14, 2021
1 parent e8977bc commit e75361f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/next/client/index.tsx
Expand Up @@ -644,16 +644,21 @@ 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')

const encoder = new TextEncoder()
const serverDataBuffer = new Map<string, string[]>()
const serverDataWriter = new Map<string, WritableStreamDefaultWriter>()
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 {
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit e75361f

Please sign in to comment.