Unverified Commit 6581ba9d authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

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
parent d85e5ab4
...@@ -762,7 +762,9 @@ if (process.env.__NEXT_RSC) { ...@@ -762,7 +762,9 @@ if (process.env.__NEXT_RSC) {
_fresh?: boolean _fresh?: boolean
}) => { }) => {
const response = useServerResponse(cacheKey, serialized) const response = useServerResponse(cacheKey, serialized)
return response.readRoot() const root = response.readRoot()
rscCache.delete(cacheKey)
return root
} }
RSCComponent = (props: any) => { RSCComponent = (props: any) => {
......
...@@ -282,8 +282,9 @@ function checkRedirectValues( ...@@ -282,8 +282,9 @@ function checkRedirectValues(
} }
} }
const rscCache = new Map()
function createRSCHook() { function createRSCHook() {
const rscCache = new Map()
const decoder = new TextDecoder() const decoder = new TextDecoder()
const encoder = new TextEncoder() const encoder = new TextEncoder()
...@@ -315,6 +316,7 @@ function createRSCHook() { ...@@ -315,6 +316,7 @@ function createRSCHook() {
) )
} }
if (done) { if (done) {
rscCache.delete(id)
writer.close() writer.close()
} else { } else {
writer.write( writer.write(
...@@ -357,7 +359,9 @@ function createServerComponentRenderer( ...@@ -357,7 +359,9 @@ function createServerComponentRenderer(
reqStream, reqStream,
true true
) )
return response.readRoot() const root = response.readRoot()
rscCache.delete(id)
return root
} }
const Component = (props: any) => { const Component = (props: any) => {
return ( return (
......
...@@ -1809,15 +1809,9 @@ export default class Router implements BaseRouter { ...@@ -1809,15 +1809,9 @@ export default class Router implements BaseRouter {
} }
_getFlightData(dataHref: string): Promise<object> { _getFlightData(dataHref: string): Promise<object> {
const { href: cacheKey } = new URL(dataHref, window.location.href) // Do not cache RSC flight response since it's not a static resource
if (!this.isPreview && this.sdc[cacheKey]) {
return Promise.resolve({ fresh: false, data: this.sdc[cacheKey] })
}
return fetchNextData(dataHref, true, true, this.sdc, false).then( return fetchNextData(dataHref, true, true, this.sdc, false).then(
(serialized) => { (serialized) => {
this.sdc[cacheKey] = serialized
return { fresh: true, data: serialized } return { fresh: true, data: serialized }
} }
) )
......
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