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: normalize html path in transformIndexHtml() #18976

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

vanaigr
Copy link

@vanaigr vanaigr commented Dec 16, 2024

Problem

Currently, the url accepted by transformIndexHtml() is passed unaltered to applyHtmlTransforms().This causes issues if the url

  1. doesn't refer to a file (see SSR dev server "Pre-transform error: Failed to load url" for relative path #18964), or
  2. contains search parameters or hash (/index.html?a=b or index.html#id).

This is different from how default vite server and build behave; they use urls that refer to a file. (The server modifies urls in htmlFallbackMiddleware()).

Solution

I extracted html path normalization from htmlFallbackMiddleware() and used it in createDevHtmlTransformFn().

Fixes #18964

@vanaigr
Copy link
Author

vanaigr commented Dec 16, 2024

Also noticed that SSR guide uses req.originalUrl as the html url.

Not sure if this is known, but it doesn't work with base config option since the base removing middleware doesn't affect originalUrl.

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.

SSR dev server "Pre-transform error: Failed to load url" for relative path
2 participants