-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Allow preventing default actions of client.js #5763
Comments
You can disable HMR by set server.hmr to false. |
Ah, I forgot to mention that it would be preferrable to do it runtime through a UI control in our case |
The scene is a little too special. Maybe you can put a breakpoint on @vite/client to stop the page reload. |
I can agree that it is quite a special case and might be solvable with the conf option. There is another case also where this has come up which is:
Result: you are still on / after navigating to /hello which is quite unexpected |
Does anyone know if it's possible to get the method suggested by @cdauth in #6695 (comment) to work in Vite 5? I've upgraded to 5.1.1 and despite throwing in If I downgrade to 4.5.2 it works. |
I also encountered the same issue as @jacksleight . I'm just trying Vite out and considering to switch from Webpack. Refreshing the browser resets all state and is an incredibly intrusive action. I get the concern about leaving the app in a supposedly inconsistent state with the code - but why take the paternalistic approach? I am not a newbie. I know what I'm doing and I want to be in control (without losing HMR altogether). |
Here is a very hacky workaround that will definitely not work forever: if (import.meta.hot) {
// Prevent full reload, see https://github.com/vitejs/vite/issues/5763#issuecomment-1974235806
import.meta.hot.on('vite:beforeFullReload', (payload) => {
payload.path = "(WORKAROUND).html";
});
} |
@patak-dev Is there any chance you'd reconsider #6695 independently from this issue? That issue was closed in favor of this one, but I feel that one has a smaller scope than this issue and like @cdauth I would prefer to simply run my vite server with full reloads completely disabled. (Though unlike @cdauth, I don't care if this also disables hot reloads - I already run with Let me elaborate on why these full page reloads can be so painful: Imagine you are working on the current code and you notice some unexpected behavior. You want to keep your app loaded in this state so you can interact with it, but you also want to go check out an older revision and check the behavior there side-by-side. So you Hopefully that helps illustrate the pain. There are ways to work around this, but it would be ideal if we could just "set and forget" a vite option if we want to be in control of when our pages reload. |
Since #5763 (comment) no longer works and #17447 was closed and locked, here's another quick hack to disable the page refresh. Place this chicanery in your
|
I think this should be a setting in |
I'm on a team with many dozens of UI developers and this issue comes up a lot. And every time I have to explain: "Vite 4 allowed a hack to prevent the page reload, but Vite 5 does not." 🤷 There should absolutely be a config option for this. |
For me my workaround still works, both with Vite 5 and Vite 6. |
@cdauth What's your workaround? Everyone else has said theirs stopped working in Vite 5. |
@kaiyoma The one from #5763 (comment). |
Clear and concise description of the problem
Some users have brought up that they want live reload temporarily disabled.
The use case is that they are modifying styles in the browser inspector instead of modifying the project files. Once they are done with styles modifications, they go through their changes and copy them to the project files. If you have live reload enabled when you do this then a full page reload can take place after the first changes are copied to a project file and that file is saved. When this happens, all remaining changes are lost.
Suggested solution
Allow listeners like
vite:beforeFullReload
to callpayload.preventDefault()
which will stop client.js from taking any actions.Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: