Bust cache for RSC in each render (#32710)
* flight response should not be cached since it's could be changed per fetching * delete cache after readRoot has constructed react tree
This commit is contained in:
parent
d85e5ab48e
commit
6581ba9dae
3 changed files with 10 additions and 10 deletions
|
@ -762,7 +762,9 @@ if (process.env.__NEXT_RSC) {
|
|||
_fresh?: boolean
|
||||
}) => {
|
||||
const response = useServerResponse(cacheKey, serialized)
|
||||
return response.readRoot()
|
||||
const root = response.readRoot()
|
||||
rscCache.delete(cacheKey)
|
||||
return root
|
||||
}
|
||||
|
||||
RSCComponent = (props: any) => {
|
||||
|
|
|
@ -282,8 +282,9 @@ function checkRedirectValues(
|
|||
}
|
||||
}
|
||||
|
||||
const rscCache = new Map()
|
||||
|
||||
function createRSCHook() {
|
||||
const rscCache = new Map()
|
||||
const decoder = new TextDecoder()
|
||||
const encoder = new TextEncoder()
|
||||
|
||||
|
@ -315,6 +316,7 @@ function createRSCHook() {
|
|||
)
|
||||
}
|
||||
if (done) {
|
||||
rscCache.delete(id)
|
||||
writer.close()
|
||||
} else {
|
||||
writer.write(
|
||||
|
@ -357,7 +359,9 @@ function createServerComponentRenderer(
|
|||
reqStream,
|
||||
true
|
||||
)
|
||||
return response.readRoot()
|
||||
const root = response.readRoot()
|
||||
rscCache.delete(id)
|
||||
return root
|
||||
}
|
||||
const Component = (props: any) => {
|
||||
return (
|
||||
|
|
|
@ -1809,15 +1809,9 @@ export default class Router implements BaseRouter {
|
|||
}
|
||||
|
||||
_getFlightData(dataHref: string): Promise<object> {
|
||||
const { href: cacheKey } = new URL(dataHref, window.location.href)
|
||||
|
||||
if (!this.isPreview && this.sdc[cacheKey]) {
|
||||
return Promise.resolve({ fresh: false, data: this.sdc[cacheKey] })
|
||||
}
|
||||
|
||||
// Do not cache RSC flight response since it's not a static resource
|
||||
return fetchNextData(dataHref, true, true, this.sdc, false).then(
|
||||
(serialized) => {
|
||||
this.sdc[cacheKey] = serialized
|
||||
return { fresh: true, data: serialized }
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue