Detect "HappyDOM" in userAgent string in same way as "jsdom" #10374
Labels
component: data grid
This is the name of the generic UI component, not the React module!
dx
Related to developers' experience
test
Duplicates
Latest version
Summary 💡
Summary
Wherever there is code like
const isJSDOM = /jsdom/.test(window.navigator.userAgent);
, generalise it to use the/jsdom|HappyDOM/
instead.Detail
Currently there are several places in the code that have logic like the following (copied from
packages/grid/x-data-grid/src/hooks/features/dimensions/useGridDimensions.ts
):This relies on the jsdom testing environment using "Mozilla/5.0 (linux) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/{packageVersion}" as its default userAgent string.
If using vitest with the default environment of happy-dom, instead, this won't work and the error is shown in tests.
release v12.0.0.0 of happy-dom has fixed an issue with its useragent string, and now uses "Mozilla/5.0 (X11; {process.platform} {process.arch}) AppleWebKit/537.36 (KHTML, like Gecko) HappyDOM/{packageVersion}" as its default. So changing the regex to
/jsdom|HappyDOM/
should be sufficient.Examples 🌈
No response
Motivation 🔦
Make development of apps using mui-x (specifically in my case x-data-grid) with vite easier without workarounds.
I was going to just submit a simple PR specifically for
useGridDimensions.ts
in x-data-grid, but realised the same logic is used all across the library, so there might be a different pattern that needs to be implemented.Order ID 💳 (optional)
No response
The text was updated successfully, but these errors were encountered: