Make hx-header and hx-vals JS eval more consistent with expectations #2673
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.
... while also preserving deprecated
hx-vars
functionality.Description
Corresponding issue: #2619
The docs don't make it clear that the underlying
getValuesForElement
function adds curly braces for anything without, even when evaluating JS, causing weird cases where you can't just eval a function to add headers, you have to wrap in curly braces and spread the result.This change makes it so anything in the string after js: or javascript: will be treated as you would normally expect an eval to go, while making it clear in the code that the curly-brace placement only applies for deprecated
hx-vars
.Docs for
hx-headers
also updated with an example, similar tohx-vals
, which uses the same function under the hood to evaluate.Testing
Tests have been updated and code updated to match to make code execution possible.
Checklist
master
for website changes,dev
forsource changes)
approved via an issue
npm run test
) and verified that it succeeded