-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[bug] Handle missing selectors for closest/find/next/previous #2915
[bug] Handle missing selectors for closest/find/next/previous #2915
Conversation
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.
Nice, simple & effective fix!
If we merge in #2902 first then this PR would need to be updated to use |
actually to merge this fix into #2902 you can simplify it down to this: let item
if (selector.indexOf('closest ') === 0) {
item = closest(asElement(elt), normalizeSelector(selector.substr(8)))
} else if (selector.indexOf('find ') === 0) {
item = find(asParentNode(elt), normalizeSelector(selector.substr(5)))
} else if (selector === 'next' || selector === 'nextElementSibling') {
item = asElement(elt).nextElementSibling
} else if (selector.indexOf('next ') === 0) {
item = scanForwardQuery(elt, normalizeSelector(selector.substr(5)), !!global)
} else if (selector === 'previous' || selector === 'previousElementSibling') {
item = asElement(elt).previousElementSibling
} else if (selector.indexOf('previous ') === 0) {
item = scanBackwardsQuery(elt, normalizeSelector(selector.substr(9)), !!global)
} else if (selector === 'document') {
item = document
} else if (selector === 'window') {
item = window
} else if (selector === 'body') {
item = document.body
} else if (selector === 'root') {
item = getRootNode(elt, !!global)
} else {
// Push back the unaltered string part, so that the standard selector fallback uses the exact initial string
unprocessedParts.push(selector)
}
item && result.push(item) Where you change it from pushing to the array each time to assign to a let variable and then only push at the end if item is not null or undefined which handles the null case well. |
Yep makes sense @MichaelWest22 |
Co-Authored-By: MichaelWest22 <[email protected]>
Merged your changes in #2902, closing this one! |
Support multiple extended selectors for hx-include Additional test for nested standard selector Add @MichaelWest22 hx-disabled-elt multiple selector test Add hx-trigger `from` test with multiple extended selectors Simplify Include bigskysoftware#2915 fix Update htmx.js Split for readability Don't apply global to previous selectors Rewrite loop, restore global recursive call, minimize diff Use break for better readability Co-Authored-By: MichaelWest22 <[email protected]>
Support multiple extended selectors for hx-include Additional test for nested standard selector Add @MichaelWest22 hx-disabled-elt multiple selector test Add hx-trigger `from` test with multiple extended selectors Simplify Include bigskysoftware#2915 fix Update htmx.js Split for readability Don't apply global to previous selectors Rewrite loop, restore global recursive call, minimize diff Use break for better readability Co-Authored-By: MichaelWest22 <[email protected]>
Description
when using some of the custom selector modes like find etc it now wraps the response in an array. But when there happens to be no elements found it then wraps the null which will throw exceptions up the chain so we need to get it to return empty array instead.
Corresponding issue:
#2913
Testing
Added test and did manual testing to confirm find etc does not throw errors anymore when no elements are found
Checklist
master
for website changes,dev
forsource changes)
approved via an issue
npm run test
) and verified that it succeeded