-
-
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: $ vite preview
404 handling
#7665
Conversation
Maybe we should have an
Maybe the option should also remove the spa fallback from dev for example. @benmccann, are you also removing this middleware by hand, no? |
I don't know of any SPA that is deployed to multiple URLs. For example https://www.photopea.com/ is only deployed to Considering this, I don't see the added value of having such SPA fallback. Or am I missing something? If we don't see the added value, I'd argue we should remove the SPA fallback altogether. |
For MPAs, maybe it makes sense for So I think |
vps injects a SSR middleware using This enables vps users to simply run This is not only for vps users but also for vps frameworks I am / folks are building. (E.g. Vilay which is a Vite + vps + Relay framework.)
👍 Good idea. This is what Static Hosts actually do.
I'm reluctant about this. It's quite an uncommon behavior. I don't see why |
single
to false
$ vite preview
404 handling
Done. |
I'm seeing this is marked for the Note that the current behavior is quite weird for SSR apps. Imagine you make a typo in the URL and then you see your landing page, that's weird and makes it seem like a bug (I actually dug at the wrong place when this first occurred to me). I think it's bad enough to postpone vps's support for Vite's CLI until this is fixed. I think the PR's current state is good to be merged. But let me know if there are any questions. |
Checking Vite's guide for static deployment, it looks like only the Google Firebase guide showed how to rewrite the path for SPAs. So yeah I think it make sense to remove In the future maybe we could explore ways to simplify redirects if the user wants to configure them. |
Yes, we are removing this middleware. I recently created #7631 discussing it
Do you mean |
@benmccann https://github.com/brillout/vite-plugin-ssr/blob/60d905d49572f9e7a9aa812d1ae7c57ac51ea63e/vite-plugin-ssr/node/plugin/plugins/chainBuildSteps.ts. As you can see, it also executes pre-rendering. |
Also relevant to this discussion: |
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.
lgtm. I agree this wouldn't necessarily have to wait until 3.0
@brillout I'm curious, what will handle SSR when you use Vite's preview server?
FYI: this is maybe more breaking than expected, as all apps using create-vue (recommended setup for Vue 3) are relying on This means e2e tests start breaking when bumping vite to v2.9.2 if they do something like I think this change should be listed as breaking? |
@cexbrayat Are you sure your problem is related to this PR? If your |
@benmccann See #7658. |
@cexbrayat @brillout if this is really breaking, we should revert and in any case evaluate it for v3. |
@brillout because it's a Vue 3 SPA, and create-vue uses If there is no way to configure this option directly, maybe this should be reverted, as I suppose a lot Vue 3 users (those who write e2e tests) will run into this. |
Precisely, that's not the case. See #7665 (comment). As for tests: if your
I don't see that for the same reason: why would users test a page that doesn't exist? |
I'm not a Vue user, but I think I understand what's going on here. I think the idea is that the server is configured to respond with I think Vue's behavior is not a good default, but we probably shouldn't change it in 2.9. I would say the behavior with this PR is a better default and then in 3.0 we can make Vue's behavior behind a flag like |
I see. @patak-dev I'm 👍 for reverting. I'll re-create this PR with a flag For |
Thanks @brillout, we can discuss there the specifics. The flag may need to be global if it would affect the dev and preview server. It could also end up removing the SPA fallback middleware from the dev server that @benmccann is looking to get rid of by default. |
@patak-dev 👍 Sounds like a plan. |
@cexbrayat thanks for the quick feedback! vite@2.9.3 has been released reverting this PR |
@brillout Sorry if I was not clear: most JS frameworks aiming at building a SPA offer a router that takes care of the navigation client-side. So when you deploy your app, you configure your server to serve index.html for every request. Then the router does its thing and Thanks @patak-dev for the quick revert and release |
That makes a lot of sense. Thanks for the explanation @cexbrayat @benmccann. |
This PR is resurrected at #8061. |
Is still have this problem? When I set |
Description
When running a production preview with
$ vite preview
, Vite fallbacks 404 pages to the landing page/
. See thedirv
optionsingle
:Currently this option is set to
true
and this PR changes it tofalse
.I guess Vite used to assume that every Vite app was an SPA, but that's not really the case anymore.
For MPA and SSR apps, having a 404 page be the landing page
/
is quite an unexpected behavior.We could make this a config, but I don't think it's worth it. I think it's fine if
$ vite preview
serves SPAs only at/
. (I would even argue that it's better, as it's a more truthful representation and preview of production.)Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).