-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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(html)!: align html serving between dev and preview #14756
Conversation
Co-authored-by: 翠 / green <[email protected]>
Run & review this pull request in StackBlitz Codeflow. |
I think it would be better for @sapphi-red to review this one, but it looks good to me. I like moving away from |
Sapphi recommended to check with https://github.com/slorber/trailing-slash-guide, so here's the new comparison against it:
The main difference is that we don't really do redirects if a trailing slash is needed/missing. And we don't do rewrites which can be dangerous when there's relative paths in the html. So for the most part I think this PR is good. |
@bluwy your table looks very similar to this one : https://github.com/slorber/trailing-slash-guide |
Yeah I linked it in the comment above |
/ecosystem-ci run |
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks mostly good to me.
Would you update this part of the migration guide?
Lines 103 to 109 in ac5d8a7
### Allow path containing `.` to fallback to index.html | |
In Vite 4, accessing a path containing `.` did not fallback to index.html even if `appType` is set to `'SPA'` (default). | |
From Vite 5, it will fallback to index.html. | |
Note that the browser will no longer show the 404 error message in the console if you point the image path to a non-existent file (e.g. `<img src="./file-does-not-exist.png">`). | |
@@ -186,9 +189,25 @@ export async function preview( | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also align the base removal behavior? The dev server uses baseMiddleware
that stips the base so that the middlewares doesn't have to take base
into consideration.
vite/packages/vite/src/node/server/index.ts
Lines 649 to 652 in ac5d8a7
// base | |
if (config.base !== '/') { | |
middlewares.use(baseMiddleware(server)) | |
} |
vite/packages/vite/src/node/server/middlewares/base.ts
Lines 18 to 19 in ac5d8a7
// rewrite url to remove base. this ensures that other middleware does | |
// not need to consider base being prepended or not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure about this one. It would be a big breaking change I think for those expecting the base not removed in preview, and I think it's a bit late to make that change now 🤔
📝 Ran ecosystem CI on
|
Ah, the rerun posts a new message now. Astro and Vike seems to be affected by this breaking change. |
The Astro fail is expected at the moment because it expects the post middlewares to have already handled serving HTML files: https://github.com/withastro/astro/blob/46d3043a3f41a826061c79241d54ecbd106e4ddd/packages/astro/src/core/preview/vite-plugin-astro-preview.ts#L53-L66. That can be workaround with a cc @brillout for the Vike fail |
I found a different inconsistency between dev and preview. |
Alright I'll merge this first and we can try to fix that separately. Looks like we might need the |
It seems like every |
Thanks for the update @brillout. Sorry I had to merge before getting your input, as I'd like to unblock the continuing PRs and would like the finish up the 5.0 milestone soon. Let me know if you found any issues with it and I'll try to get it fixed. |
👍 No problems and, yes, I'll keep you udpated about my findings. |
@bluwy Seems like a bug: upon requesting |
I guess it's intentional because of |
Does the latest vite version already come with this fix? |
Yes, this PR has been released in Vite 5.0. Please create a new issue with a minimal reproduction. The comment here will be lost soon. |
Description
Supersedes #11289
Fixes #6596
Fixes #14690
New behaviour:
nested/index.html
nested/index.html
nested/index.html
nested/index.html
nested
index.html
(mpa 404)nested/index.html
index.html
(mpa 404)nested/
nested/index.html
nested/index.html
nested/index.html
non-nested.html
non-nested.html
non-nested.html
non-nested.html
non-nested
index.html
(mpa 404)non-nested.html
non-nested.html
non-nested/
index.html
(mpa 404)non-nested.html
index.html
(mpa 404)Additional context
HTML files now also don't have
charset=utf-8
by default. I'm not really sure how to handle that and I've come to agree that it's also off that it's misaligned. Previouslycharset=utf-8
is automatically added bysirv
by default in preview, but not in dev.Also removed
connect-history-api-fallback
and implement the fallback ourselves.What is the purpose of this pull request?