Skip to content

Commit c9614b9

Browse files
authored
fix: remove special handling for Accept: text/html (#20376)
1 parent 862e192 commit c9614b9

File tree

4 files changed

+6
-25
lines changed

4 files changed

+6
-25
lines changed

packages/vite/src/node/plugin.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,6 @@ export interface Plugin<A = any> extends RollupPlugin<A> {
144144
id: string,
145145
options?: {
146146
ssr?: boolean
147-
/**
148-
* @internal
149-
*/
150-
html?: boolean
151147
},
152148
) => Promise<LoadResult> | LoadResult,
153149
{ filter?: { id?: StringFilter } }

packages/vite/src/node/publicDir.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import fs from 'node:fs'
21
import path from 'node:path'
32
import { cleanUrl, withTrailingSlash } from '../shared/utils'
43
import type { ResolvedConfig } from './config'
54
import {
65
ERR_SYMLINK_IN_RECURSIVE_READDIR,
76
normalizePath,
87
recursiveReaddir,
8+
tryStatSync,
99
} from './utils'
1010

1111
const publicFilesMap = new WeakMap<ResolvedConfig, Set<string>>()
@@ -60,5 +60,5 @@ export function checkPublicFile(
6060
return
6161
}
6262

63-
return fs.existsSync(publicFile) ? publicFile : undefined
63+
return tryStatSync(publicFile)?.isFile() ? publicFile : undefined
6464
}

packages/vite/src/node/server/middlewares/transform.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ export function transformMiddleware(
263263

264264
// resolve, load and transform using the plugin container
265265
const result = await transformRequest(environment, url, {
266-
html: req.headers.accept?.includes('text/html'),
267266
allowId(id) {
268267
return (
269268
id.startsWith('\0') ||

packages/vite/src/node/server/transformRequest.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ export interface TransformOptions {
5353
* @deprecated inferred from environment
5454
*/
5555
ssr?: boolean
56-
/**
57-
* @internal
58-
*/
59-
html?: boolean
6056
/**
6157
* @internal
6258
*/
@@ -84,8 +80,6 @@ export function transformRequest(
8480
if (environment._closing && environment.config.dev.recoverable)
8581
throwClosedServerError()
8682

87-
const cacheKey = `${options.html ? 'html:' : ''}${url}`
88-
8983
// This module may get invalidated while we are processing it. For example
9084
// when a full page reload is needed after the re-processing of pre-bundled
9185
// dependencies when a missing dep is discovered. We save the current time
@@ -108,7 +102,7 @@ export function transformRequest(
108102
// last time this module is invalidated
109103
const timestamp = monotonicDateNow()
110104

111-
const pending = environment._pendingRequests.get(cacheKey)
105+
const pending = environment._pendingRequests.get(url)
112106
if (pending) {
113107
return environment.moduleGraph
114108
.getModuleByUrl(removeTimestampQuery(url))
@@ -135,13 +129,13 @@ export function transformRequest(
135129
let cleared = false
136130
const clearCache = () => {
137131
if (!cleared) {
138-
environment._pendingRequests.delete(cacheKey)
132+
environment._pendingRequests.delete(url)
139133
cleared = true
140134
}
141135
}
142136

143137
// Cache the request and clear it once processing is done
144-
environment._pendingRequests.set(cacheKey, {
138+
environment._pendingRequests.set(url, {
145139
request,
146140
timestamp,
147141
abort: clearCache,
@@ -270,11 +264,6 @@ async function loadAndTransform(
270264
if (loadResult == null) {
271265
const file = cleanUrl(id)
272266

273-
// if this is an html request and there is no load result, skip ahead to
274-
// SPA fallback.
275-
if (options.html && !id.endsWith('.html')) {
276-
return null
277-
}
278267
// try fallback loading it from fs as string
279268
// if the file is a binary, there should be a plugin that already loaded it
280269
// as string
@@ -288,10 +277,7 @@ async function loadAndTransform(
288277
code = await fsp.readFile(file, 'utf-8')
289278
debugLoad?.(`${timeFrom(loadStart)} [fs] ${prettyUrl}`)
290279
} catch (e) {
291-
if (e.code !== 'ENOENT') {
292-
if (e.code === 'EISDIR') {
293-
e.message = `${e.message} ${file}`
294-
}
280+
if (e.code !== 'ENOENT' && e.code !== 'EISDIR') {
295281
throw e
296282
}
297283
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy