Skip to content
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

fix(indexHtml): ensure correct URL when querying module graph #19601

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

OnlyWick
Copy link
Contributor

@OnlyWick OnlyWick commented Mar 7, 2025

Description

closes: #19135

Just adjust the order of code execution.

The main reason is that the URL during preTransformRequest may be inconsistent. For example, converting ./src/main.js to /src/main.js.

let preTransformUrl: string | undefined
if (url[0] === '/' && url[1] !== '/') {
preTransformUrl = url
} else if (url[0] === '.' || isBareRelative(url)) {
preTransformUrl = path.posix.join(
config.base,
path.posix.dirname(htmlPath),
url,
)
}

Later, storing /src/main.js in urlToModuleMap.

preTransformRequest(server, preTransformUrl, config.decodedBase)

When HMR is triggered, the value will be retrieved based on ./src/main.js instead of /src/main.js, which will not access the previously stored data.

if (server) {
const mod = server.environments.client.moduleGraph.urlToModuleMap.get(url)
if (mod && mod.lastHMRTimestamp > 0) {
url = injectQuery(url, `t=${mod.lastHMRTimestamp}`)
}
}

@OnlyWick OnlyWick force-pushed the fix-vite-2025-03-07 branch from 1428058 to 3ce23c0 Compare March 7, 2025 05:47
@OnlyWick OnlyWick changed the title fix(html): ensure correct URL when querying module graph fix(indexHtml): ensure correct URL when querying module graph Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dev server resolving file paths inconsistently causing duplicated imports after hot load
1 participant