Skip to content

Conversation

@MichaelWest22
Copy link
Collaborator

@MichaelWest22 MichaelWest22 commented Apr 17, 2025

Description

I've looked at all cases of IE fallbacks that can be removed now that IE 11 is no longer supported by htmx 2.x.
I've included all possible old browser compatibility checks I could find but it may be possible to roll back some of these changes

As well as just safely removing dead un-needed fallbacks I also found three bugs that the removals have also forced me to address

1st is NormalizePath() which does not function at all as calling new URL(path) without an origin domain added as a second parameter is designed to throw errors every time causing the IE11 fallback to happen for ALL calls to normalizePath and this fallback does zero normalization. I don't think this lost functionality would have caused big issues as this function is only used to set and restore paths to history so even if it is broken it was consistently broken so broken paths going into history cache came out with the same non normalized path most of the time. After this change it normalizes properly again

2nd I found shadow dom tests were calling process/init node on the shadow dom root node itself which are not possible to init properly because this node can't have attributes. The IE fallback was preventing any errors but it was leaving rubbish htmx internal data on the shadow root nodes then. only processing elements resolved the shadow dom tests failing.

3rd there is a minor issue where after removing the IE fallback for if verifyPath() I found situations where new URL() will fail if things like srcdoc iframes have invalid origins. Found using window.origin as a fallback when these null origins from about: protocol situations resolved the issue.

Corresponding issue:

Testing

Performed extensive testing with the test suite and used my work on the loc coverage reporting to track down and test the dead branches.

Checklist

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded
function matches(elt, selector) {
// @ts-ignore: non-standard properties for browser compatibility
// noinspection JSUnresolvedVariable
const matchesFunction = elt instanceof Element && (elt.matches || elt.matchesSelector || elt.msMatchesSelector || elt.mozMatchesSelector || elt.webkitMatchesSelector || elt.oMatchesSelector)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all supported browsers have long since moved to support .matches in the last 10 years so we don't need this fallback now

src/htmx.js Outdated
return
}
// Ensure only valid Elements and not shadow DOM roots are inited
if (elt instanceof Element) return
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensure only elements that can have attribute which need hashing and can have hx-attributes are processed to avoid processing shadow dom root nodes

} else if (console.log) {
console.log('ERROR: ', msg)
}
console.error(msg)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.error is standard in all supported browsers now

Copy link
Collaborator

@Telroshan Telroshan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good riddance if you ask me!

@Telroshan Telroshan added ready for review Issues that are ready to be considered for merging 2.0 labels Apr 20, 2025
@1cg 1cg merged commit 05d37e6 into bigskysoftware:dev Apr 24, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.0 ready for review Issues that are ready to be considered for merging

3 participants