Skip to content

fix: remove special handling for Accept: text/html #20376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/vite/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ export interface Plugin<A = any> extends RollupPlugin<A> {
id: string,
options?: {
ssr?: boolean
/**
* @internal
*/
html?: boolean
},
) => Promise<LoadResult> | LoadResult,
{ filter?: { id?: StringFilter } }
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/publicDir.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import fs from 'node:fs'
import path from 'node:path'
import { cleanUrl, withTrailingSlash } from '../shared/utils'
import type { ResolvedConfig } from './config'
import {
ERR_SYMLINK_IN_RECURSIVE_READDIR,
normalizePath,
recursiveReaddir,
tryStatSync,
} from './utils'

const publicFilesMap = new WeakMap<ResolvedConfig, Set<string>>()
Expand Down Expand Up @@ -60,5 +60,5 @@ export function checkPublicFile(
return
}

return fs.existsSync(publicFile) ? publicFile : undefined
return tryStatSync(publicFile)?.isFile() ? publicFile : undefined
}
1 change: 0 additions & 1 deletion packages/vite/src/node/server/middlewares/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ export function transformMiddleware(

// resolve, load and transform using the plugin container
const result = await transformRequest(environment, url, {
html: req.headers.accept?.includes('text/html'),
allowId(id) {
return (
id.startsWith('\0') ||
Expand Down
22 changes: 4 additions & 18 deletions packages/vite/src/node/server/transformRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ export interface TransformOptions {
* @deprecated inferred from environment
*/
ssr?: boolean
/**
* @internal
*/
html?: boolean
/**
* @internal
*/
Expand Down Expand Up @@ -84,8 +80,6 @@ export function transformRequest(
if (environment._closing && environment.config.dev.recoverable)
throwClosedServerError()

const cacheKey = `${options.html ? 'html:' : ''}${url}`

// This module may get invalidated while we are processing it. For example
// when a full page reload is needed after the re-processing of pre-bundled
// dependencies when a missing dep is discovered. We save the current time
Expand All @@ -108,7 +102,7 @@ export function transformRequest(
// last time this module is invalidated
const timestamp = monotonicDateNow()

const pending = environment._pendingRequests.get(cacheKey)
const pending = environment._pendingRequests.get(url)
if (pending) {
return environment.moduleGraph
.getModuleByUrl(removeTimestampQuery(url))
Expand All @@ -135,13 +129,13 @@ export function transformRequest(
let cleared = false
const clearCache = () => {
if (!cleared) {
environment._pendingRequests.delete(cacheKey)
environment._pendingRequests.delete(url)
cleared = true
}
}

// Cache the request and clear it once processing is done
environment._pendingRequests.set(cacheKey, {
environment._pendingRequests.set(url, {
request,
timestamp,
abort: clearCache,
Expand Down Expand Up @@ -270,11 +264,6 @@ async function loadAndTransform(
if (loadResult == null) {
const file = cleanUrl(id)

// if this is an html request and there is no load result, skip ahead to
// SPA fallback.
if (options.html && !id.endsWith('.html')) {
return null
}
// try fallback loading it from fs as string
// if the file is a binary, there should be a plugin that already loaded it
// as string
Expand All @@ -288,10 +277,7 @@ async function loadAndTransform(
code = await fsp.readFile(file, 'utf-8')
debugLoad?.(`${timeFrom(loadStart)} [fs] ${prettyUrl}`)
} catch (e) {
if (e.code !== 'ENOENT') {
if (e.code === 'EISDIR') {
e.message = `${e.message} ${file}`
}
if (e.code !== 'ENOENT' && e.code !== 'EISDIR') {
throw e
}
}
Expand Down
Loading