-
Notifications
You must be signed in to change notification settings - Fork 12
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
Make element filtering configurable #40
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/
5f198c2
to
2709528
Compare
@keithamus could you review these changes? |
keithamus
approved these changes
Jan 21, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a sensible improvement. @github/web-systems need to review/merge this.
theinterned
approved these changes
Jan 23, 2024
@seanpdoyle thank you for the contribution! |
@seanpdoyle I just merged this, but realized that, like your other PRs it would be great to see
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduce support for a
{ storageFilter: (field) => boolean }
configuration override for calls topersistResumableFields
. 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:
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.