@@ -40,6 +40,17 @@ const debugCache = createDebugger('vite:cache')
4040
4141const knownIgnoreList = new Set ( [ '/' , '/favicon.ico' ] )
4242
43+ const documentFetchDests = new Set ( [
44+ 'document' ,
45+ 'iframe' ,
46+ 'frame' ,
47+ 'fencedframe' ,
48+ ] )
49+ function isDocumentFetchDest ( req : Connect . IncomingMessage ) {
50+ const fetchDest = req . headers [ 'sec-fetch-dest' ]
51+ return fetchDest !== undefined && documentFetchDests . has ( fetchDest )
52+ }
53+
4354// TODO: consolidate this regex pattern with the url, raw, and inline checks in plugins
4455const urlRE = / [ ? & ] u r l \b /
4556const rawRE = / [ ? & ] r a w \b /
@@ -63,6 +74,11 @@ export function cachedTransformMiddleware(
6374 return function viteCachedTransformMiddleware ( req , res , next ) {
6475 const environment = server . environments . client
6576
77+ if ( isDocumentFetchDest ( req ) ) {
78+ res . appendHeader ( 'Vary' , 'Sec-Fetch-Dest' )
79+ return next ( )
80+ }
81+
6682 // check if we can return 304 early
6783 const ifNoneMatch = req . headers [ 'if-none-match' ]
6884 if ( ifNoneMatch ) {
@@ -102,7 +118,8 @@ export function transformMiddleware(
102118
103119 if (
104120 ( req . method !== 'GET' && req . method !== 'HEAD' ) ||
105- knownIgnoreList . has ( req . url ! )
121+ knownIgnoreList . has ( req . url ! ) ||
122+ isDocumentFetchDest ( req )
106123 ) {
107124 return next ( )
108125 }
0 commit comments