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

Bug: DOMException [SyntaxError]: 'h1,h2' is not a valid selector #3706

Open
nbbaier opened this issue Apr 21, 2024 · 4 comments
Open

Bug: DOMException [SyntaxError]: 'h1,h2' is not a valid selector #3706

nbbaier opened this issue Apr 21, 2024 · 4 comments

Comments

@nbbaier
Copy link

nbbaier commented Apr 21, 2024

Basic info:

  • Node.js version: v21.6.2
  • jsdom version: 24.0.0

Minimal reproduction case

const { JSDOM } = require("jsdom");
const doc = new JSDOM(`<h1>Hello world</h1><h2>Goodbye world</h2>`);
console.log(doc.window.document.querySelectorAll("h1,h2"));

When I run the above code, I get the follow error trace:

DOMException [SyntaxError]: 'h1,h2' is not a valid selector
    at emit (/Users/nicholasbaier/thing/node_modules/nwsapi/src/nwsapi.js:557:17)
    at Object._querySelectorAll [as select] (/Users/nicholasbaier/thing/node_modules/nwsapi/src/nwsapi.js:1501:9)
    at DocumentImpl.querySelectorAll (/Users/nicholasbaier/thing/node_modules/jsdom/lib/jsdom/living/nodes/ParentNode-impl.js:78:26)
    at Document.querySelectorAll (/Users/nicholasbaier/thing/node_modules/jsdom/lib/jsdom/living/generated/Document.js:1051:58)
    at Object.<anonymous> (/Users/nicholasbaier/thing/index.js:4:33)
    at Module._compile (node:internal/modules/cjs/loader:1378:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
    at Module.load (node:internal/modules/cjs/loader:1212:32)
    at Module._load (node:internal/modules/cjs/loader:1028:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12)

How does similar code behave in browsers?

As expected, the error does not occur in browsers. See this jsbin

Note that this error does not occur in Deno, either. Minimal deno example:

import { JSDOM } from "https://esm.sh/jsdom@24.0.0";
const doc = new JSDOM(`<h1>Hello world</h1><h2>Goodbye world</h2>`);

console.log(doc.window.document.querySelectorAll("h1,h2"));

Output:

s [NodeList] {
  "0": s [HTMLHeadingElement] {},
  "1": s [HTMLHeadingElement] {}
}
@zombieJ
Copy link

zombieJ commented Apr 21, 2024

seems some deps updated make this bug.

@nin-o
Copy link

nin-o commented Apr 21, 2024

I also started getting this recently. It's not happening when downgrading from 24.0.0 to 23.2.0.

@elimau
Copy link

elimau commented Apr 22, 2024

I had this problem yesterday.
I was using jest-environment-jsdom rather than jsdom directly.
However, today, I uninstalled and installed jest-environment-jsdom and the problem mysteriously disappeared.

So out of curiosity, i just tested @nbbaier 's code using jsdom and it also seem to work.

No idea! Not sure why.

Can you try uninstall and install jsdom and see if your problem disappears?

@mootari
Copy link

mootari commented May 13, 2024

Try pinning nwsapi to 2.2.9 via overrides (npm) or resolutions (yarn).

Here's a package.json with a simple repro:

{
  "name": "nwsapi-regression",
  "version": "0",
  "scripts": {
    "test": "node -p -e 'new (require(\"jsdom\").JSDOM)().window.document.querySelector(\"h1,h2\")'"
  },
  "dependencies": { "jsdom": "24.0.0" },
  "overrides": { "nwsapi": "2.2.8" },
  "resolutions": { "nwsapi": "2.2.8" }
}

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

5 participants