-
-
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: consistent html handling between dev and preview #11289
Conversation
app.use( | ||
previewBase, | ||
htmlFallbackMiddleware(distDir, config.appType === 'spa'), | ||
) |
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.
We could add a middleware here to support rewriting /foo
to /foo.html
. I didn't implement it because it wasn't supported in dev.
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.
Would it be possible to add an option in preview
to skip the shouldServe
and let sirv
handle it?.
That would allow frameworks like îles to configure the preview
to work in a way that is consistent with the deployment target (which might resolve /foo
to /foo.html
).
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 think that is possible by injecting a middleware by the post configurePreviewServer
hook, too.
In that way, I think we can have the same behavior in dev by injecting that middleware by configureServer
hook.
fetchPath('nested/index.html'), // -> nested/index.html | ||
fetchPath('nested'), // -> index.html | ||
fetchPath('nested/'), // -> nested/index.html | ||
|
||
fetchPath('non-nested.html'), // -> non-nested.html | ||
fetchPath('non-nested'), // -> index.html | ||
fetchPath('non-nested/'), // -> index.html |
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.
With dev server, these tests passes without this PR.
With preview server and without this PR, these tests resolved to
nested/index.html
->nested/index.html
nested
->nested/index.html
(changed, Inconsistent URL trailing slash behavior between dev and preview servers #6596)nested/
->nested/index.html
non-nested.html
->non-nested.html
non-nested
-> 404 (changed, Routing broken for preview with react-router-dom in 4.0.0-alpha.2 #10925)non-nested/
-> 404 (changed, Routing broken for preview with react-router-dom in 4.0.0-alpha.2 #10925)
Interesting, I agree that the extra complexity is worth it. @benmccann @bluwy @ElMassimo @brillout would you help us review this PR? It is a big change for a patch but given the regression and that it only affects preview, I think we should move forward with it as soon as we agree this is good for all of you. |
lgtm as long as we can run the ecosystem CI against this before merge and it passes our tests. sorry for causing the regression here and thank you so much for investigating and fixing it!! ❤️ 💯 |
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
Would it be simpler if we patch We could probably add the case-sensitive check here by exposing another option. Also it seems like for |
I don't think patching is a good thing in terms of maintainability for the long run, given that case sensitivity feature might not land in sirv (lukeed/sirv#141 (comment)).
If we wanted to align the preview and dev server behavior, I think we cannot avoid this complexity. |
I don't think the preview server needs to align with the dev server. The preview server should be allowed to implement a superset of what dev supports to mimic production behaviour, so I'm not sure if the breaking change is needed.
|
The last commit to sirv was one year ago. I agree with @bluwy that keeping a patch for it shouldn't bring much maintenance overhead for us. We may also want to check out alternatives to sirv. There aren't many issues, but @sapphi-red issue hasn't been addressed for example lukeed/sirv#138. |
That's a must-have for SSGs (i.e. pre-rendered apps), since the HTML is served statically from As for the rest of the PR, I lack the context to provide feedback. That said, further aligning the
Since On a high level I'd say: |
Does that help? I think
sirv's a single file and is less than 200 lines, so we could copy it into the project and modify it as needed.
I guess this would be the main one? http://expressjs.com/en/resources/middleware/serve-static.html It has an
That looks like an easy one. I just sent a PR: lukeed/sirv#149
@brillout to confirm, when you say "that PR", do you mean this PR? |
Yeah I was on my phone so I omitted the params, but it should be like |
This sounds good to me. Less complexity than keeping the patch, and no maintainance overhead of external users asking for features. And if later there are a lot of changes in sirv and becomes active we could go back to use it as a dep instead of tracking them. I think we will also benefit by having the code in ts directly explorable in Vite's source. |
I've created a PR that patches sirv (#11312). I think we should go with #11312, while we discuss about this PR. I still think it would be nice to align preview and dev server behavior. But I can understand that the complexity might not worth it. Also I think having vite/packages/vite/src/node/server/middlewares/static.ts Lines 137 to 148 in 42976d8
|
Yes |
There is another regression: #11346. |
Do we still need to keep this PR given we've merged #11312? |
I still think it would be nice to align the dev/preview server behavior. |
Description
I thought it difficult to use
sirv
'ssingle: true
andextensions
feature withshouldServe
. We could use those, but we will still need to implement those behaviors toshouldServe
on our side.So instead of relying on
sirv
, this PR makes preview server to use the same middlewares with the dev server.This is a possible breaking change, because the preview server's behavior is now aligned to the dev server's behavior. For example,
/foo
won't be resolved to/foo.html
.fixes #6596
fixes #10925
superseds close #10944
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).