@@ -57,7 +57,6 @@ import {
5757 NEXT_URL ,
5858 RSC_HEADER ,
5959 NEXT_ROUTER_SEGMENT_PREFETCH_HEADER ,
60- NEXT_HMR_REFRESH_HASH_COOKIE ,
6160 NEXT_REQUEST_ID_HEADER ,
6261 NEXT_HTML_REQUEST_ID_HEADER ,
6362} from '../../client/components/app-router-headers'
@@ -178,6 +177,7 @@ import {
178177} from './app-render-render-utils'
179178import { waitAtLeastOneReactRenderTask } from '../../lib/scheduler'
180179import {
180+ getHmrRefreshHash ,
181181 workUnitAsyncStorage ,
182182 type PrerenderStore ,
183183} from './work-unit-async-storage.external'
@@ -782,10 +782,11 @@ async function generateDynamicFlightRenderResultWithStagesInDev(
782782 onFlightDataRenderError
783783 )
784784
785- // If we decide to validate this render we will assign this function when the
786- // payload is constructed.
787- let resolveValidation : null | ReturnType < typeof createValidationOutlet > [ 0 ] =
788- null
785+ // We only validate RSC requests if it is for HMR refreshes since we know we
786+ // will render all the layouts necessary to perform the validation.
787+ const shouldValidate =
788+ ! isBypassingCachesInDev ( renderOpts , initialRequestStore ) &&
789+ initialRequestStore . isHmrRefresh === true
789790
790791 const getPayload = async ( requestStore : RequestStore ) => {
791792 const payload : RSCPayload &
@@ -803,18 +804,9 @@ async function generateDynamicFlightRenderResultWithStagesInDev(
803804 payload . _bypassCachesInDev = createElement ( WarnForBypassCachesInDev , {
804805 route : workStore . route ,
805806 } )
806- } else if ( requestStore . isHmrRefresh ) {
807- // We only validate RSC requests if it is for HMR refreshes since
808- // we know we will render all the layouts necessary to perform the validation.
809- // We also must add the canonical URL part of the payload
810-
811- // Placing the validation outlet in the payload is safe
812- // even if we end up discarding a render and restarting,
813- // because we're not going to wait for the stream to complete,
814- // so leaving the validation unresolved is fine.
815- const [ validationResolver , validationOutlet ] = createValidationOutlet ( )
816- resolveValidation = validationResolver
817- payload . _validation = validationOutlet
807+ } else if ( shouldValidate ) {
808+ // If this payload will be used for validation, it needs to contain the
809+ // canonical URL. Without it we'd get an error.
818810 payload . c = prepareInitialCanonicalUrl ( url )
819811 }
820812
@@ -855,7 +847,7 @@ async function generateDynamicFlightRenderResultWithStagesInDev(
855847 onError
856848 )
857849
858- if ( resolveValidation ) {
850+ if ( shouldValidate ) {
859851 let validationDebugChannelClient : Readable | undefined = undefined
860852 if ( returnedDebugChannel ) {
861853 const [ t1 , t2 ] = returnedDebugChannel . clientSide . readable . tee ( )
@@ -3587,14 +3579,6 @@ function createDebugChannel(): DebugChannelPair | undefined {
35873579 }
35883580}
35893581
3590- function createValidationOutlet ( ) {
3591- let resolveValidation : ( value : ReactNode ) => void
3592- let outlet = new Promise < ReactNode > ( ( resolve ) => {
3593- resolveValidation = resolve
3594- } )
3595- return [ resolveValidation ! , outlet ] as const
3596- }
3597-
35983582/**
35993583 * Logs the given messages, and sends the error instances to the browser as an
36003584 * RSC stream, where they can be deserialized and logged (or otherwise presented
@@ -3684,9 +3668,7 @@ async function spawnStaticShellValidationInDev(
36843668 getDynamicParamFromSegment
36853669 )
36863670
3687- const hmrRefreshHash = requestStore . cookies . get (
3688- NEXT_HMR_REFRESH_HASH_COOKIE
3689- ) ?. value
3671+ const hmrRefreshHash = getHmrRefreshHash ( workStore , requestStore )
36903672
36913673 // We don't need to continue the prerender process if we already
36923674 // detected invalid dynamic usage in the initial prerender phase.
0 commit comments