Version
nwsapi@2.2.25 (regression from 2.2.24)
Reproduction
With jsdom@26.1.0, which accepts nwsapi through ^2.2.16:
const { JSDOM } = require('jsdom');
const dom = new JSDOM(
'<div class="subject"><span class="target"></span></div><div class="sibling"></div>',
);
const { document } = dom.window;
console.log(
document.querySelector('.target').matches('.subject:has(~ .sibling) .target'),
);
console.log(document.documentElement.matches(':has(~ p)'));
Expected
The expressions return true and false, respectively. That is the behavior with nwsapi@2.2.24.
Actual
Both paths can throw in nwsapi@2.2.25:
TypeError: Cannot read properties of null (reading 'children')
The same applies to adjacent-sibling relational selectors (:has(+ ...)) when matching reaches a root element.
This appears to be a regression of #145. The 2.2.25 selector compiler emits sibling checks without first guarding e.parentElement, whereas 2.2.24 included that guard.
Downstream evidence
Ant Design PRs #59150 and #59151 independently began failing the same six Tooltip tests after 2.2.25 was published. On the exact #59151 head, the three affected Tooltip test files fail 6/55 with 2.2.25 and pass 55/55 (5 snapshots) when only nwsapi is changed to 2.2.24. A local build with the parent guard restored also passes 55/55.
I have a small fix and browser regression test ready and will open a PR linked to this issue.
AI assistance disclosure: Codex was used to trace the dependency update, compare releases, minimize the reproduction, and draft the report. I reproduced and verified all results locally.
Version
nwsapi@2.2.25(regression from2.2.24)Reproduction
With
jsdom@26.1.0, which acceptsnwsapithrough^2.2.16:Expected
The expressions return
trueandfalse, respectively. That is the behavior withnwsapi@2.2.24.Actual
Both paths can throw in
nwsapi@2.2.25:The same applies to adjacent-sibling relational selectors (
:has(+ ...)) when matching reaches a root element.This appears to be a regression of #145. The 2.2.25 selector compiler emits sibling checks without first guarding
e.parentElement, whereas 2.2.24 included that guard.Downstream evidence
Ant Design PRs #59150 and #59151 independently began failing the same six Tooltip tests after 2.2.25 was published. On the exact #59151 head, the three affected Tooltip test files fail 6/55 with 2.2.25 and pass 55/55 (5 snapshots) when only
nwsapiis changed to 2.2.24. A local build with the parent guard restored also passes 55/55.I have a small fix and browser regression test ready and will open a PR linked to this issue.
AI assistance disclosure: Codex was used to trace the dependency update, compare releases, minimize the reproduction, and draft the report. I reproduced and verified all results locally.
@nrps9909
thank you for the help identify this bug and for suggesting the fix too.
Your complete reproduction of the problem, both on headless and client browser
is an example to follow allowing us to pin the problem as quickly as possible and release a fix.
I recognized the problem and can assure a new release will be available in a few hours (I am traveling back home).