Skip to content
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

querySelector no longer works correctly with comma separated selectors if first selector does not match #3666

Open
nrkn opened this issue Jan 18, 2024 · 2 comments

Comments

@nrkn
Copy link

nrkn commented Jan 18, 2024

Basic info:

  • Node.js version: v20.11.0
  • jsdom version: v23.2.0

Minimal reproduction case

import { JSDOM } from 'jsdom'

const html = `
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
  </head>
  <body>
    <p>One</p>
    <span>Two</span>
  </body>
</html>
`

const dom = new JSDOM(html)

const { document } = dom.window

const pOrSpan = document.querySelector('p, span')

// correct - it's p
console.log( pOrSpan )

// fails if the first option doesn't exist!
const divOrSpan = document.querySelector('div, span')

// should be span - but it's null!
console.log( divOrSpan )

// however, this works
const spanOrDiv = document.querySelector('span, div')

console.log( spanOrDiv )

How does similar code behave in browsers?

In browsers, it selects the second option if the first doesn't exist - and same for previous version of JSDOM

@asamuzaK
Copy link
Contributor

Thanks for the catch.
Fixed upstream.

Please try again with the latest development build of dom-selector.

npm i --save-dev @asamuzakjp/dom-selector@next

@nrkn
Copy link
Author

nrkn commented Jan 22, 2024

Thanks, unfortunately I'm still getting null with the divOrSpan example above after installing latest dom-selector

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants