22

I've found a new bug today. When I hammer a page close using a post where I've already posted an answer, there is an automated prompt that tells me that the page was added to my Saves.

If I hammer with a page where I haven't posted an answer, the bug is not presented.

I then go to my Saves, and I find that the dupe target was automatically added to my Saves.

I do not want to have to prune my Saves list every time I hammer a page.


Update hours later...

I just hammered another page closed and:

11
  • This bug doesn't appear to manifest when I hammer a question with a dupe target that I asked. BTW, were you the only close voter on the question that you hammered (where the target was added to Saves)?
    – cigien
    Commented Nov 2, 2022 at 4:43
  • Good additional feedback. Yes, both times that the bug occurred for me today, I was the lone close voter. Commented Nov 2, 2022 at 4:48
  • I think this bug has happened with bookmarks as well, when you closed it with the Enter key after pasting the target URL. Do you?
    – CodeCaster
    Commented Nov 2, 2022 at 7:09
  • Yes, I believe I do that consistently/habitually. I paste the dupe target link then press enter (instead of clicking the "Vote to close" button). Commented Nov 2, 2022 at 7:12
  • Maybe this bug can be refurbished into a feature :) close something and the target gets added to a saves list called "Duplicate Targets" Commented Nov 2, 2022 at 11:04
  • I think I got that. A couple of times now, I dupehammered a question and got an error show up. I suspect it might be where it tried to add a save but the pare also refreshed at the same time. Also, in both cases, the dupe targets were already in my saves - it could be either or both of these. But I didn't have an answer on the dupe. I think in both cases I pressed Enter to add the dupe, though.
    – VLAZ
    Commented Nov 2, 2022 at 11:44
  • 3
    Fun: it also works the other way around: if you add a save from the duplicate window, it acts as voting for that duplicate: i.sstatic.net/1tw4d.gif
    – VLAZ
    Commented Nov 3, 2022 at 15:42
  • 3
    Also the same can be seen in the duplicate editing window - hitting "save" will just act as if you've decided to add the question: i.sstatic.net/jnKou.gif
    – VLAZ
    Commented Nov 3, 2022 at 15:56
  • This sounds more like an accidental feature than a bug to me. Different strokes.... Commented Nov 4, 2022 at 5:55
  • @Karl I do a lot of hammering. I definitely do not want to bloat my Saves with all of that noise. I don't keep a master list of dupe targets. I do a natural Google search for dupe targets each time -- it serves me well. Commented Nov 4, 2022 at 5:58
  • If it's adding the target, then I probably already have it in Saves, and if I don't, I would want it there. I primarily use the feature to make it easier to find my common targets. Commented Nov 4, 2022 at 6:00

4 Answers 4

7

This issue was solved shortly after this bug was reported as a coincidence. Allowing the save button to appear in modals and other non-question places was causing a host of issues for the save functionality so the decision was made to disable the save button everywhere except on question pages. When this change was made, it prevented the save action from being performed in the close as duplicate modal which resolved the bug.

Still, I have added the type="button" attribute to the saves button for good measure which will hopefully prevent any issues like this down the road.

We greatly appreciate all of your help reproducing and reporting this bug, the detailed information made it easy to track down and see that it had already been resolved.

9

As VLAZ notes, "it also works the other way around: if you add a save from the duplicate window, it acts as voting for that duplicate".

The reason this is happening is that the save button is a <button> and the close modal is a <form> Per MDN:

  • If a button does not specify a form attribute, it's set to the ancestor <form>, if any
  • If the type attribute is not specified on the button, it defaults to submit for buttons associated with a form.

So when you click the save button, it submits the closure form, voting to close the question as a duplicate.

As for why voting for the duplicate closure also saves the target question, that's because submitting a form triggers its submit button's onClick. Try hitting enter in the textbox:

<form name="form" method="post">
    <input type="text" name="whatever">
    <button onClick="alert('Submit button clicked!');">Submit</button>
</form>

1
  • "I'm not entirely certain why voting for the duplicate closure also saves the target question, though." just to be clear - pressing Enter is what also causes a save. If you click the vote button with your mouse, then you don't also get a save.
    – VLAZ
    Commented Nov 3, 2022 at 16:48
6

Repro'd: I closed https://stackoverflow.com/questions/74287315/newtonsoft-json-jsonserializationexception-deserialize-the-current-json-array as a duplicate of Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON array by pasting the URL of the latter in the dupe-close-box and pressing Enter, and that caused me to "save" the latter question.

This would appear to be a regression, a comparable issue has happened during the "thanks" experiment.

1
4

I have created a temporary fix for this as a userscript.

Summary of the issue

To summarise the issue - the Saves button is <button> element which will submit forms by default. It is displayed in a <form> in the duplicate dialog.

  • Pressing the button will submit the form.
  • Pressing with Enter will automatically click the first button that allows submission of the form.

Solution

The Saves button is prevented from submitting forms by adding the attribute `type="button" to it. See How to prevent buttons from submitting forms.

The element still works as a simple button - all the Saves functionality is there, since it does not rely on any forms.

This adjustment is attempted on page load and every time content changes via an AJAX call, which covers all types of opening dialogs, reloading the content of posts, reviews, etc.

function fix() {
    document.querySelectorAll("button.js-saves-btn:not([type])")
        .forEach(el => el.setAttribute("type", "button"));
}

$(document).ajaxComplete(fix);
fix();

Installation

Install the userscript with: direct link

See the code on GitHub

2
  • Thanks for this patch, but the great majority of my volunteer time is done via my mobile phone (and I don't download userscripts on my work computer -- which I am on all day long). Commented Nov 4, 2022 at 6:42
  • 1
    @mickmackusa I'm only doing what I can, sorry. The real solution is for SE to fix this and stop making random buttons that aren't just buttons. This is a short-term solution for the 6-8 it takes for the real solution.
    – VLAZ
    Commented Nov 4, 2022 at 6:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .