I've come across an issue where a user can go to a certain page, go to a new page, press the chrome back button (happens with all major browsers) and some elements will be duplicated.
The elements in question come from JavaScript within a partial view I am rendering as part of that page.
I have seen some people having this issue while using turbolinks, however I don't have that installed so I am not sure what is causing this issue.
I have tried putting bindings in Chrome dev console on the JavaScript that is run to create these elements, however on Chrome back button press, it doesn't trigger, so I'm not sure why they are being duplicated.
Below is what I'm doing to create the elements that are being duplicated:
theFieldset = document.getElementsByTagName("fieldset")[0];
editForm = document.getElementById("edit_pattern");
theFieldset.innerHTML += "<div class='form-group control-group belongs_to_association_type pattern_field ' id='pattern_html_block_id_field'><label class='col-sm-2 control-label' for='pattern_pattern_html_block'>Attach template</label><div class='controls col-sm-10' data-children-count='2'><select data-filteringselect='true' placeholder='Search' name='email[pattern_id]' id='pattern_pattern_html_block' style='display: none;'><option value=''></option></select><span class='help-block'>Optional. </span></div></div><div class='form-group control-group belongs_to_association_type pattern_field ' id='pattern_pattern_field' style='display:none'><label class='col-sm-2 control-label' for='currentTemplate'>Current template</label><div class='controls col-sm-10' data-children-count='2'></div><br><label class='col-sm-2 control-label' for='pattern_pattern_html_block'>Attach template</label><div class='controls col-sm-10' data-children-count='2'></div></div>";
Edit: Neither turbolinks nor hotwire is installed. Have been unsuccessful in trying to individually create elements and adding them to the fieldset rather than adding in bulk via innerHTML or insertAdjacentHTML.