Incorrect form field value in Chrome using the back button #11165
Comments
This seems to be a regression on Chromium 79. I filled a bug there: https://bugs.chromium.org/p/chromium/issues/detail?id=1057463#makechanges |
is there any solution from vue js end??? |
I find it strange that this bug has received so little attention as Chrome is the most popular browser and this bug seems to affect every Vuejs form. Even the form on the official Vuejs documentation exhibits the same fault. At https://vuejs.org/v2/guide/forms.html#Text, fill the text box, click a link to another page, and then click the back button. You'll see that the message is blank but the text box is out of sync and contains the previous typed value. As the Chrome team as marked the related bug as WontFix, it seems it will be up to the Vuejs team to come up with a workaround. |
This problem affects every js framework, even raw javascript. As they said, the would look into fixing the regression if enough people at concerned. So please express the need in the reported issue |
you can do something like this. Resolved my problem as of now. in main js. window.addEventListener('pageshow', function() {
}) |
@mvgn new Vue({ |
@posva, I've commented on the Chrome bug, but I don't know enough to make a technical argument — can only say that other browsers are behaving as expected with Vuejs while Chrome is not. thanks @sandipbiswasbehala. I'm using Vuejs in a rails app and the default initialisation is with the DOMContentLoaded event, so I'm keeping that for other browsers and changed to the pageshow event just for Chrome. if (navigator.userAgent.indexOf('Chrome/') > 0) {
window.addEventListener('pageshow', () => {
new Vue({
render: (h) => h(App),
}).$mount('#app');
});
} else {
document.addEventListener('DOMContentLoaded', () => {
new Vue({
render: (h) => h(App),
}).$mount('#app');
});
} |
Thanks to @sandipbiswasbehala and @mvgn for the solution, it works perfect on Chrome but unfortunately im having the same issue on Opera. This is quite weird because they are both Chromium based even their dev tools are same. There should be a work around for this, which will solve this problem regardless of which browser. |
Okay i was digging down because this solution wasn't working for Opera, here is my work around: I found out that when i focus on one of the inputs all the other inputs was becoming empty or default(it is how it should be) So i tried to focus that input as soon as the component is mounted but it did not work. Then i set a time out to focus function then it worked. It seems like for some reason it needs a delay around 300ms to render the state normal. Basically i asynchronously rendered components which has forms now it seems like all of them works flawlessly here is one of them: const MainComponent = () => ({
component: import("./Searchbox/MainComponent"),
delay: 300,
}); Eventhough it works i have no clue why this behaviour exists in Chrome based browsers. Maybe someone else can explain it better. Here is the related link in vue docs: https://vuejs.org/v2/guide/components-dynamic-async.html |
On my machine at least, Chrome on OS X is showing the following user agent:
So the looking at user agent for the pageshow workaround doesn't work on Desktop (I haven't tested mobile yet). I can modify my
But I do not know other implications of this, whether it works in all browsers, etc. I have also noticed that this makes it so the prefilled form fields are reset to the components default values. Ideally Vue would pick up Chrome's prefilled form fields and bind them into its I'm also surprised this issue doesn't have more traction. |
Also running into this. |
with the autocomplete attribute you can prevent the browser from autofilling your form. However, users will also not receive suggestions anymore.
|
Just thought I'd add a bit more information on this. Wrapping I haven't found a way to reliably work around this issue in Chrome without breaking Safari. The Vue core contains this code:
https://github.com/vuejs/vue/blob/a9a303009a4267b7f12b956741b4e34dfdc6566f/src/core/util/env.js Which implies that testing the user agent is reliable. So I wonder whether I was mistaken when I commented previously that the Chrome user agent did not contain the string "chrome". In any case, my version of Chrome now does contain "chrome" so I will go back to inspecting the user agent string. |
I just used autocomplete="off" on the form inputs and now it shows the default values (or empty value if it's the case), but no more the cached values when hitting the back button. Hope it helps someone! |
I have a plain select component in a vue2 sfc and autocomplete="off" doesn't work for me :( will need to look into async component or this pageshow event |
Version
2.6.11
Reproduction link
https://jsfiddle.net/jc26tewa/
Steps to reproduce
What is expected?
It is expected that the input field be blank or that Vue recognises its current value and shows "Submitted message: Hello" after clicking on the Submit button.
What is actually happening?
In Chrome, the input field contains the value it had before leaving the page, but Vue thinks the field is empty, so nothing happens when you click on the Submit button. In other browsers, the input field is blank after clicking on the back button.
The text was updated successfully, but these errors were encountered: