Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce support for a `{ storageFilter: (field) => boolean }` configuration override for calls to `persistResumableFields`. By default, preserve the existing behavior of rejecting fields where [value][] is equivalent to [defaultValue][]. This change is motivated by situations where an element's value is impacted by events or packages that change its `[value]` attribute directly. For example, consider the following sample code: ```html <input id="input" type="hidden" value="the default value"> <output id="output"></output> <button>Change</button> <script> const button = document.querySelector("button") const input = document.getElementById("input") const output = document.getElementById("output") output.textContent = input.defaultValue button.addEventListener("click", () => { input.setAttribute("value", "a new default value") output.textContent = input.defaultValue }) </script> ``` You can experiment with the code on [JSFiddle][]. Clicking the button changes the `<input>` element's `[value]` directly, which has a side-effect of change its `.defaultValue` as well. Within the context of `session-resume`, this means that any elements impacted by side-effects of other code on the page will always be omitted from being stored. This is especially incompatible with `<trix-editor>` elements provided by [Trix][] and [Action Text][]. [Trix]: https://trix-editor.org [Action Text]: https://edgeguides.rubyonrails.org/action_text_overview.html [value]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#value [defaultValue]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#defaultvalue [JSFiddle]: https://jsfiddle.net/1nwb4o23/
- Loading branch information