-
-
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: appType mpa #9865
fix: appType mpa #9865
Conversation
Could you explain a bit more here @brillout? And we should add a test case too. I thought not having the spa fallback was one of the reasons to have |
Why doesn't the index middleware work without the spa middleware and is that something we should fix? |
The reason for I unfortunately don't have the bandwidth to implement a test case. I found a workaround, so this is not urgent/important from my side. But I do think we should fix this for other folks. |
@brillout more than a test case, we need to understand why this is needed. I still don't get what are we fixing here. |
While vite/packages/vite/src/node/server/middlewares/spaFallback.ts Lines 17 to 24 in cc8800a
In other words:
I do agree that a proper fix would be to split out |
7ef90fc
to
d170896
Compare
d170896
to
dfc396a
Compare
Nevermind, I implemented another proper fix. See the latest commit. I believe everything is fixed now. |
@benmccann @matthewp @danielroe are you removing the spaFallbackMiddleware in SvelteKit, Astro, Nuxt using its function name? I would like to check if applying this fix in 3.1 is safe. If not, we will need to create another middleware, but that would also be breaking if you need to remove it. Another option is to wait until Vite 4, but this looks like a bug we should fix sooner. |
We are not using |
@danielroe to clarify, it isnt about using it, but if you are manually removing it by function name. If you are removing this middleware, then your app could break as the name is going to change. |
Thanks for the feedback @matthewp, I see you are now using If that is the case, then you don't need to remove by hand this middleware anymore (from Vite 3). And you shouldn't be affected by this PR either. vite/packages/vite/src/node/server/index.ts Line 544 in 2d2f2e5
|
@bluwy SvelteKit is also using |
Yup SvelteKit is using custom too. |
@@ -4,8 +4,9 @@ import history from 'connect-history-api-fallback' | |||
import type { Connect } from 'types/connect' | |||
import { createDebugger } from '../../utils' | |||
|
|||
export function spaFallbackMiddleware( | |||
root: string | |||
export function rewriteUrlMiddleware( |
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.
Just me being really nitpicky, but I feel like htmlFallbackMiddleware
better reflects its usecase 🤔
const historySpaFallbackMiddleware = history({ | ||
logger: createDebugger('vite:spa-fallback'), |
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.
Perhaps we want to change the names here too.
return `/index.html` | ||
if (spaFallback) { | ||
return `/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.
Few lines below we have:
return function viteSpaFallbackMiddleware(req, res, next) {
return historySpaFallbackMiddleware(req, res, next)
}
so technically we're still preserving the old function name (so someone can remove it). If appType
is the blessed way forward, we could say that the middleware function names aren't part of the public API following semver? And change it too? 🤔
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.
Oh, I didn't see that the name was not yet changed.
Yes, I think we should rename it to htmlFallbackMiddleware
in this PR, since everyone in v3 that doesn't want the HTML middleware is using appType: custom
I think we could do this change in Vite 3.1.
I just checked to confirm - we don't remove |
@patak-dev curious what is the status of this PR, as I see this is the last issue blocking 3.2. |
@jiby-aurum This PR needs a rebase and the naming changes discussed above. If you'd like to help out that'd be great! You can submit a PR to brillout's fork or open a new PR here with the updated changes. |
Description
Fix
appType: 'mpa'
which currently doesn't work:indexHtmlMiddleware()
doesn't work withoutspaFallbackMiddleware()
. In other words MPAs also needspaFallbackMiddleware()
.This seems to have been a glitch we missed at #8452.
Additional context
This is a blocker for Telefunc.
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).